液晶1602显示源代码
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit en=P2^0;
sbit rs=P2^1;
uchar code table[]="I LOVE YOU";
uchar code table1[]="FOREVER MAMA!";
uchar num;
void delay(uint z);
void write_com(uchar com);
void write_data(uchar date);
void init();
void main()
{
init();
for(num=0;num<10;num++)
{
write_data(table[num]);
delay(5);
}
write_com(0x80+0x53);
for(num=0;num<13;num++)
{
write_data(table1[num]);
delay(5);
}
for(num=0;num<16;num++)
{
write_com(0x18);
delay(20);
}
while(1);
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)
{
rs=0;
delay(5);
P0=com;
en=1;
delay(5);
en=0;
}
void write_data(uchar date)
{
rs=1;
delay(5);
P0=date;
en=1;
delay(5);
en=0;
}
void init()
{
en=0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x80+0x10);
}