|
#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[]="HELLO QX-MCS51";
uchar table2[]=" QQ:7651719 ";
void delay(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=10;b>0;b--);
}
void delay1(uint x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=100;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); //顯示模式設(shè)置:16×2顯示,5×7點(diǎn)陣,8位數(shù)據(jù)接口
delay(20);
write_com(0x0f); //顯示模式設(shè)置
delay(20);
write_com(0x06); //顯示模式設(shè)置:光標(biāo)右移,字符不移
delay(20);
write_com(0x01); //清屏幕指令,將以前的顯示內(nèi)容清除
delay(20);
}
void main()
{
uchar a;
init();
write_com(0x80+17); //將第一個(gè)字符寫(xiě)在向右偏移17個(gè)字符處,為后面的由右向左劃入做準(zhǔn)備。
delay(20);
for(a=0;a<14;a++)
{
write_date(table1[a]);
delay(20);
}
write_com(0xc0+17);
delay(50);
for(a=0;a<14;a++)
{
write_date(table2[a]);
delay(40);
}
for(a=0;a<16;a++)
{
write_com(0x18); //左移
delay1(200);
}
while(1);
}
|
|