12864LCD显示程序.doc_第1页
12864LCD显示程序.doc_第2页
12864LCD显示程序.doc_第3页
12864LCD显示程序.doc_第4页
12864LCD显示程序.doc_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

/*|* 12864LCD显示程序 proteus6.9 仿真AMPIRE128*64 *|* 制作人:熊涛 *|* 时间:2007年4月12日 *|* 接口定义:P1接数据 DB7DB0 *|* P2.0 P2.1 P2.2 P2.3 P2.4 接控制线 *| |* 具体见定义 *|*/*|* 注:本程序只能写16*16的汉字 并且有一个小问题 就是 *|* 当字库中汉字的代码的第一个数据不是0x00时 该汉字就不 *|* 能显示出来 调试时发现是因为不能检索到那个汉字 具体原 *|* 因还在调试中 直接写汉字句子时注意两个字节一个字,不要 *|* 弄半角的字符或标点符号否则后面的汉字将找不到 *|* 2007年4月14日1时 修改 熊涛 *|*/#include #include /包含字库 该字库采用晓奇工作室液晶字模提取软件默认保存的文件 采用结构体数组定义的方法#include typedef unsigned char uchar;typedef unsigned int uint;struct word_BUFFER uchar word2; ; struct word_BUFFER word_buf33; /定义结构体数组用来存储待显示的汉字共个 uchar bank=0; /设置第几行反显 0表示不反显 14表示各行的反显uchar key=0; /第几个键被按下sbit DI =P37; / 数据指令 选择sbit RW =P36; / 读写 选择sbit E =P35; / 读写使能sbit CS2 =P34; / 片选1sbit CS1 =P33; / 片选2sbit RST =P32; / 复位keych(void) /检测是否有键按下子程序/ uint n; if(P2=0xf0) return(0); else while(P2&0xf0!=0xf0) for(n=0;n60000;n+); return(1);keyscan() / 检测是哪个键按下子程序/ uchar m,n; uchar code k4=0xfe,0xfd,0xfb,0xf7; for(m=0;mL DB7DB0的数据被写到IR或DR /*|* 写数据子程序 *|* 入口参数:dat 显示字符的数据 *|* oppo 标志位 1:显示阳文 *|* 0:显示阴文 *|* 出口参数:null *|* 调用函数: null *|*/ void write_dat(uchar dat,bit oppo) /写数据子程序 RW=0; DI=1; /DI=1 写数据 E=1; if(oppo=0) P1=dat; /按位取反得阴文 if(oppo=1) P1=dat; oppo=1; E=0; /RW=L,E=H-L DB7DB0的数据被写到IR或DR /*|* 设置显示起始行 X地址和Y地址 *|* 入口参数:st_line 显示起始行 063 *| |* x_add 页地址 8行为一页 07 *|* y_add Y地址 0128 *|* 出口参数:null *|* 调用函数: write_cmd() *|*/ void set_dis(uchar st_line,uchar x_add,uchar y_add) /设置显示起始行 X地址和Y地址 write_cmd(st_line+0xc0); /+0xc0是参照设置起始行的格式 write_cmd(x_add+0xb8); /+0xb8是参照设置页地址的格式 if(y_add64) CS1=0;CS2=1;write_cmd(y_add+0x40); /Y_add地址实际上只有063 采用CS1和CS2选左右半屏 else CS1=1;CS2=0;write_cmd(y_add); /*|* 写汉字子程序1 可以在任意位置写入 *|* 入口参数:st_line 显示起始行 063 *| |* x_add 页地址 8行为一页 07 *|* y_add Y地址 0128 *|* Index2 字符串数组 用来存储汉字*|* 出口参数:null *|* 调用函数: write_cmd() set_dis() *|* strcmp() write_dat() *|*/ void write_word_all(uchar st_line,uchar x_add,uchar y_add,uchar Index2) /写入汉字 uchar i,j; bit oppo=1; if(y_add64) CS1=0;CS2=1;write_cmd(y_add+0x40); else CS1=1;CS2=0;write_cmd(y_add); set_dis(st_line, x_add,y_add); if(bank%5=0) oppo=1; if(bank%5=1&(x_add=0|x_add=1) oppo=0; if(bank%5=2&(x_add=2|x_add=3) oppo=0; if(bank%5=3&(x_add=4|x_add=5) oppo=0; if(bank%5=4&(x_add=6|x_add=7) oppo=0; for(i=0;i255;i+) if (GB_16i.Index0=Index0 & GB_16i.Index1=Index1) /汉字作为双字节字符串处理 采用顺序检索方式查找结构体名 for(j=0;j16;j+) write_dat(GB_16i.Mskj,oppo); /逐字节写入 set_dis(st_line, x_add+1,y_add); /下一页 写字的下半部分 for(j=16;j32;j+) write_dat(GB_16i.Mskj,oppo);break; /此处用break是为了能跳出for循环 /*|* 写汉字子程序2 只能在指定位置写入 *|* 入口参数:n 指定地址 031 全屏32字(16*16) *|* Index2 字符串数组 用来存储汉字*|* 出口参数:null *|* 调用函数: write_word_all() *|* *|*/ void write_word(uchar n,uchar Index2) /写入汉字 uchar st_line=0,x_add=n%32/8*2,y_add=n%32%8*16; write_word_all(st_line,x_add,y_add,Index); /*|* 写句子子程序 *|* 入口参数:sentence 待写入汉字 组成字符串*|* 按照031的顺序写入 *|* 出口参数:null *|* 调用函数: strlen() write_word() *|* *|*/ void write_sentence(uchar sentence255) uchar i,j=0; if(keych()=1) keyscan(); if(key=0) bank+; if(key=1) bank-; for(i=0;istrlen(sentence)/2;i+) word_bufi.word0=sentencei*2;word_bufi.word1=sentencei*2+1; /从sentence中两个两个的取字符串即汉字 注意不要弄半角的字符或标点符号,否则后面的汉字将找不到 write_word(j+,word_bufi.word); /*void Scrolling(uchar sentence255) /滚动显示子程序 uchar i,j=0; int k=2000; for(i=0;istrlen(sentence)/2;i+) for(j=0;j=i;j+) word_bufi.word0=sentencei*2;word_bufi.word1=sentencei*2+1; write_word(i,word_bufi.word); ; */*|* 初始化子程序 *|* 入口参数:null *|* 出口参数:null *|* 调用函数: null *|*/ /*void initial(void) /初始化子程序 write_cmd(0x3e); /关显示 */ /*|* 主程序入口 *|* 12864LCD显示程序 proteus6.9 仿真AMPIRE128*64 *|* 制作人:熊涛 *|* 时间:2007年4月12日 *|* *|*/ void main(void) /主程序P0=0xaa; / uint n=65535; /write_cmd(0x3e); /关显示 / 故人西辞黄鹤楼,烟花三月下扬州。孤帆远影碧空尽唯见长江天际流 / write_sentence(单片机液晶显示 武汉理工大学余区熊涛制作 悠悠苍天奈何独立苍茫); / write_sentence(故人西辞黄鹤楼,烟花叁月下扬州。); / write_sentence(孤帆远影碧空尽,唯见长江天际流。); / write_word(31,。); / write_word_all(0,6,112,黄); /Scrolling(单片机控制液晶武汉理工大学熊涛制作); while(1) P2=0xf0; P0=P0; write_sentence(单片机液晶显示 武汉理工大学余区熊涛 制作 悠悠苍天独立苍茫); / while(n-);/ n=65535;/ while(n-);/ n=65535;/ P0=0x55; / write_sentence( ); / write_sentence(悠悠苍天 奈何独立苍茫 熊涛制作 单片机液晶显示 );/ while(n-); / n=65535;/ while(n-); / write_sentence( );/ n=65535; CS1=CS2=1; write_cmd(0x3f); /开显示 /* while(1) write_sentence(故人西辞黄鹤楼,烟花叁月下扬州。); while(k-); write_sentence(孤帆远影碧空尽,唯见长江天际流。); while(k-); */ / - 汉字字模的数据结构定义 - /typedef struct typFNT_GB16 / 汉字字模数据结构 signed char Index2; / 汉字内码索引 char Msk32; / 点阵码数据;/ 汉字字模表 / Font:楷体_GB231216, 纵向取模下高位,数据排列:从左到右从上到下 /struct typFNT_GB16 code GB_16 = / 数据表 , 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,0x00,0x00,0x70,0x92,0xAC,0xA8, 0xF8,0xAC,0x8A,0x69,0x18,0x00,0x00,0x00, 0x00,0x04,0x04,0x04,0x04,0x04,0x04,0x04, 0x7F,0x02,0x02,0x02,0x02,0x02,0x02,0x00,片, 0x00,0x00,0x00,0x00,0x00,0xFE,0x20,0x20, 0x20,0xA0,0x9F,0x10,0x10,0x00,0x00,0x00, 0x00,0x00,0x20,0x10,0x0C,0x03,0x01,0x01, 0x01,0x00,0x3F,0x00,0x00,0x00,0x00,0x00,机, 0x00,0x00,0x20,0x20,0xFF,0x90,0x10,0x00, 0x00,0xF0,0x08,0xE8,0x18,0x00,0x00,0x00, 0x00,0x04,0x02,0x01,0x3F,0x00,0x11,0x08, 0x06,0x01,0x00,0x07,0x08,0x08,0x08,0x0E,液, 0x00,0x00,0x20,0x64,0x0C,0x00,0x90,0x70, 0x10,0x89,0x6A,0x48,0xC8,0x00,0x00,0x00, 0x00,0x00,0x18,0x07,0x02,0x01,0x3F,0x10, 0x11,0x0A,0x05,0x0A,0x19,0x10,0x10,0x10,晶, 0x00,0x00,0x00,0x00,0x00,0x00,0x3E,0x2A, 0x29,0x21,0xBF,0x80,0x80,0x80,0x00,0x00, 0x00,0x00,0x00,0x3F,0x15,0x11,0x3F,0x00, 0x00,0x3F,0x14,0x14,0x10,0x3F,0x00,0x00,显, 0x00,0x00,0x00,0x00,0x0C,0x74,0xD4,0x54, 0x2A,0xAA,0x22,0x1E,0x80,0x00,0x00,0x00, 0x00,0x20,0x20,0x22,0x24,0x20,0x1F,0x10, 0x10,0x1F,0x14,0x12,0x11,0x10,0x10,0x00,示, 0x00,0x00,0x40,0x40,0x40,0x44,0x44,0x44, 0xC4,0x24,0x22,0x22,0x20,0x20,0x20,0x00, 0x00,0x00,0x00,0x0C,0x07,0x00,0x00,0x10, 0x3F,0x00,0x00,0x01,0x02,0x06,0x00,0x00,武, 0x00,0x00,0x00,0x40,0x50,0x50,0xC8,0x28, 0x20,0xFF,0x10,0x12,0x14,0x00,0x00,0x00, 0x00,0x00,0x20,0x20,0x1F,0x10,0x0F,0x09, 0x09,0x00,0x03,0x0C,0x10,0x20,0x40,0x78,汉, 0x00,0x20,0x40,0x02,0x84,0x00,0x28,0x48, 0x88,0x04,0xE4,0x1C,0x00,0x00,0x00,0x00, 0x00,0x00,0x18,0x06,0x09,0x08,0x04,0x04, 0x02,0x01,0x02,0x04,0x0C,0x08,0x08,0x00,理, 0x00,0x00,0x88,0x88,0xF8,0x44,0x00,0x1C, 0xE4,0xA4,0xFC,0x52,0x42,0x7E,0x00,0x00, 0x00,0x08,0x08,0x04,0x07,0x12,0x12,0x10, 0x12,0x12,0x0F,0x09,0x09,0x08,0x08,0x00,工, 0x00,0x00,0x00,0x00,0x00,0x10,0x10,0x10, 0xF0,0x08,0x08,0x08,0x00,0x00,0x00,0x00, 0x00,0x00,0x08,0x08,0x08,0x08,0x08,0x08, 0x07,0x04,0x04,0x04,0x04,0x04,0x04,0x00,大, 0x00,0x00,0x00,0x40,0x40,0x40,0x40,0xFF, 0x20,0x20,0x20,0x20,0x20,0x00,0x00,0x00, 0x00,0x00,0x20,0x10,0x08,0x04,0x03,0x00, 0x01,0x02,0x04,0x08,0x10,0x30,0x20,0x20,学, 0x00,0x00,0xC0,0x70,0x22,0x24,0xA0,0x52, 0x54,0xD0,0x58,0x17,0x10,0x30,0x10,0x00, 0x00,0x00,0x04,0x04,0x04,0x04,0x04,0x24, 0x43,0x3E,0x02,0x02,0x02,0x02,0x00,0x00,余, 0x00,0x00,0x80,0x40,0x20,0x50,0x4C,0xC3, 0x24,0x28,0x10,0x20,0x60,0x40,0x40,0x40, 0x00,0x01,0x00,0x22,0x1A,0x02,0x22,0x7F, 0x01,0x01,0x05,0x09,0x10,0x00,0x00,0x00,区, 0x00,0x00,0x00,0x04,0xFC,0x04,0x04,0x24, 0x44,0x82,0x42,0x3A,0x02,0x02,0x00,0x00, 0x00,0x00,0x00,0x00,0x3F,0x20,0x14,0x12, 0x11,0x10,0x11,0x12,0x14,0x10,0x00,0x00,熊, 0x00,0x00,0x00,0x10,0xD8,0xB4,0x2B,0xEC, 0x00,0x0F,0xD4,0x14,0x92,0x18,0x00,0x00, 0x00,0x00,0x20,0x30,0x07,0x02,0x14,0x27, 0x00,0x10,0x23,0x05,0x04,0x14,0x23,0x00,涛, 0x00,0x10,0x20,0x82,0x0C,0x40,0x40,0xD4, 0x74,0x5F,0x2A,0xAA,0x22,0x20,0x00,0x00, 0x00,0x08,0x0C,0x23,0x10,0x08,0x06,0x03, 0x06,0x2A,0x42,0x3F,0x01,0x01,0x01,0x00,制, 0x00,0x00,0x80,0xA0,0x98,0x90,0xFE,0x48, 0x48,0x40,0x00,0xF0,0x00,0xFE,0x00,0x00, 0x00,0x00,0x00,0x0E,0x02,0x02,0x3F,0x09, 0x0F,0x00,0x00,0x03,0x10,0x3F,0x00,0x00,作, 0x00,0x80,0x40,0x20,0xF0,0x0E,0x80,0x40, 0x30,0x1C,0xF3,0x90,0x88,0x88,0x08,0x00, 0x00,0x00,0x00,0x00,0x1F,0x00,0x00,0x00, 0x00,0x00,0x7F,0x04,0x04,0x04,0x00,0x00,悠, 0x00,0x80,0x40,0x20,0xF8,0x06,0xF0,0x10, 0x88,0x57,0x24,0x5C,0x84,0x84,0x80,0x00, 0x00,0x00,0x10,0x0C,0x01,0x04,0x08,0x11, 0x22,0x24,0x20,0x28,0x30,0x22,0x04,0x00,苍, 0x00,0x00,0x08,0x08,0x08,0x85,0x4F,0x34, 0x14,0x24,0x4F,0x84,0x84,0x04,0x00,0x00, 0x00,0x04,0x04,0x02,0x01,0x00,0x3E,0x41, 0x41,0x49,0x47,0x40,0x39,0x01,0x01,0x01,天, 0x00,0x00,0x00,0x40,0x44,0x44,0x44,0xFC, 0x22,0x22,0x22,0x20,0x00,0x00,0x00,0x00, 0x00,0x20,0x20,0x10,0x08,0x04,0x03,0x00, 0x01,0

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论