#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]="I LIKE MCU!";
uchar code table1[]="WWW.SMAPS.COM!";
uchar code table2[]="I LIKE MCU!";
uchar code table3[]="WWW.SMAPS.COM!";
sbit LCD_RS = P2^0;
sbit LCD_RW = P2^1;
sbit LCD_EN = P2^2;
uchar num;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(uchar com)
{
LCD_RS=0;
LCD_RW=0;
P0=com;
delay(5);
LCD_EN=1;
delay(5);
LCD_EN=0;
}
void write_data(uchar date)
{
LCD_RS=1;
LCD_RW=0;
P0=date;
delay(5);
LCD_EN=1;
delay(5);
LCD_EN=0;
}
void init()
{
LCD_EN =0;
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
}
void flash()
{
delay(200); //控制停留时间
write_com(0x08); //关闭显示
delay(1000); //延时
write_com(0x0c); //开显示
delay(1000);
write_com(0x08); //关闭显示
delay(1000); //延时
write_com(0x0c); //开显示
delay(500); //控制停留时间
}
void main()
{
init();
while(1)
{
write_com(0x80+0x10);
for(num=0;num<11;num++)
{
write_data(table2[num]);
delay(20);
}
write_com(0x80+0x50);
for(num=0;num<13;num++)
{
write_data(table3[num]);
delay(20);
}
for(num=0;num<16;num++)
{
write_com(0x18);
delay(500);
}
flash(); //闪动二次
write_com(0x01); //清除LCD的显示内容
write_com(0x00);
for(num=0;num<11;num++)
{
write_data(table[num]);
delay(40);
}
write_com(0x80+0x40);
for(num=0;num<13;num++)
{
write_data(table1[num]);
delay(40);
}
for(num=0;num<16;num++)
{
write_com(0x1c);
delay(500);
}
}
}
文章评论(0条评论)
登录后参与讨论