新闻中心

EEPW首页>嵌入式系统>设计应用> LCD1602液晶屏幕显示介绍

LCD1602液晶屏幕显示介绍

作者: 时间:2016-11-11 来源:网络 收藏
下面是protues仿真电路,屏幕中第二行能看清吧,后面再说怎么显示的,第一行是我自定义的汉字“确认”和“取消”的“取”(左右写反了),发现1602显示汉字也就自己弄着玩玩,派不上大场合,而且如果一个汉字占两个字符的话(就像下图显示的),最多只能自定义4个汉字。

本文引用地址://m.amcfsurvey.com/article/201611/316795.htm

先贴上程序,后面再分析。

#include
#include

#define uchar unsigned char
#define uint unsigned int

uchar code line1[] = {"welcome!"};

uchar p[]= //自定义字模数组
{
0x00,0x0f,0x04,0x0f,0x05,0x07,0x00,0x00,
0x0f,0x12,0x1f,0x15,0x1f,0x15,0x1f,0x15, //确
0x04,0x02,0x0e,0x02,0x02,0x03,0x02,0x00,
0x04,0x04,0x04,0x04,0x04,0x0a,0x11,0x00, //认
0x00,0x0f,0x09,0x06,0x06,0x06,0x09,0x00,
0x1f,0x0a,0x0e,0x0e,0x0a,0x1f,0x02,0x02 //取
};

sbit E=P2^7;
sbit RW=P2^5;
sbit RS=P2^6;

busying ()
{
bit result;
RS = 0;
RW = 1;
E = 1;
_nop_();
_nop_();
_nop_();
_nop_();
result = (bit)(P0&0x80);
E = 0;
return result;
}

writeorder (uchar cmd)
{
while (busying());
RS = 0;
RW = 0;
E = 0;
_nop_();
_nop_();
P0 = cmd;
_nop_();
_nop_();
_nop_();
_nop_();
E = 1;
_nop_();
_nop_();
_nop_();
_nop_();
E = 0;
}

writedata (uchar dat)
{
while (busying());
RS = 1;
RW = 0;
E = 0;
_nop_();
_nop_();
P0 = dat;
_nop_();
_nop_();
_nop_();
_nop_();
E = 1;
_nop_();
_nop_();
_nop_();
_nop_();
E = 0;
}

delay(uchar i)
{
while(i--)
{
uchar j=250;
while(j--)
{
_nop_();
_nop_();
_nop_();
_nop_();
}
}
}

initial ()
{
delay (150);
writeorder (0x38);//工作方式:8位、2行、5x7
delay(5);
writeorder (0x06); //输入方式:光标右移、屏幕不动
delay(5);
writeorder (0x0c);//显示状态:显示开、有光标、不闪烁
delay(5);
writeorder (0x01);//清屏
delay(5);
}

newbyte (void) //设置自定义字符
{
uchar i,j,k=0;
uchar temp=0x40;
for(j=0;j<6;j++)
{
for(i=0;i<8;i++)
{
writeorder(temp+i);
writedata(p[k]);
k++;
}
temp += 8;
}
}

main (void)
{
uchar i=0;
initial ();
newbyte ();
writeorder (0x85); //设置第一行显示位置
writedata (0x00);
writedata (0x01);
writedata (0x02);
writedata (0x03);
writedata (0x04);
writedata (0x05);

writeorder (0xc4); //设置第二行显示位置
while(line1[i] != )
{ // 显示字符"welcome!"
writedata(line1[i]);
i++;
}
while (1);
}

如果之前没有接触过1602,这里有资料,可以免注册免费下载:

http://wdpvip.qupan.com/6311643.html

http://wdpvip.qupan.com/6311649.html

下载:LCD1602汉字显示讲解.doc

程序中函数名定义的都很清楚了,不清楚的后面都有注释,补充两点:

1、数组uchar p[]和函数newbyte ()是为了自定义汉字的,可以删除掉。

2、1602共有两行,第一行显示从0x80开始,第二行从0xc0开始

举例说明,想在第一行第二个光标处显示,地址就是:0x81;想在第二行第三个光标处显示,地址就是:0xc2.



评论


技术专区

关闭