我按复位键或者重新上电就会就会乱,或者刚刚上电的时候显示就不对,这是什么原因呢
#include <STC12C5A60S2.H>
#define uchar unsigned char
#define uint unsigned int
sbit E=P2^7;
sbit RW=P2^5;
sbit RS=P2^6;
sbit PSB=P3^2;
uchar code table1 []="当前温度:";
uchar code table2 []="剩余电量:";
void write_com(uchar com);
void write_dat(uchar dat);
void lcd_inti();
void delay(uchar i) ; //0.1ms
void main()
{
uchar a,b;
lcd_inti();
delay(500);
write_com(0x80);
for(a=0;a<10;a++)
{
write_dat(table1[a]);
delay(10);
}
delay(50);
write_com(0x90);
for(b=0;b<10;b++)
{
write_dat(table2);
delay(10);
}
while(10);
}
void write_com(uchar com)
{
E=0;
RS=0;
RW=0;
E=1;
P0=com;
delay(10);
E=0;
}
void write_dat(uchar dat)
{
E=0;
RS=1;
RW=0;
E=1;
P0=dat;
delay(10);
E=0;
}
void lcd_inti()
{
delay(500);
PSB=1; //并口
write_com(0x30); //基本指令
delay(50);
write_com(0x0c); //打开显示,光标关闭
delay(50);
write_com(0x01); //清除LCD显示类容
delay(50);
}
void delay(uchar i) //0.1ms
{
uchar j;
while(i--)
for(j=1200;j>0;j--);
}
|