#include
#define uchar unsigned char
#define uint unsigned int
***it RS=P1^3;
***it RW=P1^0;
***it PSB=P1^2;
***it EN=P1^1;
uchar code addr_tab[]={
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,//第一行汉字位置
0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,//第二行汉字位置
0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,//第三行汉字位置
0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,//第四行汉字位置
};
void lcd_wcmd(uchar cmd);
void lcd_wdat(uchar dat);
void delay(uchar z)//延时
{
uchar i,j;
for(i=z;i>0;i--)
for(j=120;j>0;j--);
}
void lcd_checkBusy(void)//检测忙标志
{
uchar busy;
do{
EN = 0;
RS = 0;
RW = 1;
delay(4);
EN = 1;
busy = P0;
delay(4);
EN = 0;
}
while(busy&0x80);
}
void hanzi_Disp(uchar x,uchar y,uchar *pt)//显汉字
{
lcd_wcmd(addr_tab[8*x+y]); //写地址
while(*pt>0)
{
lcd_wdat(*pt); //写数据
*pt++;
}
}
void lcd_wcmd(uchar cmd) //写指令
{
RS=0;
RW=0;
EN=0;
delay(4);
P0=(cmd);
delay(4);
EN=1;
delay(4);
EN=0;
}
void lcd_wdat(uchar dat)//写数据
{
RS=1;
RW=0;
EN=0;
P0=dat;
delay(4);
EN=1;
delay(4);
EN=0;
}
void lcd_init()//初始化
{
PSB=1;
lcd_wcmd(0x30);
delay(4);
lcd_wcmd(0x0f);
delay(4);
lcd_wcmd(0x01);
delay(4);
}
void main()//主函数
{
void lcd_checkBusy(void);
lcd_init();
hanzi_Disp(0,0,"单片机学习");
hanzi_Disp(1,2,"爱你到老");
while(1);
}
|