Sei sulla pagina 1di 11

#include <at89x52.h> #include "lcd.h" main( ) { LCD_init(); LCD_row1(); LCD_puts("Hello World"); LCD_row2(); LCD_puts("Good Morning"); while (1); } seven.

c #define LCD_en P3_1 #define LCD_rs P3_0 #define LCD_DELAY 2000 /* Delay for 1 ms */ #define LCD_clear() LCD_command(0x1) /* Clear display LCD */ #define LCD_origin() LCD_command(0x2) /* Set to origin LCD */ #define LCD_row1() LCD_command(0x80) /* Begin at Line 1 */ #define LCD_row2() LCD_command(0xC0) /* Begin at Line 2 */ /*************************************************** * Prototype(s) * ***************************************************/ void LCD_delay(unsigned char ms); void LCD_enable(); void LCD_command(unsigned char command); void LCD_putc(unsigned char ascii); void LCD_puts(unsigned char *lcd_string); void LCD_init(); /*************************************************** * Sources * ***************************************************/ void LCD_delay(unsigned char ms) { unsigned char n; unsigned int i; for (n=0; n<ms; n++) { for (i=0; i<LCD_DELAY; i++); /* For 1 ms */ } }

void LCD_enable() { LCD_en = 0; /* Clear bit P2.4 */ LCD_delay(1); LCD_en = 1; /* Set bit P2.4 */ } void LCD_command(unsigned char command) { LCD_rs = 0; /* Clear bit P2.5 */ P2 = (P2 & 0xF0)|((command>>4) & 0x0F); LCD_enable(); P2 = (P2 & 0xF0)|(command & 0x0F); LCD_enable(); LCD_delay(1); } void LCD_putc(unsigned char ascii) { LCD_rs = 1; /* Set bit P2.5 */ P2 = (P2 & 0xF0)|((ascii>>4) & 0x0F); LCD_enable(); P2 = (P2 & 0xF0)|(ascii & 0x0F); LCD_enable(); LCD_delay(1); } void LCD_puts(unsigned char *lcd_string) { while (*lcd_string) { LCD_putc(*lcd_string++); } } void LCD_init() { LCD_en = 1; /* Set bit P2.4 */ LCD_rs = 0; /* Clear bit P2.5 */ LCD_command(0x33); LCD_command(0x32); LCD_command(0x28); LCD_command(0x0C); LCD_command(0x06); LCD_command(0x01); /* Clear */ LCD_delay(256);

//calculator with lcd display #pragma SMALL DB OE #include <reg51.h> #include "io.h" /* The functions to initialize and control the LCD are assumed to be in the file io.c */ /* Function to output the decimal value of the result on the LCD */ void PrintInt(int i) { . . . } /* Routine to scan the key pressed */ unsigned char key_scan() {

unsigned char i, j, temp1, temp2; while( 1 ) /* keep waiting for a key to be pressed */ for(i=0; i<4; i++) { /* Set each row to 0 */ P1 = 0xff & ~(1<<i); /* Scan each column to see which key was pressed */ for (j=4; j<8; j++) { /* Code to determine the position of the key which was pressed */ /* return(position) */ } } } void main() { /* You can have a conversion table to convert the key position into a valid number which indicates the operator or operand value. For eg: the numbers 0 to 9 are valid operands and 100 to 103 denote addition, subtraction, multiplication and division respectively */ char conv_table[] = { 1, 4, 7, -1, 2, 3, 5, 6, 8, 9, 0, -1, 100 101 102 103 /* /* /* /* add sub mul div */, */, */, */

}; char num1, num2, op; int result; InitIO(); while(1) {

ClearScreen(); /* read num1 */ GotoXY(0, 0); PrintString("num1 : "); do { num1 = conv_table[key_scan()]; } while( num1 < 0 || num1 > 9 ); /* read a valid operation */ GotoXY(0, 0); PrintString("op : "); do { op = conv_table[key_scan()]; } while( op < 100 ); /* read num2 */ GotoXY(0, 0); PrintString("num2 : "); do { num2 = conv_table[key_scan()]; } while( num2 < 0 || num2 > 9 ); /* compute result */ if( op == 100 ) { /* Add numbers and display result on the LCD */ } else if( op == 101 ) { . . . . /* Continue similarly for other operations */ } } }

#include <reg51.h> #include <absacc.h> sbit p10=P1^0; sbit p11=P1^1; sbit p12=P1^2; #define #define #define UP 20 DOWN 30 STOP 40

