LCD滚动显示汉字仿真.docx
《LCD滚动显示汉字仿真.docx》由会员分享,可在线阅读,更多相关《LCD滚动显示汉字仿真.docx(16页珍藏版)》请在冰豆网上搜索。
![LCD滚动显示汉字仿真.docx](https://file1.bdocx.com/fileroot1/2023-2/28/17bdfcdc-ead0-4bd6-aeda-8ddfa6461709/17bdfcdc-ead0-4bd6-aeda-8ddfa64617091.gif)
LCD滚动显示汉字仿真
《微机式医学仪器设计》
课程设计报告
题目:
LCD滚动显示汉字
学院:
XXXX
专业:
XXXXXX
班级:
XXXXXXXXX
姓名:
XXXXXXXXXXX
学号:
XXXXXXXX
指导教师:
XXXXXXX
2011年06月19日
LCD滚动显示汉字
摘要:
利用系统软硬件设计仿真平台proteus对LCD滚动汉字显示屏
12864进行仿真设计,完成了系统的硬件电路设计和软件编程,并进行了仿真调试,实现了汉字在LCD显示屏上滚动显示,达到了仿真设计的目的。
关键字:
ProteusLCD12864汉字滚动keil仿真
Abstract:
UseofsystemsoftwareandhardwaredesignsimulationplatformforLCDscreenproteusrollingChinesecharacters
12864,andcompletedthedesignsimulationsystemdesignofhardwarecircuitandthesoftwareprogramming,andsimulationtest,toachievetheChinesecharactersdisplayedontheLCDscreen,tothepurposeofdesignsimulation.
Keywords:
ProteusLCD12864scrollChinesekeilsimulation
1.1设计目的:
通过keil软件和Proteus软件仿真,达到对汉字的动态显示,利用软件仿真的方式对电子产品的前期开发进行模拟。
以减少生产成本,增加产品的效益。
1.2设计过程及要求
1、基本功能:
实现汉字的循环滚动显示
2、主要技术参数
1.单片机选择AT89C51
AT89C51是一种带4K字节FLASH存储器的低电压、高性能CMOS8位微处理器,俗称单片机。
AT89C2051是一种带2K字节闪存可编程可擦除只读存储器的单片机。
单片机的可擦除只读存储器可以反复擦除1000次。
该器件采用ATMEL高密度非易失存储器制造技术制造,与工业标准的MCS-51指令集和输出管脚相兼容。
由于将多功能8位CPU和闪烁存储器组合在单个芯片中,ATMEL的AT89C51是一种高效微控制器,AT89C2051是它的一种精简版本。
AT89C单片机为很多嵌入式控制系统提供了一种灵活性高且价廉的方案。
外形及引脚排列如图所示
2.LCD显示器选择SMG12864
SMG12864是一种具有4位/8位并行、2线或3线串行多种接口方式,内部含有国标一级、二级简体中文字库的点阵图形液晶显示模块;其显示分辨率为128×64,内置8192个16*16点汉字,和128个16*8点ASCII字符集.利用该模块灵活的接口方式和简单、方便的操作指令,可构成全中文人机交互图形界面。
可以显示8×4行16×16点阵的汉字.也可完成图形显示.低电压低功耗是其又一显著特点。
由该模块构成的液晶显示方案与同类型的图形点阵液晶显示模块相比,不论硬件电路结构或显示程序都要简洁得多,且该模块的价格也略低于相同点阵的图形液晶模块。
如方框图:
3.晶振选择12MHz
使用晶体振子组成的振荡电路,叫晶振电路,晶体振子内部由石英晶体构成。
电路图为:
1.3系统设计
该设计是基于51单片机的LCD汉字显示,其设计总框图如下:
系统总体框图
1.4系统调试
打开ProteusISIS,在其编辑窗口中单击元件列表上的“P”按钮,添加元件,画出电路图。
硬件电路制作完成并调试好后,便可以将程序编译好后下载到单片机使运行。
根据实际情况可以修改汉字内容、大小以及滚动方向。
源程序可以使用汇编语言,也可以使用C语言,本实验采用C语言。
下面给出部分程序:
#include
#include
typedefunsignedcharuchar;
typedefunsignedintuint;
#defineLLCD_CMD_WRPBYTE[0x10]/定义左屏写命令/
#defineLLCD_CMD_RDPBYTE[0x11]/定义左屏读命令/
#defineLLCD_DATA_WRPBYTE[0x12]/定义左屏写数据/
#defineLLCD_DATA_RDPBYTE[0x13]/定义左屏读数据/
#defineRLCD_CMD_WRPBYTE[0x20]/定义右屏写命令/
#defineRLCD_CMD_RDPBYTE[0x21]/定义右屏读命令/
#defineRLCD_DATA_WRPBYTE[0x22]/定义右屏写数据/
#defineRLCD_DATA_RDPBYTE[0x23]/定义右屏读数据/
sbitbusy=P0^1;/定义读忙接口/
以上程序为各子函数的定义,后面将要用到以上程序对汉字的显示,滚动等共同构成整个程序。
汉字代码函数:
ucharcodehz0[]=/汉字代码函数/
{
0x10,0x10,0xF0,0x1F,0x10,0xF0,0x40,0x3C,0x10,0x10,0xFF,0x10,0x10,0x10,0x00,0x00
0x40,0x22,0x15,0x08,0x16,0x21,0x40,0x42,0x42,0x42,0x7F,0x42,0x42,0x42,0x40,0x00
0x00,0x20,0x20,0x10,0x08,0x14,0x67,0x84,0x44,0x24,0x14,0x0C,0x00,0x00,0x00,0x00
0x04,0x04,0x04,0x02,0xFE,0x43,0x43,0x42,0x42,0x42,0x42,0x42,0xFE,0x00,0x00,0x00
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
0x00,0x02,0x0C,0x80,0x60,0x02,0xF2,0x82,0x82,0x82,0x82,0xFE,0x80,0x80,0x00,0x00
0x02,0x02,0x7E,0x01,0x00,0x08,0x08,0x08,0x08,0x08,0x48,0x88,0x40,0x3F,0x00,0x00
0x40,0x48,0x48,0x48,0xFF,0x48,0x48,0x42,0xA2,0x9E,0x82,0xA2,0xC2,0xBE,0x00,0x00
0x80,0x60,0x1F,0x20,0x7F,0x44,0x44,0x40,0x4F,0x48,0x48,0x48,0x48,0x4F,0x40,0x00
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
0x00,0x00,0x31,0x22,0x22,0x11,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
0x80,0x80,0x80,0xBE,0xA2,0xA2,0xA2,0xA2,0xA2,0xA2,0xA2,0xBE,0x80,0x80,0x80,0x00
0x00,0x00,0x00,0x06,0x05,0x04,0x04,0x04,0x44,0x84,0x44,0x3C,0x00,0x00,0x00,0x00
};
ucharcodehz1[]=
{
0x80,0x40,0x30,0x1E,0x10,0x10,0x10,0xFF,0x10,0x10,0x10,0x10,0x10,0x10,0x00,0x00
0x40,0x40,0x42,0x42,0x42,0x42,0x42,0x7F,0x42,0x42,0x42,0x42,0x42,0x40,0x40,0x00
0x40,0x3C,0x10,0xFF,0x10,0x10,0x20,0x10,0x8F,0x78,0x08,0xF8,0x08,0xF8,0x00,0x00
0x02,0x06,0x02,0xFF,0x01,0x01,0x04,0x42,0x21,0x18,0x46,0x81,0x40,0x3F,0x00,0x00
0x00,0xFE,0x02,0xA2,0x92,0x9E,0x92,0x92,0xF2,0x92,0x92,0x92,0x92,0x82,0x00,0x00
0x00,0x7F,0x40,0x50,0x50,0x48,0x44,0x42,0x41,0x42,0x44,0x48,0x50,0x40,0x40,0x00
0x40,0x30,0x11,0x96,0x90,0x90,0x91,0x96,0x90,0x90,0x98,0x14,0x13,0x50,0x30,0x00
0x04,0x04,0x04,0x04,0x04,0x44,0x84,0x7E,0x06,0x05,0x04,0x04,0x04,0x04,0x04,0x00
0x00,0x04,0x04,0x04,0x04,0x04,0x04,0xFC,0x04,0x04,0x04,0x04,0x04,0x04,0x00,0x00
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x3F,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x00
0x24,0x24,0xA4,0xFE,0x23,0x22,0x00,0x3E,0x22,0x22,0x22,0x22,0x22,0x3E,0x00,0x00
0x08,0x06,0x01,0xFF,0x01,0x06,0x40,0x49,0x49,0x49,0x7F,0x49,0x49,0x49,0x41,0x00
0x40,0x30,0x11,0x96,0x90,0x90,0x91,0x96,0x90,0x90,0x98,0x14,0x13,0x50,0x30,0x00
0x04,0x04,0x04,0x04,0x04,0x44,0x84,0x7E,0x06,0x05,0x04,0x04,0x04,0x04,0x04,0x00
0x00,0xFE,0x22,0x5A,0x86,0x10,0x0C,0x24,0x24,0x25,0x26,0x24,0x24,0x14,0x0C,0x00
0x00,0xFF,0x04,0x08,0x07,0x80,0x41,0x31,0x0F,0x01,0x01,0x3F,0x41,0x41,0x71,0x00
};
ucharcodehz2[]=
{
0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
0x00,0x0F,0x10,0x20,0x20,0x10,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
0x00,0x70,0x88,0x08,0x08,0x88,0x70,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
0x00,0x1C,0x22,0x21,0x21,0x22,0x1C,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
0x20,0x30,0xAC,0x63,0x30,0x00,0x02,0x02,0xFE,0x02,0x02,0x62,0x5A,0xC6,0x00,0x00
0x22,0x67,0x22,0x12,0x12,0x40,0x30,0x8F,0x80,0x43,0x2C,0x10,0x2C,0x43,0x80,0x00
0x00,0x10,0x10,0x10,0x10,0xD0,0x30,0xFF,0x30,0xD0,0x10,0x10,0x10,0x10,0x00,0x00
0x10,0x08,0x04,0x02,0x09,0x08,0x08,0xFF,0x08,0x08,0x09,0x02,0x04,0x08,0x10,0x00
0x24,0x24,0xA4,0xFE,0xA3,0x22,0x00,0x22,0xCC,0x00,0x00,0xFF,0x00,0x00,0x00,0x00
0x08,0x06,0x01,0xFF,0x00,0x01,0x04,0x04,0x04,0x04,0x04,0xFF,0x02,0x02,0x02,0x00
0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
0x84,0x84,0xFC,0x84,0x84,0x00,0xF8,0x00,0xFF,0x00,0x84,0x84,0xFC,0x84,0x84,0x00
0x10,0x30,0x1F,0x08,0x88,0x42,0x21,0x18,0x07,0x00,0x20,0x20,0x3F,0x20,0x20,0x00
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
ucharcodehz3[]=
{
0x00,0x00,0xFC,0x04,0x84,0x74,0x84,0x05,0xFE,0x04,0x84,0x74,0x84,0x04,0x04,0x00
0x40,0x30,0x4F,0x41,0x44,0x44,0x44,0x45,0x7F,0x45,0x44,0x44,0x44,0x41,0x40,0x00
0x08,0x08,0x08,0x08,0xC8,0x38,0x0F,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00
0x08,0x04,0x02,0x01,0xFF,0x41,0x41,0x41,0x41,0x41,0x41,0x41,0xFF,0x00,0x00,0x00
0x20,0x10,0x2C,0xE7,0x24,0x24,0x10,0x08,0x14,0xA7,0x44,0x24,0x14,0x0C,0x00,0x00
0x01,0x01,0x01,0x7F,0x21,0x11,0x04,0x02,0xFF,0x42,0x42,0x42,0x42,0xFE,0x00,0x00
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
0x10,0x10,0x10,0xD0,0xFF,0x90,0x10,0x00,0xFE,0x22,0x22,0x22,0x22,0xFE,0x00,0x00
0x08,0x04,0x03,0x00,0xFF,0x00,0x03,0x00,0xFF,0x42,0x42,0x42,0x42,0xFF,0x00,0x00
0x00,0x80,0x60,0xF8,0x07,0x00,0x04,0x24,0x24,0x25,0x26,0x24,0x24,0x24,0x04,0x00
0x01,0x00,0x00,0xFF,0x00,0x00,0x00,0xF9,0x49,0x49,0x49,0x49,0x49,0xF9,0x00,0x00
0x00,0x00,0x00,0xF8,0x88,0x8C,0x8A,0x89,0x88,0x88,0x88,0xF8,0x00,0x00,0x00,0x00
0x00,0x00,0x00,0xFF,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0xFF,0x00,0x00,0x00,0x00
0x00,0x00,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0x82,0xFE,0x00,0x00,0x00,0x00
0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x78,0x00,0x00
};
分别将四行汉字的代码写入上面程序,用来对汉字的显示。
子函数的调用:
voidlcd_cmd_wr(ucharcmdcode,ucharf);/调用写命令函数/
voidlcd_data_wr(ucharldata,ucharf);/调用写数据函数/
voidchech_busy(ucharf);/调用读忙函数/
voidlcd_hz_wr(ucharposx,ucharposy,uchar*hz);/调用写汉字函数/
voidlcd_str_wr(ucharrow,ucharcol,ucharn,uchar*str);/调用写结构/
voidlcd_rol();/调用滚屏程序/
voidlcd_init();/调用初始化/
voiddelay(uintn);/延调用时/
LCD12864的汉字显示是利用不同的子函数共同构成的,子函数调用是其一个特点。
主函数:
voidmain()/主函数/
{
while
(1)
{
lcd_init();
lcd_str_wr(0,0,8,hz0);/汉字0的结构/
delay(100);/延时100/
lcd_str_wr(1,0,8,hz1);/汉字1的结构/
delay(100);/延时100/
lcd_str_wr(2,0,8,hz2);/汉字2的结构/
delay(100);/延时100/
lcd_str_wr(3,0,8,hz3);/汉字3的结构/
delay(100);/延时100/
lcd_rol();/滚屏程序/
delay(1000);/延时1000/
lcd_rol();/滚屏程序/
delay(1000);/延时1000/
}
}
主函数是程序的开始部分。
主函数意味着建立一个独立进程,且该进程成为了程序的入口,对其它各函数进行调用,当然其它被调用函数也可以再去调用更多函数。
主函数既是程序的入口,又是程序的出口。
LCD初始化程序:
voidlcd_init()/LCD初始化程序/
{
uinti;
lcd_cmd_wr(0x3f,0);
lcd_cmd_wr(0xc0,0);
lcd_cmd_wr(0xb8,0);
lcd_cmd_wr(0x40,0);
lcd_cmd_wr(0x3f,1);
lcd_cmd_wr(0xc0,1);
lcd_cmd_wr(0xb8,1);
lcd_cmd_wr(0x40,1);
for(i=0;i<256;i++)/循环256/
{
lcd_data_wr(0x00,0);
lcd_data_wr(0x00,1);
}
lcd_cmd_wr(0xb8+4,0);
lcd_cmd_wr(0xb8+4,1);
for(i=0;i<256;i++)/循环256/
{
lcd_data_wr(0x00,0);
lcd_data_wr(0x00,1);
}
}
LCD初始化程序是为第一次显示做准备,初始化要做的有:
显示模式设置,显示开、关和光标设置,清屏,显示光标移动设置,显示开及光标设置……
LCD写命令程序:
voidlcd_cmd_wr(ucharcmdcode,ucharf)/LCD写命令程序/
{
chech_busy(f);/读忙/
if(f==0)LLCD_CMD_WR=cmdcode;
elseRLCD_CMD_WR=cmdcode;
}
将汉字代码写入程序。
读忙程序:
voidchech_busy(ucharf)/读忙程序/
{
if(f==0)LLCD_CMD_RD;/左屏读命令/
elseRLCD_CMD_RD;/右屏读命令/
while(busy);
}
这是检测LCD忙否的函数,如果是1说明数据还没传完,此时LCD忙碌,否则LCD空闲。
voidlcd_str_wr(ucharrow,ucharcol,ucharn,uchar*str)/写结构函数/
{
uchari;
for(i=0;i{
lcd_hz_wr(row,col,str+i*32);/写汉字/
delay(50);/延时50/
col++;
}
}
写汉字程序:
voidlcd_hz_wr(ucharposx,ucharposy,uchar*hz)/写汉字程序/
{
uchari;
if(posy<4)
{
lcd_cmd_wr(0xb8+2*posx,0);/写命令/
lcd_cmd_wr(0x40+16*posy,0);/写命令/
for(i=0;i<16;i++)lcd_data_wr(hz[i],0);/循环16写数据/
lcd_cmd_wr(0xb8+2*posx+1,0);/写命令/
lcd_cmd_wr(0x40+16*posy,0);/写命令/
for(i=16;i<32;i++)lcd_data_wr(hz[i],0);/循环16写数据/
}
else
{
lcd_cmd_wr(0xb8+2*posx,1);/写命令/
lcd_cmd_wr(0x40+16*(posy-4),1);/写命令/
for(i=0;i<16;i++)lcd_data_wr(hz[i],1);/循环16写数据/
lcd_cmd_wr(0xb8+2*posx+1,1);/写命令/
lcd_cmd_wr(0