今天继续调试板子,写了个LCD1602的程序,代码如下:
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
void delay_50us(uint i)
{ uchar j;
for(;i>0;i--)
for(j=19;j>0;j--);
}
sbit rs=P2^4;
sbit rw=P2^5;
sbit e=P2^6;
uchar table1[]="WWW.EEPW.COM.CN ";
uchar table2[]="Best wishes to U";
void write_com(uchar com)
{ e=0;
rs=0;
rw=0;
P0=com;
delay_50us(10);
e=1;
delay_50us(20);
e=0;
}
void write_dat(uchar dat)
{ e=0;
rs=1;
rw=0;
P0=dat;
delay_50us(10);
e=1;
delay_50us(20);
e=0;
}
void init(void)
{ delay_50us(300);
write_com(0x38);
delay_50us(100);
write_com(0x38);
delay_50us(100);
write_com(0x38);
write_com(0x01);
write_com(0x06);
write_com(0x0c);
}
void main()
{ uchar i=0;
init();
while(1)
{ write_com(0x06);
write_com(0x80);
while(table1[i]!='\0')
{ write_dat(table1[i]);
i++;
delay_50us(1500);
}
delay_50us(300);
i=0;
write_com(0xc0);
while(table2[i]!='\0')
{ write_dat(table2[i]);
i++;
delay_50us(1500);
}
delay_50us(300);
i=0;
}
}