标题:
[分享]= = = = = = = = = = 1602/2002/2402液晶驱动程序 = = = = = = = = = =
[打印本页]
作者:
ayumi7
时间:
2009-12-10 15:35
标题:
[分享]= = = = = = = = = = 1602/2002/2402液晶驱动程序 = = = = = = = = = =
本帖最后由 ayumi7 于 2009-12-10 15:43 编辑
1602 16字符2行
2002 20个字符2行
2402 24个字符2行
使用命令和接口方式都是一样的
唯一就是显示字符数量差异
稍微修改下地址就能可以了
源程序
建造目标 '目标 1'
正在编绎 2002A.C...
连接中...
Program Size: data=10.0 xdata=0 code=277
正在从 "2002a" 产生 HEX文件...
"2002a" - 0 错误 (s), 0 警告 (s).
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={" USER ID:Ayumi7 "};
uchar code table1[]={" PASSWORD:********* "};
sbit lcden=P2^5;
sbit lcdrs=P2^7;
sbit lcdrw=P2^6;
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)
{
lcdrs=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
/**********************************************************/
//发送数据子函数
/**********************************************************/
void write_data(uchar date)
{
lcdrs=1;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()//初始化
{
lcden=0;
lcdrs=0;
lcdrw=0;
write_com(0x38);
write_com(0x0c);//设置光标和显示开关
write_com(0x06);
write_com(0x01);
write_com(0x80);
}
void main()
{
while(1)
{
init();
write_com(0x80+0x14);//字符初始位置+偏移量
for(num=0;num<20;num++)//字符移动量
{
write_data(table[num]);
delay(20);
}
write_com(0x80+0x54);//第二行
for(num=0;num<20;num++)
{
write_data(table1[num]);
delay(20);
}
for(num=0;num<20;num++)
{
write_com(0x18);
delay(200);
}
delay(5000);
for(num=0;num<20;num++)
{
write_com(0x18);
delay(200);
}
}
}
效果如下:
欢迎光临 『家电维修论坛 163DZ.COM』 (http://xn--www-ryc87f.163dz.com/bbs/)
Powered by Discuz! 7.0.0