void delay()//Delay process { unsigned i,j,k; for(i=0;i<0x02;i++) for(j=0;j<0x02;j++) for(k=0;k<0xff;k++); } main() { unsigned char temp; while(1) { if(p10==0) { temp=UP;//Control is transferred P2=0X00; delay(); } if(p11==0) { temp=DOWN;//Inversion of control P2=0X00; delay(); } if(p12==0) { temp=STOP;//Control stop } switch(temp) { case DOWN : P2=0X01;//Inversion of control //0011 delay(); delay(); P2=0X02;//0110 delay(); delay(); P2=0X04;//1100 delay(); delay(); P2=0X08;//1001 delay(); delay(); break; case UP : P2=0X08;//Control is transferred delay(); delay();

case

P2=0X04; delay(); delay(); P2=0X02; delay(); delay(); P2=0X01; delay(); delay(); break; STOP ://Control stop P2=0X00; delay(); delay(); break;

} }

#include <reg51.h> #include <absacc.h> #define REG0 XBYTE[0x0000] //LCD instruction register to write the address, according to configuration changes #define REG1 XBYTE[0x0001] //D0 ~ D7 LCD read data to the address, according to configuration changes #define REG2 XBYTE[0x0002] //LCD write data register address, configuration changes can #define REG3 XBYTE[0x0003] //LCD read data register address, configuration changes can unsigned char bdata busyflag; unsigned char dat,datn; unsigned char word1[16]={" This programm "}; //Line unsigned char word2[16]={" by Sonu "}; cache code unsigned char word3[16]={"microcodes.info"}; for the data to the ROM in curing code unsigned char word4[16]={" Microcedes !"}; for the data to the ROM in curing code unsigned char word5[16]={" Wellcome To "}; for the data to the ROM in curing code unsigned char word6[16]={" Proteus Tools!"}; for the data to the ROM in curing sbit sbit sbit sbit busyflag_7=busyflag^7; p10=P1^0; p11=P1^1; p12=P1^2; //Check whether the busy routines LCD 1 shows the cache //Line 2 shows the //Fixed display //Fixed display //Fixed display //Fixed display

void busy() { do

{ }

busyflag=REG1; }while(busyflag_7); //Subroutine to write control

void wrc(unsigned char wcon) instructions { busy(); REG0=wcon; } void wrd(unsigned char wdat) { busy(); REG2=wdat; }

//Subroutine write data register

void rdd() //Subroutine read data register { busy(); dat=REG3; } void lcdint() //LCD initialization subroutine { wrc(0x38); wrc(0x01); wrc(0x06); wrc(0x0c); } void wrn(unsigned char word[]) //Continuous data write n characters to the LCD data register { unsigned char i; for(i=0;i<16;i++) { wrd(word[i]); } } void main() {

lcdint(); wrc(0x80); wrn(word1); wrc(0xc0); wrn(word2);

//Initialization //Showing 1 of 1 character line //Display line 2 1 of character

while(1) { if(p10==0) //Determine whether the press P1.0, and display data { wrc(0x80); wrn(word1); wrc(0xc0);

display data

wrn(word2); } if(p11==0)//Determine whether P1.1 press, and { wrc(0x80); wrn(word3); wrc(0xc0); wrn(word4);

display data

} if(p12==0)//Determine whether P1.2 press, and { wrc(0x80); wrn(word5); wrc(0xc0); wrn(word6);

} } include <reg51.h> #include <stdio.h> #define byte unsigned char }

//Interrupt service routine void keyinterrupt() interrupt 2 { int t; byte keycode,scancode,flag=0xff; t=5000; while(t--); if(INT1==1) return; EX1=0; scancode=0xef; while(scancode!=0xff) { P1=scancode; keycode=P1; if((keycode&0x0f)!=0x0f) break; scancode=(keycode<<1)|0x0f; } keycode=~keycode; P2=keycode; //Will scan the code output, digital control with digital control functions with the decoding P1=0X0F; while(1) { if(INT1==1) { flag=~flag; if(flag==0) break;

} EX1=1; return; }

} t=10000; while(t--);

void main(void) { IE=0; EX1=1; EA=1; //Break open P2=0XFF; P1=0X0F; while(1) { } } #include <reg51.h> #include <stdio.h> unsigned int temp1; void delay(unsigned int temp)//Delay process { while(--temp); } void main() { P2=255;//led is off while(1) { P2=0XFE; temp1=35000; delay(temp1); P2=0XFD; temp1=35000; delay(temp1); P2=0XFB; temp1=35000; delay(temp1); P2=0XF7; temp1=35000; delay(temp1); P2=0XEF; temp1=35000; delay(temp1); P2=0XDF; temp1=35000; delay(temp1); P2=0XBF; temp1=35000; delay(temp1); P2=0X7F;

temp1=35000; delay(temp1)

Potrebbero piacerti anche