#include
#define uint unsigned int
#define uchar unsigned char
sbit rs=P3^4; // 数据/指令控制位
sbit r_w=P3^5;//读/写控制位
sbit end=P3^3;//势能
uchar code man[]="TEL:021-57857288 ";
uchar code han[]="shanghai carl";
void delay(uchar x) //延时
{
uchar a,b;
for(a=x;a>0;a--)
{
for(b=100;b>0;b--);
}
}
void write_instruct(uchar inst)//写指令
{
P1=inst;
end=0;
delay(10);
rs=0;
r_w=0;
delay(10);
end=1;
delay(10);
end=0;
}
void write_data(uchar date)//写数据
{
P1=date;
end=0;
delay(10);
rs=1;
r_w=0;
delay(10);
end=1;
delay(10);
end=0;
}
void zhong ()//字符 中,地址0x02.
{
write_instruct(0x80);//第1行开始
delay(10);
write_instruct(0x50);//字摸地址
delay(10);
write_data(0x84);//第1行
delay(10);
write_data(0x9f);//第2行
delay(10);
write_data(0x95);//第3行
delay(10);
write_data(0x95);//第4行
delay(10);
write_data(0x95);//第5行
delay(10);
write_data(0x95);//第6行
delay(10);
write_data(0x9f);//第7行
delay(10);
write_data(0x84);//第8行
delay(10);
}
void guo ()//字符 国,地址0x01.
{
write_instruct(0x80);//第1行开始
delay(10);
write_instruct(0x48);//字摸地址
delay(10);
write_data(0x9f);//第1行
delay(10);
write_data(0x91);//第2行
delay(10);
write_data(0x9f);//第3行
delay(10);
write_data(0x95);//第4行
delay(10);
write_data(0x9f);//第5行
delay(10);
write_data(0x95);//第6行
delay(10);
write_data(0x9f);//第7行
delay(10);
write_data(0x9f);//第8行
delay(10);
}
void init()//复位
{
write_instruct(0x38);//功能设置 8位 两行显示 5X7点阵
delay(10);
write_instruct(0x0c);//显示开 光标显示 光标闪烁
delay(10);
write_instruct(0x06);//光标右移 显示不移
delay(10);
write_instruct(0x01);//清显示
delay(10);
zhong();
guo ();
}
void main()
{
uchar i,h;
init();
delay(50);
write_instruct(0x80);//显示位置
delay(50);
for(i=0;i<21;i++)
{
write_data(man[i]);
delay(50);
}
write_instruct(0xc0);//显示位置
delay(50);
for(h=0;h<13;h++)
{
write_data(han[h]);
delay(50);
}
delay(50);
write_data(0x02);
delay(50);
write_data(0x01);
delay(50);
//write_instruct(0x07);
delay(200);
while(1);
}
程序运行后的结果见图片: