#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit lcden=P1^2;
sbit lcdrs=P1^0;
sbit lcdrw=P1^1;
uchar i,j;
uchar code table[]="东北大学";
uchar code table1[]="张旭";
void delay(uint z) //延时函数
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_cmd(uchar cmd) //向lcd写指令
{
lcdrs=0;
lcdrw=0;
lcden=0;
P0=cmd;
delay(6);
lcden=1;
delay(6);
lcden=0;
}
void write_date(uchar date) //向lcd写数据
{
lcdrs=1;
lcdrw=0;
lcden=0;
P0=date;
delay(6);
lcden=1;
delay(6);
lcden=0;
}
void lcd_position(uchar X,uchar Y) //设定显示的位置
{
uchar pos;
if(X==0)
{X=0x80;}
else if(X==1)
{X=0x90;}
else if(X==2)
{X=0x88;}
else if(X==3)
{X=0x98;}
pos=X+Y;
write_cmd(pos);
}
void lcd_init() //lcd初始化
{
write_cmd(0x30);//基本指令动作,绘图显示关
delay(10);
write_cmd(0x0c);//整体显示开,游标关
delay(10);
write_cmd(0x01);//清屏
delay(10);
}
void main()
{
lcd_init();
lcd_position(1,2);
for(i=0;i<8;i++)
{
write_date(table);
delay(20);
}
lcd_position(2,3);
for(j=0;j<4;j++)
{
write_date(table1[j]);
}
while(1);
} |