//第一行 显示‘a’ 第二行显示“welcome”
#include
void initial_lcd(void); //初始化
void write_code(unsigned char m); //写代码
void write_char(unsigned char m); //写字节
void write_string(unsigned char m,unsigned char *p); //写字符串
void busy_lcd(void); //判忙
void lcd_location(unsigned char m); //光标定位
sbit rs=P2^4;
sbit rw=P2^5;
sbit e=P2^6;
void main(void)
{
initial_lcd();
lcd_location(0);
write_char('a');
lcd_location(0x40);
write_string(7,"welcome");
while(1);
}
void initial_lcd(void)
{
write_code(0x38);
write_code(0x38);
write_code(0x38);
write_code(0x06);
write_code(0x08);
write_code(0x01);
}
void write_code(unsigned char m)
{
busy_lcd();
rs=0;
rw=0;
e=1;
P0=m;
e=0;
}
void write_char(unsigned char m)
{
busy_lcd();
rs=1;
rw=0;
e=1;
P0=m;
e=0;
}
void write_string(unsigned char count,unsigned char *p)
{
while(count--)
{
busy_lcd();
write_char(*p);
p++;
}
}
void busy_lcd(void)
{
rw=1;
rs=0;
e=0;
P0=0xff;
e=1;
while(P0_7==1);
e=0;
}
void lcd_location(unsigned char m)
{
write_code(0x80+m);
}