帶移屏幕的LCD1602顯示程序
#include
#define uint unsigned int
#define uchar unsigned char
sbit rs=P2^0;
sbit ea=P2^1;
uchar code tab1[]={"cekongjishuyiqi"};
uchar code tab2[]={"danpianjishiyan"};
void delay(uint z)
{
uchar i;
while(z--)
for(i=0;i<120;i++);
}
void com(uchar com)
{
rs=1;
delay(1);
rs=0;
delay(1);
P3=com;
delay(1);
ea=1;
delay(1);
ea=0;
}
void date(uchar date)
{
rs=0;
delay(5);
rs=1;
delay(1);
P3=date;
delay(1);
ea=1;
delay(1);
ea=0;
}
void init()
{
ea=0;
com(0X38);
delay(5);
com(0x0f);
delay(5);
com(0x06);
delay(5);
com(0x01);
delay(5);
}
void main()
{
uchar i;
init();
com(0x80+0x10);
for(i=0;i<16;i++)
date(tab1[i]);
com(0x80+0x50);
for(i=0;i<16;i++)
date(tab2[i]);
for(i=0;i<16;i++)
com(0x18);
while(1);
}
評(píng)論