Current location - Quotes Website - Team slogan - Single-chip C language, please heroes, in the back of each note, thank you.
Single-chip C language, please heroes, in the back of each note, thank you.
# include & ltreg52.h & gt// Call the header file reg52.h.

sbit rs=p2^6; //bit definition defines the sixth bit of P2 as RS, and then the operation of RS is equivalent to the operation of P2^6.

sbit rw=p2^5; //ditto

sbit e=p2^7; //ditto

Unsigned characters are busy; //Define the variable busy as an unsigned character variable.

Void delay(unsigned char asf) // This is a delay function, and asf in brackets is the delay time.

{ while(ASF-); }//When asf>= 1 has been in this loop until ASF.

Lcd_busy()// This is to write a function, but it needs to be preceded by void to become void lcd_busy ().

{ RS = 0; RW = 1; e = 1; P0 = 0X80 delay (0xff); //Assign 0 to RS, 1 to RW, 1 to E, and output 0x80 at P0 port is delayed by 0xff for such a long time.

If(P0==0X00)//if Judgment Statement When P0=0x00, execute the following busy=0x00 statement.

Busy = 0x00// Assign 0 to busy.

Else // if the above if judgment is not true, execute busy = 0x00 1.

busy = 0x 0 1; //ditto

}

Write_cmd(unsigned char cmd)// Creates a subfunction whose slogan defines cmd as an unsigned character variable.

{

Busy =1; //ditto

While(busy) Because busy= 1, it will always execute the following statement in braces. You are missing a bracket here.

{

LCD _ busy(); //Call the lcd_busy () function on it.

RS = 0; RW = 0; e = 0; P0 = cmd// The first three are assignment statements, as above, followed by giving the value of cmd to P0.

Delay (0xff); The delay function is as above

e = 1; //General allocation

Delay (0xff); The delay function is as above

e = 0; //General assignment

}

Lcd_cmd()// Create a subfunction as above.

{

write _ cmd(0x 38); Call the write_cmd(unsigned char cmd) function above, where cmd is assigned 0x38.

write _ cmd(0x 08); //ditto

write _ cmd(0x 0 1); //ditto

write _ cmd(0x 06); //ditto

write _ cmd(0x0c); //ditto

write _ cmd(0x 84); //ditto

}

Lcd_date()// This function refers to lcd_busy () above.

{

Busy =1;

When (busy)

LCD _ busy();

RS = 1; RW = 0; e = 0; P0 = 0X62

Delay (0xff); e = 1; Delay (0xff); e = 0;

}

Main () main function

{ LCD _ cmd(); LCD _ date(); while( 1); } Call LCD _ cmd () respectively; LCD _ date(); These two subfunctions. And (1) is an infinite loop, and the function has been executed until now.