LCD12864原理与应用(源程序+原理图+proteus仿真)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

原理与应用1、LCD12864简介:LCD12864分为两种,带字库的和不带字库的,不带字库的液晶显示汉字的时候可以选择自己喜欢的字体。而带字库的液晶,只能显示GB2312字体,当然也可以显示其他的字体,不过是用图片的形式显示。下面介绍不带字库的LCD12864,以Proteus中的AMPIRE128×64为例,如下图所示,它的液晶驱动器为KS0108。引脚功能:引脚符号状态引脚名称功能CS1,CS2输入芯片片选端,都是低电平有效CS1=0开左屏幕,CS1=1关左屏幕CS2=0开右屏幕,CS2=1关右屏幕RS输入数据/命令选择信号RS=1为数据操作,RS=0为写指令或读状态RW输入读写选择信号R/W=1为读选通,R/W=0为写选通E输入读写使能信号在E下降沿,数据被锁存(写)入液晶,在E高电平期间,数据被读出DB0—DB7三态数据总线数据或指令的传送通道RST输入复位信号,低电平时复位复位时,关闭液晶显示,使显示起始行为0,可以跟单片机的复位引脚RST相连,也可以直接接VCC,使之不起作用V0液晶显示器驱动电压-Vout-10VLCD驱动负电压与带字库的液晶不同,此块液晶含有两个液晶驱动器,每块驱动器都控制64*64个点,分为左右两个屏幕显示,总共为128*64个点(即有128×64个点)。这就是为什么AMPIRE128*64有CS1和CS2两个片选端的原因。此液晶有8页,一页有8行点阵点,左右各64列,共128列。如下图所示:、LCD12864中的几条重要指令(一)行(line)设置命令:由此可见显示的起始行地址为0XC0,共64行,有规律地改变起始行号,可以实现滚屏效果。(二)页(page)设置指令:起始页地址为0XB8,因为液晶有64行点,分为8页,每页就有8行点。(三)列(column)地址设置指令每块驱动器的列地址都是从0X40到0X7F,共64列,所以此液晶共有128列点。(四)读状态指令、用LCD12864显示汉字(一)由于这块液晶不带字库,我们就要自己编写字库,编写字库所用的字模提取软件为Zimo21(软件下载地址),LCD1602显示自定义字符的时候也是用它。在取模之前我们要进行一些设定,根据此液晶的显示原理,设置为“纵向取模,字节倒序”,如下图所示:(若不是这样,则取模得到的数据不是我们想要的,将会出现乱码,同样可以在下载到关于字模提取原理文档)字体选择默认的“宋体,常规,小四号”,小四号为16*16大小,如下图所示:与单片机的连接如下图所示:C程序如下:#includereg51.h#includeintrins.h#defineucharunsignedchar#defineuintunsignedint//下面是“欢迎访问伊人憔悴百度空间”点阵数据,一个汉字有32字节数据组成unsignedcharcodehuan[]=//欢{0x04,0x24,0x44,0x84,0x64,0x9C,0x40,0x30,0x0F,0xC8,0x08,0x08,0x28,0x18,0x00,0x00,0x10,0x08,0x06,0x01,0x82,0x4C,0x20,0x18,0x06,0x01,0x06,0x18,0x20,0x40,0x80,0x00};unsignedcharcodeying[]=//迎{0x40,0x40,0x42,0xCC,0x00,0x00,0xFC,0x04,0x02,0x00,0xFC,0x04,0x04,0xFC,0x00,0x00,0x00,0x40,0x20,0x1F,0x20,0x40,0x4F,0x44,0x42,0x40,0x7F,0x42,0x44,0x43,0x40,0x00};unsignedcharcodefang[]=//访{0x40,0x40,0x42,0xCC,0x00,0x08,0x08,0xF8,0x89,0x8E,0x88,0x88,0x88,0x08,0x08,0x00,0x00,0x00,0x00,0x3F,0x90,0x48,0x30,0x0F,0x00,0x40,0x80,0x40,0x3F,0x00,0x00,0x00};unsignedcharcodewen[]=//问{0x00,0xF8,0x01,0x02,0x00,0xE2,0x22,0x22,0x22,0xE2,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x1F,0x08,0x08,0x08,0x1F,0x00,0x40,0x80,0x7F,0x00,0x00};unsignedcharcodeyi[]=//伊{0x00,0x80,0x60,0xF8,0x07,0x20,0x22,0x22,0xFE,0x22,0x22,0x22,0xFE,0x20,0x20,0x00,0x01,0x00,0x00,0xFF,0x00,0x80,0x42,0x32,0x0F,0x02,0x02,0x02,0x07,0x00,0x00,0x00};unsignedcharcoderen[]=//人{0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x3F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x40,0x20,0x10,0x0C,0x03,0x00,0x00,0x00,0x03,0x0C,0x10,0x20,0x40,0x80,0x00};unsignedcharcodeqiao[]=//憔{0xE0,0x00,0xFF,0x10,0x20,0x10,0xFC,0x27,0x24,0x25,0xFE,0x24,0x24,0x24,0x04,0x00,0x01,0x00,0xFF,0x00,0x80,0x60,0x1F,0x29,0xC9,0x09,0x2F,0xC9,0x09,0x29,0xC8,0x00};unsignedcharcodecui[]=//悴{0x80,0x70,0x00,0xFF,0x08,0x90,0x44,0x34,0x45,0x86,0x44,0x34,0x44,0x84,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x04,0x04,0x04,0x04,0xFE,0x04,0x04,0x04,0x04,0x04,0x00};unsignedcharcodebai[]=//百{0x02,0x02,0xE2,0x22,0x22,0x32,0x2A,0x26,0x22,0x22,0x22,0x22,0xE2,0x02,0x02,0x00,0x00,0x00,0xFF,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0x42,0xFF,0x00,0x00,0x00};unsignedcharcodedu[]=//度{0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00};[]=//空{0x10,0x0C,0x44,0x24,0x14,0x04,0x05,0x06,0x04,0x04,0x14,0x24,0x44,0x14,0x0C,0x00,0x00,0x40,0x40,0x41,0x41,0x41,0x41,0x7F,0x41,0x41,0x41,0x41,0x40,0x40,0x00,0x00};unsignedcharcodejian[]=//间{0x00,0xF8,0x01,0x06,0x00,0xF0,0x12,0x12,0x12,0xF2,0x02,0x02,0x02,0xFE,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x1F,0x11,0x11,0x11,0x1F,0x00,0x40,0x80,0x7F,0x00,0x00};sbitCS1=P2^0;//片选1,低电平有效,CS1=0开左屏幕,CS1=1关左屏幕sbitCS2=P2^1;//片选2,低电平有效,CS2=0开右屏幕,CS2=1关右屏幕sbitRS=P2^2;//数据,指令选择信号,RS=1为数据操作,RS=0为写指令或读状态(一般为读忙标志)sbitRW=P2^3;//读写选择信号,RW=1为读选通,RW=0为写选通sbitEN=P2^4;//读写使能信号voidbusy()//忙检测函数{P0=0X00;//这句不能少RS=0;RW=1;EN=1;while(P0&0X80);//P0&0X80结果为真则一直执行空操作,也就是说P0&0X80为0则结束循环EN=0;}voidwcmd(ucharcmd){busy();//每次写入指令或数据之前都进行忙检测RS=0;RW=0;P0=cmd;EN=1;_nop_();_nop_();//在EN下降沿写入数据和指令EN=0;}voidwdata(uchardat)//写命令和写数据只在RS=0或RS=1上不同,其余都相同{busy();RS=1;RW=0;P0=dat;EN=1;_nop_();_nop_();//在EN下降沿写入数据和指令EN=0;}voidset_page(ucharpage)//设置页,12864LCD共有8页,每页有8行点阵点。{page=0xb8|page;//首页地址为0XB8wcmd(page);//page取值范围为0~7,表示第1到8页}voidset_line(ucharline)//设置显示的起始行,共有0——63行,一般从0行开始显示{line=0xc0|line;//起始行地址0XC0wcmd(line);//line取值范围为0~63,表示第1到64行}voidset_column(ucharcolumn)//设置显示的列{//column=column&0x3f;//列的最大值为0X3F,即64column=0x40|column;//列的首地址为0X40,wcmd(column);//column的取值范围为0~63,共64列}voidset_onoff(ucharonoff)//设置显示开关,onoff取值为0或1{onoff|=0x3e;//0X3E是关显示,0X3F是开显示wcmd(onoff);//所以若onoff为0,则表示关显示,onoff为1,则表示开显示}voidselect_screen(ucharscreen

1 / 12
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功