实现51单片机LCD1602两行移动显示
第一行:My name is Eagal
第二行:Music film Games
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit lcden=P3^4;
sbit rs=P3^5;
sbit rw=P3^6;
sbit dula=P2^6;
sbit wela=P2^7;
uchar table1[]="My name is Eagal";
uchar table2[]=" Music Flim Games ";
void delay(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=10;b>0;b--);
}
void write_com(uchar com)
{
P0=com;
rs=0;
lcden=0;
delay(10);
lcden=1;
delay(10);
lcden=0;
}
void write_date(uchar date)
{
P0=date;
rs=1;
lcden=0;
delay(10);
lcden=1;
delay(10);
lcden=0;
}
void init()
{
rw=0;
dula=0;
wela=0;
write_com(0x38);
delay(20);
write_com(0x0c);
delay(20);
write_com(0x06);
delay(20);
write_com(0x01);
delay(20);
}
void main()
{
uint k=1000;
uchar *pa,*pb;
init();
write_com(0x80 | 0x0f);
delay(20);
pa = table1;
while(*pa != '\0')
{
write_date(*pa++);
while(k--);
}
write_com(0x07);
write_com(0x80 | 0x4f);
pb = table2;
while(*pb != '\0')
{
write_date(*pb++);
while(k--);
}
}