《128x64液晶KS0108控制器驱动程序.docx》由会员分享,可在线阅读,更多相关《128x64液晶KS0108控制器驱动程序.docx(17页珍藏版)》请在第一文库网上搜索。
1、#includeabsacc.hincludeintrins.h自定义库在C:comp51UserLib文件夹中include“.incASCII816.h”标准ASCII库include”.incHZTable.h汉字点阵库(自做)#include.incMenu.h菜单库(自做)/LCD128*64数据线#defineLCD12864DataPortPl/LCD128*64I/O信号管脚sbitdi=P3A1;/数据、指令选择sbitrw=P3八3;读、写选择sbiten=P3A2;/读、写使能sbitcsl=P3八4;片选1,低有效(前64列)sbitcs2=P3A5;/片选2,低有效(
2、后64列)sbitreset=P0A7;/复位*/*函数歹u表*开关显示voidSetOnOfffunsignedcharonoff)选择屏幕/screen:0全屏,1左屏,2-右voidSelectScreen(unsignedcharscreen)清屏/screen:0全屏,1左屏,2-右voidClearScreen(unsignedcharscreen)显示8*8点阵旋转90度:字模被竖着切分lin:行(0-7),column:列(0-15)/address:字模区首地址voidShow88(unsignedcharlin,unsignedcharcolumn,unsignedinta
3、ddress)显示8*16字符旋转90度:字模被竖着切分lin:行(0-3),column:列(0-15)“character:字符代码(标准ASCII码)voidShowChar(unsignedcharlin,unsignedcharcolumn,unsignedcharcharacter)显示8*16字符串!只能显示在一行上即:串长+column=15旋转90度:字模被竖着切分lin:行(0-3),column:列(0-15)/address:字模区首地址voidShowString(unsignedcharlin,unsignedcharcolumn,unsignedchar*stri
4、ng)显示一个汉字旋转90度:字模被竖着切分lin:行(0-3),column:列(0-15)/hzcode:汉字代码档定义的)voidShowHZ(unsignedcharlin,unsignedcharcolumn,unsignedinthzcode)显示图片旋转90度:字模被竖着切分/startline:开始行startcolumn:开始歹ijlinechar:图片行点除8(图片以8*8点阵为单位)/columnchar:图片列点除8(图片以8*8点阵为单位)/address:字模区首地址voidShowPicturefunsignedcharstartline,unsignedchar
5、startcolumn,unsignedcharlinechar;unsignedcharcolumncharzunsignedintaddress)!问题大户显示一行汉字lin:行/lineheadaddr:此行汉字代码区首地址voidShowLine(unsignedcharlin,unsignedintlineheadaddr)显示一屏汉字pageheadaddr:此屏汉字代码地址区首地址voidShowPage(unsignedintpageheadaddr)反显一个8*8字块lin:行(0-3),column:列(07)voidReverseShow88(unsignedcharli
6、n,unsignedcharcolumn)反显一个字符lin:行(0-4),column:列(0-15)voidReverseShowChar(unsignedcharlin,unsignedcharcolumn)反显一个汉字lin:行(0-3),column:列(0-7)ReverseShowHZ(unsignedcharlin,unsignedcharcolumn)反显一行汉字lin:行ReverseShow(unsignedcharlin)初始化LCDvoidlnitLCD()*函数列表结束*/*/*基本函数源程序*/延时Lcdl2864delay()unsignedinti=500;w
7、hile(i-);)/*/状态检查voidCheckState()(unsignedchardat;di=0;rw=l;doLCD12864DataPort=0xff;en=l;dat=LCD12864DataPort;en=0;dat=0x90&dat;仅当第4,7位为0时才可操作while(!(dat=0x00);)/*/写显示数据dat:显示数据voidWriteByte(unsignedchardat)CheckState();di=l;rw=0;LCD12864DataPort=dat;en=l;en=0;向LCD发送命令/command:命令SendCommandToLCD(uns
8、ignedcharcommand)(CheckState();rw=0;LCD12864DataPort=command;en=l;en=0;)设定行地址(页卜-X0-7voidSetLine(unsignedcharline)line=line&0x07;/0=line=7line=line10xb8;/1011lxxxSendCommandToLCD(line);设定列地址-Y0-63voidSetColumn(unsignedcharcolumn)column=column&0x3f;/0=column=63column=column|0x40;/OlxxxxxxSendCommandT
9、oLCD(column);)设定显示开始行XXvoidSetStartLine(unsignedcharstartline)/0-63startline=startline&0x07;startline=startline|0xc0;/11000000SendCommandToLCD(startline);)开关显示voidSetOnOff(unsignedcharonoff)onoff=0x3e|onoff;/0011lllxSendCommandToLCD(onoff);)选择屏幕/screen:0全屏,1左屏2右屏voidSelectScreen(unsignedcharscreen)(
10、北京显示器:负有效csl:0-右;cs2:0-左switch(screen)case0:csl=0;全屏_nop_();_nopj);_nopj);_nop_();_nop_();_nop_();_nopj);_nop_();_nopj);_nop_();_nop_();cs2=0;_nopj);_nop_();_nopj);_nopj);_nop_();_nopj);_nopj);_nopj);_nop_();_nop_();nopj);break;case 1: csl=l;左屏_nopj);_nop_();_nopj);_nopj);_nop_();_nopj);_nopj);_nopj
11、);_nop_();_nop_();cs2=0;_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();break;case 2: csl=0;右屏_nop_();_nopj);_nopj);_nopj);_nop_();_nopj);_nop_();_nopj);_nop_();_nopj);cs2=l;_nop_();_nopj);_nopj);_nop_();_nop_();_nop_();_nopj);_nop_();_nopj);_nop_();break;)nop_();_nop
12、_();_nop_();_nop_();)清屏/screen:0全屏3左屏2右voidClearScreen(unsignedcharscreen)unsignedcharij;SelectScreen(screen);for(i=0;i8;i+)SetLine(i);for(j=0;j16)return;if(column8)SelectScreen;如果列数8(0,1,234,5,6,7)则写在第一屏上elseSelectScreen(2);否则(8,9,10,11,12,23,14,15)写在第二屏上column=column&0x07;防止越界)SetLine(lin);SetColu
13、mn(column3);for(i=0;i8;i+)WriteByte(CBYTEaddress+i);)/*/显示8*16字符旋转90度:字模被竖着切分lin:行(0-3),column:列(0-15)“character:字符代码(标准ASCII码)voidShowChar(unsignedcharlin,unsignedcharcolumn,unsignedcharcharacter)Show88(lin,column,ASCII816character-0x20);Show88(lin+1,column,ASCII816character-0x20+8);)/*/*显示8*16字符串!只能显示在一行上即:串长+column15)break;(只能显示在一行上即:串长+columnv=15)ShowChar(lin,i+column,c