The LCD display does not display, but the program can run normally?
[Copy link]
#include<reg51.h>
#include<intrins.h> //Include _nop_() empty function instruction
#define out P2 //P2 port output display
#define uchar unsigned char
#define uint unsigned int
sbit RS=P3^0;
sbit RW=P3^1;
sbit E=P3^2;
void lcd_initial(void); //lcd initialization function
void cheek_busy(void); //check busy flag function
void write_command(uchar com); //write command function
void write_data(uchar dat); //write data function
void string(uchar ad,uchar *s); //display character function
void delay(uint); //delay function
void main(void)
{
lcd_initial();
while(1)
{
string(0x85,"welcome"); //Call function to display characters
string(0xc2,"harbin CHINA");
delay(100);
write_command(0x01); //Call write command function to clear screen
delay(100);
}
}
void delay(uint j) //延时函数
{
uchar i=250;
for(;j>0;j--)
{
while(--i);
i=249;
while(--i);
i=250;
}
}
void cheek_busy(void) //Check busy flag function
{
uchar dt;
do
{
dt=0xff;
E=0;
RS=0;
RW=1;
E=1;
dt=out;
}while(dt&0x80);
E=0;
}
void write_command(uchar com) //write command function
{
cheek_busy();
E=0;
RS=0;
RW=0;
out=com;
E=1;
_nop_();
E=0;
delay(1);
}
void write_data(uchar dat) //Write display function
{
cheek_busy();
E=0;
RS=1;
RW=0;
out=dat;
_nop_();
_nop_();
_nop_();
_nop_();
E=1;
_nop_();
_nop_();
_nop_();
_nop_();
E=0;
delay(1);
}
void lcd_initial(void) //LCD初始化函数
{
delay(15);
write_command(0x38);
delay(5);
write_command(0x38);
delay(5);
write_command(0x38);
delay(5);
write_command(0x0c);
delay(5);
write_command(0x06);
write_command(0x01);
delay(1);
}
void string(uchar ad,uchar *s) //output display string function
{
write_command(ad);
while(*s>0)
{
write_data(*s++);
delay(100);
}
}
|