12864液晶屏驱动程序分享

编程实验

72人已加入

描述

  概述

  带中文字库的128X64是一种具有4位/8位并行、2线或3线串行多种接口方式,内部含有国标一级、二级简体中文字库的点阵图形液晶显示模块;其显示分辨率为128×64,内置8192个16*16点汉字,和128个16*8点ASCII字符集。利用该模块灵活的接口方式和简单、方便的操作指令,可构成全中文人机交互图形界面。可以显示8×4行16×16点阵的汉字。也可完成图形显示。低电压低功耗是其又一显著特点。由该模块构成的液晶显示方案与同类型的图形点阵液晶显示模块相比,不论硬件电路结构或显示程序都要简洁得多,且该模块的价格也略低于相同点阵的图形液晶模块。

  12864基本参数

12864

  12864电气特性

12864

  12864极限参数

12864

  12864光学特性

12864

  12864管脚及功能

12864
12864

  12864应用举例

  1、使用前的准备

  先给模块加上工作电压,再按照下图的连接方法调节LCD的对比度,使其显示出黑色的底影。此过程亦可以初步检测LCD有无缺段现象。

  2、字符显示

  带中文字库的128X64-0402B每屏可显示4行8列共32个16×16点阵的汉字,每个显示RAM可显示1个中文字符或2个16×8点阵全高ASCII码字符,即每屏最多可实现32个中文字符或64个ASCII码字符的显示。带中文字库的128X64-0402B内部提供128×2字节的字符显示RAM缓冲区(DDRAM)。字符显示是通过将字符显示编码写入该字符显示RAM实现的。根据写入内容的不同,可分别在液晶屏上显示CGROM(中文字库)、HCGROM(ASCII码字库)及CGRAM(自定义字形)的内容。三种不同字符/字型的选择编码范围为:0000~0006H(其代码分别是0000、0002、0004、0006共4个)显示自定义字型,02H~7FH显示半宽ASCII码字符,A1A0H~F7FFH显示8192种GB2312中文字库字形。字符显示RAM在液晶模块中的地址80H~9FH。字符显示的RAM的地址与32个字符显示区域有着一一对应的关系,其对应关系如下表所示。

12864

  3、图形显示

  先设垂直地址再设水平地址(连续写入两个字节的资料来完成垂直与水平的坐标地址)

  垂直地址范围AC5.。.AC0

  水平地址范围AC3…AC0

  绘图RAM的地址计数器(AC)只会对水平地址(X轴)自动加一,当水平地址=0FH时会重新设为00H但并不会对垂直地址做进位自动加一,故当连续写入多笔资料时,程序需自行判断垂直地址是否需重新设定。GDRAM的坐标地址与资料排列顺序如下图:

12864

  4、应用说明

  用带中文字库的128X64显示模块时应注意以下几点:

  ①欲在某一个位置显示中文字符时,应先设定显示字符位置,即先设定显示地址,再写入中文字符编码。

  ②显示ASCII字符过程与显示中文字符过程相同。不过在显示连续字符时,只须设定一次显示地址,由模块自动对地址加1指向下一个字符位置,否则,显示的字符中将会有一个空ASCII字符位置。

  ③当字符编码为2字节时,应先写入高位字节,再写入低位字节。

  ④模块在接收指令前,向处理器必须先确认模块内部处于非忙状态,即读取BF标志时BF需为“0”,方可接受新的指令。如果在送出一个指令前不检查BF标志,则在前一个指令和这个指令中间必须延迟一段较长的时间,即等待前一个指令确定执行完成。指令执行的时间请参考指令表中的指令执行时间说明。

  ⑤“RE”为基本指令集与扩充指令集的选择控制位。当变更“RE”后,以后的指令集将维持在最后的状态,除非再次变更“RE”位,否则使用相同指令集时,无需每次均重设“RE”位。

  12864液晶屏驱动程序分享

  #include《absacc.h》

  #include《reg52.h》

  #include《stdarg.h》

  #include《stdio.h》

  #defineulongunsignedlong

  #defineuintunsignedint

  #defineucharunsignedchar

  #defineSTX0x02

  #defineETX0x03

  #defineEOT0x04

  #defineENQ0x05

  #defineBS0x08

  #defineCR0x0D

  #defineLF0x0A

  #defineDLE0x10

  #defineETB0x17

  #defineSPACE0x20

  #defineCOMMA0x2C

  #defineTRUE1

  #defineFALSE0

  #defineHIGH1

  #defineLOW0

  //T6963C端口定义

  #defineLCMDWXBYTE[0x5000]//数据口

  #defineLCMCWXBYTE[0x5002]//命令口

  //T6963C命令定义

  #defineLC_CUR_POS0x21//光标位置设置

  #defineLC_CGR_POS0x22//CGRAM偏置地址设置

  #defineLC_ADD_POS0x24//地址指针位置

  #defineLC_TXT_STP0x40//文本区首址

  #defineLC_TXT_WID0x41//文本区宽度

  #defineLC_GRH_STP0x42//图形区首址

  #defineLC_GRH_WID0x43//图形区宽度

  #defineLC_MOD_OR0x80//显示方式:逻辑“或”

  #defineLC_MOD_XOR0x81//显示方式:逻辑“异或”

  #defineLC_MOD_AND0x82//显示方式:逻辑“与”

  #defineLC_MOD_TCH0x83//显示方式:文本特征

  #defineLC_DIS_SW0x90//显示开关:D0=1/0:光标闪烁启用/禁用;

  //D1=1/0:光标显示启用/禁用;

  //D2=1/0:文本显示启用/禁用;

  //D3=1/0:图形显示启用/禁用;

  #defineLC_CUR_SHP0xA0//光标形状选择:0xA0-0xA7表示光标占的行数

  #defineLC_AUT_WR0xB0//自动写设置

  #defineLC_AUT_RD0xB1//自动读设置

  #defineLC_AUT_OVR0xB2//自动读/写结束

  #defineLC_INC_WR0xC0//数据一次写,地址加1

  #defineLC_INC_RD0xC1//数据一次读,地址加1

  #defineLC_DEC_WR0xC2//数据一次写,地址减1

  #defineLC_DEC_RD0xC3//数据一次读,地址减1

  #defineLC_NOC_WR0xC4//数据一次写,地址不变

  #defineLC_NOC_RD0xC5//数据一次读,地址不变

  #defineLC_SCN_RD0xE0//屏读

  #defineLC_SCN_CP0xE8//屏拷贝

  #defineLC_BIT_OP0xF0//位操作:D0-D2:定义D0-D7位;D3:1置位;0:清除

  codeucharconstuPowArr[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};

  //ASCII字模宽度及高度定义

  #defineASC_CHR_WIDTH8

  #defineASC_CHR_HEIGHT12

  //ASCII字模,显示为8*16

  charcodeASC_MSK[96*12]={

  //Terminal9;此字体下对应的点阵为:宽x高=8x12

  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,0xff,//《0x20时,打印此字

  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//‘’

  0x00,0x0C,0x1E,0x1E,0x1E,0x0C,0x0C,0x00,0x0C,0x0C,0x00,0x00,//‘!’

  0x00,0x66,0x66,0x66,0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//‘“’

  0x00,0x36,0x36,0x7F,0x36,0x36,0x36,0x7F,0x36,0x36,0x00,0x00,//‘#’

  0x0C,0x0C,0x3E,0x03,0x03,0x1E,0x30,0x30,0x1F,0x0C,0x0C,0x00,//‘$’

  0x00,0x00,0x00,0x23,0x33,0x18,0x0C,0x06,0x33,0x31,0x00,0x00,//‘%’

  0x00,0x0E,0x1B,0x1B,0x0E,0x5F,0x7B,0x33,0x3B,0x6E,0x00,0x00,//‘&’

  0x00,0x0C,0x0C,0x0C,0x06,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//‘’‘

  0x00,0x30,0x18,0x0C,0x06,0x06,0x06,0x0C,0x18,0x30,0x00,0x00,//’(‘

  0x00,0x06,0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x06,0x00,0x00,//’)‘

  0x00,0x00,0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00,0x00,0x00,//’*‘

  0x00,0x00,0x00,0x18,0x18,0x7E,0x18,0x18,0x00,0x00,0x00,0x00,//’+‘

  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x06,0x00,//’,‘

  0x00,0x00,0x00,0x00,0x00,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,//’-‘

  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,//’。‘

  0x00,0x00,0x40,0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00,0x00,//’/‘

  0x00,0x3E,0x63,0x73,0x7B,0x6B,0x6F,0x67,0x63,0x3E,0x00,0x00,//’0‘

  0x00,0x08,0x0C,0x0F,0x0C,0x0C,0x0C,0x0C,0x0C,0x3F,0x00,0x00,//’1‘

  0x00,0x1E,0x33,0x33,0x30,0x18,0x0C,0x06,0x33,0x3F,0x00,0x00,//’2‘

  0x00,0x1E,0x33,0x30,0x30,0x1C,0x30,0x30,0x33,0x1E,0x00,0x00,//’3‘

  0x00,0x30,0x38,0x3C,0x36,0x33,0x7F,0x30,0x30,0x78,0x00,0x00,//’4‘

  0x00,0x3F,0x03,0x03,0x03,0x1F,0x30,0x30,0x33,0x1E,0x00,0x00,//’5‘

  0x00,0x1C,0x06,0x03,0x03,0x1F,0x33,0x33,0x33,0x1E,0x00,0x00,//’6‘

  0x00,0x7F,0x63,0x63,0x60,0x30,0x18,0x0C,0x0C,0x0C,0x00,0x00,//’7‘

  0x00,0x1E,0x33,0x33,0x37,0x1E,0x3B,0x33,0x33,0x1E,0x00,0x00,//’8‘

  0x00,0x1E,0x33,0x33,0x33,0x3E,0x18,0x18,0x0C,0x0E,0x00,0x00,//’9‘

  0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,0x1C,0x1C,0x00,0x00,0x00,//’:‘

  0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,0x1C,0x1C,0x18,0x0C,0x00,//’;‘

  0x00,0x30,0x18,0x0C,0x06,0x03,0x06,0x0C,0x18,0x30,0x00,0x00,//’《‘

  0x00,0x00,0x00,0x00,0x7E,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,//’=‘

  0x00,0x06,0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x06,0x00,0x00,//’》‘

  0x00,0x1E,0x33,0x30,0x18,0x0C,0x0C,0x00,0x0C,0x0C,0x00,0x00,//’?‘

  0x00,0x3E,0x63,0x63,0x7B,0x7B,0x7B,0x03,0x03,0x3E,0x00,0x00,//’@‘

  0x00,0x0C,0x1E,0x33,0x33,0x33,0x3F,0x33,0x33,0x33,0x00,0x00,//’A‘

  0x00,0x3F,0x66,0x66,0x66,0x3E,0x66,0x66,0x66,0x3F,0x00,0x00,//’B‘

  0x00,0x3C,0x66,0x63,0x03,0x03,0x03,0x63,0x66,0x3C,0x00,0x00,//’C‘

  0x00,0x1F,0x36,0x66,0x66,0x66,0x66,0x66,0x36,0x1F,0x00,0x00,//’D‘

  0x00,0x7F,0x46,0x06,0x26,0x3E,0x26,0x06,0x46,0x7F,0x00,0x00,//’E‘

  0x00,0x7F,0x66,0x46,0x26,0x3E,0x26,0x06,0x06,0x0F,0x00,0x00,//’F‘

  0x00,0x3C,0x66,0x63,0x03,0x03,0x73,0x63,0x66,0x7C,0x00,0x00,//’G‘

  0x00,0x33,0x33,0x33,0x33,0x3F,0x33,0x33,0x33,0x33,0x00,0x00,//’H‘

  0x00,0x1E,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00,0x00,//’I‘

  0x00,0x78,0x30,0x30,0x30,0x30,0x33,0x33,0x33,0x1E,0x00,0x00,//’J‘

  0x00,0x67,0x66,0x36,0x36,0x1E,0x36,0x36,0x66,0x67,0x00,0x00,//’K‘

  0x00,0x0F,0x06,0x06,0x06,0x06,0x46,0x66,0x66,0x7F,0x00,0x00,//’L‘

  0x00,0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x63,0x63,0x00,0x00,//’M‘

  0x00,0x63,0x63,0x67,0x6F,0x7F,0x7B,0x73,0x63,0x63,0x00,0x00,//’N‘

  0x00,0x1C,0x36,0x63,0x63,0x63,0x63,0x63,0x36,0x1C,0x00,0x00,//’O‘

  0x00,0x3F,0x66,0x66,0x66,0x3E,0x06,0x06,0x06,0x0F,0x00,0x00,//’P‘

  0x00,0x1C,0x36,0x63,0x63,0x63,0x73,0x7B,0x3E,0x30,0x78,0x00,//’Q‘

  0x00,0x3F,0x66,0x66,0x66,0x3E,0x36,0x66,0x66,0x67,0x00,0x00,//’R‘

  0x00,0x1E,0x33,0x33,0x03,0x0E,0x18,0x33,0x33,0x1E,0x00,0x00,//’S‘

  0x00,0x3F,0x2D,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x1E,0x00,0x00,//’T‘

  0x00,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x1E,0x00,0x00,//’U‘

  0x00,0x33,0x33,0x33,0x33,0x33,0x33,0x33,0x1E,0x0C,0x00,0x00,//’V‘

  0x00,0x63,0x63,0x63,0x63,0x6B,0x6B,0x36,0x36,0x36,0x00,0x00,//’W‘

  0x00,0x33,0x33,0x33,0x1E,0x0C,0x1E,0x33,0x33,0x33,0x00,0x00,//’X‘

  0x00,0x33,0x33,0x33,0x33,0x1E,0x0C,0x0C,0x0C,0x1E,0x00,0x00,//’Y‘

  0x00,0x7F,0x73,0x19,0x18,0x0C,0x06,0x46,0x63,0x7F,0x00,0x00,//’Z‘

  0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00,0x00,//’[‘

  0x00,0x00,0x01,0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00,0x00,//’\‘

  0x00,0x3C,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x3C,0x00,0x00,//’]‘

  0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//’^‘

  0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,//’_‘

  0x0C,0x0C,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//’`‘

  0x00,0x00,0x00,0x00,0x1E,0x30,0x3E,0x33,0x33,0x6E,0x00,0x00,//’a‘

  0x00,0x07,0x06,0x06,0x3E,0x66,0x66,0x66,0x66,0x3B,0x00,0x00,//’b‘

  0x00,0x00,0x00,0x00,0x1E,0x33,0x03,0x03,0x33,0x1E,0x00,0x00,//’c‘

  0x00,0x38,0x30,0x30,0x3E,0x33,0x33,0x33,0x33,0x6E,0x00,0x00,//’d‘

  0x00,0x00,0x00,0x00,0x1E,0x33,0x3F,0x03,0x33,0x1E,0x00,0x00,//’e‘

  0x00,0x1C,0x36,0x06,0x06,0x1F,0x06,0x06,0x06,0x0F,0x00,0x00,//’f‘

  0x00,0x00,0x00,0x00,0x6E,0x33,0x33,0x33,0x3E,0x30,0x33,0x1E,//’g‘

  0x00,0x07,0x06,0x06,0x36,0x6E,0x66,0x66,0x66,0x67,0x00,0x00,//’h‘

  0x00,0x18,0x18,0x00,0x1E,0x18,0x18,0x18,0x18,0x7E,0x00,0x00,//’i‘

  0x00,0x30,0x30,0x00,0x3C,0x30,0x30,0x30,0x30,0x33,0x33,0x1E,//’j‘

  0x00,0x07,0x06,0x06,0x66,0x36,0x1E,0x36,0x66,0x67,0x00,0x00,//’k‘

  0x00,0x1E,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x7E,0x00,0x00,//’l‘

  0x00,0x00,0x00,0x00,0x3F,0x6B,0x6B,0x6B,0x6B,0x63,0x00,0x00,//’m‘

  0x00,0x00,0x00,0x00,0x1F,0x33,0x33,0x33,0x33,0x33,0x00,0x00,//’n‘

  0x00,0x00,0x00,0x00,0x1E,0x33,0x33,0x33,0x33,0x1E,0x00,0x00,//’o‘

  0x00,0x00,0x00,0x00,0x3B,0x66,0x66,0x66,0x66,0x3E,0x06,0x0F,//’p‘

  0x00,0x00,0x00,0x00,0x6E,0x33,0x33,0x33,0x33,0x3E,0x30,0x78,//’q‘

  0x00,0x00,0x00,0x00,0x37,0x76,0x6E,0x06,0x06,0x0F,0x00,0x00,//’r‘

  0x00,0x00,0x00,0x00,0x1E,0x33,0x06,0x18,0x33,0x1E,0x00,0x00,//’s‘

  0x00,0x00,0x04,0x06,0x3F,0x06,0x06,0x06,0x36,0x1C,0x00,0x00,//’t‘

  0x00,0x00,0x00,0x00,0x33,0x33,0x33,0x33,0x33,0x6E,0x00,0x00,//’u‘

  0x00,0x00,0x00,0x00,0x33,0x33,0x33,0x33,0x1E,0x0C,0x00,0x00,//’v‘

  0x00,0x00,0x00,0x00,0x63,0x63,0x6B,0x6B,0x36,0x36,0x00,0x00,//’w‘

  0x00,0x00,0x00,0x00,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00,0x00,//’x‘

  0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x3C,0x30,0x18,0x0F,//’y‘

  0x00,0x00,0x00,0x00,0x3F,0x31,0x18,0x06,0x23,0x3F,0x00,0x00,//’z‘

  0x00,0x38,0x0C,0x0C,0x06,0x03,0x06,0x0C,0x0C,0x38,0x00,0x00,//’{‘

  0x00,0x18,0x18,0x18,0x18,0x00,0x18,0x18,0x18,0x18,0x00,0x00,//’|‘

  0x00,0x07,0x0C,0x0C,0x18,0x30,0x18,0x0C,0x0C,0x07,0x00,0x00,//’}‘

  0x00,0xCE,0x5B,0x73,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,//’~‘

  };

  typedefstructtypFNT_GB16//汉字字模显示数据结构

  {

  charIndex[2];

  charMsk[32];

  };

  structtypFNT_GB16xdataGB_16[]={//显示为16*16

  ”中“,0x01,0x00,0x01,0x00,0x21,0x08,0x3F,0xFC,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x3F,0xF8,0x21,0x08,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,0x01,0x00,

  ”文“,0x02,0x00,0x01,0x00,0x01,0x00,0xFF,0xFE,0x08,0x20,0x08,0x20,0x08,0x20,0x04,0x40,0x04,0x40,0x02,0x80,0x01,0x00,0x02,0x80,0x04,0x60,0x18,0x1E,0xE0,0x08,0x00,0x00,

  ”测“,0x40,0x02,0x27,0xC2,0x24,0x42,0x84,0x52,0x45,0x52,0x55,0x52,0x15,0x52,0x25,0x52,0x25,0x52,0x25,0x52,0xC5,0x52,0x41,0x02,0x42,0x82,0x42,0x42,0x44,0x4A,0x48,0x04,

  ”试“,0x00,0x20,0x40,0x28,0x20,0x24,0x30,0x24,0x27,0xFE,0x00,0x20,0xE0,0x20,0x27,0xE0,0x21,0x20,0x21,0x10,0x21,0x10,0x21,0x0A,0x29,0xCA,0x36,0x06,0x20,0x02,0x00,0x00,

  };

  uchargCurRow,gCurCol;//当前行、列存储,行高16点,列宽8点

  ucharfnGetRow(void)

  {

  returngCurRow;

  }

  ucharfnGetCol(void)

  {

  returngCurCol;

  }

  ucharfnST01(void)//状态位STA1,STA0判断(读写指令和读写数据)

  {

  uchari;

  for(i=10;i》0;i--)

  {

  if((LCMCW&0x03)==0x03)

  break;

  }

  returni;//若返回零,说明错误

  }

  ucharfnST2(void)//状态位ST2判断(数据自动读状态)

  {

  uchari;

  for(i=10;i》0;i--)

  {

  if((LCMCW&0x04)==0x04)

  break;

  }

  returni;//若返回零,说明错误

  }

  ucharfnST3(void)//状态位ST3判断(数据自动写状态)

  {

  uchari;

  for(i=10;i》0;i--)

  {

  if((LCMCW&0x08)==0x08)

  break;

  }

  returni;//若返回零,说明错误

  }

  ucharfnST6(void)//状态位ST6判断(屏读/屏拷贝状态)

  {

  uchari;

  for(i=10;i》0;i--)

  {

  if((LCMCW&0x40)==0x40)

  break;

  }

  returni;//若返回零,说明错误

  }

  ucharfnPR1(ucharuCmd,ucharuPar1,ucharuPar2)//写双参数的指令

  {

  if(fnST01()==0)

  return1;

  LCMDW=uPar1;

  if(fnST01()==0)

  return2;

  LCMDW=uPar2;

  if(fnST01()==0)

  return3;

  LCMCW=uCmd;

  return0;//返回0成功

  }

  ucharfnPR11(ucharuCmd,ucharuPar1)//写单参数的指令

  {

  if(fnST01()==0)

  return1;

  LCMDW=uPar1;

  if(fnST01()==0)

  return2;

  LCMCW=uCmd;

  return0;//返回0成功

  }

  ucharfnPR12(ucharuCmd)//写无参数的指令

  {

  if(fnST01()==0)

  return1;

  LCMCW=uCmd;

  return0;//返回0成功

  }

  ucharfnPR13(ucharuData)//写数据

  {

  if(fnST3()==0)

  return1;

  LCMDW=uData;

  return0;//返回0成功

  }

  ucharfnPR2(void)//读数据

  {

  if(fnST01()==0)

  return1;

  returnLCMDW;

  }

  //设置当前地址

  voidfnSetPos(ucharurow,ucharucol)

  {

  uintiPos;

  iPos=urow*30+ucol;

  fnPR1(LC_ADD_POS,iPos&0xFF,iPos/256);

  gCurRow=urow;

  gCurCol=ucol;

  }

  //设置当前显示行、列

  voidcursor(ucharuRow,ucharuCol)

  {

  fnSetPos(uRow*16,uCol);

  }

  //清屏

  voidcls(void)

  {

  uinti;

  fnPR1(LC_ADD_POS,0x00,0x00);//置地址指针

  fnPR12(LC_AUT_WR);//自动写

  for(i=0;i《240*30;i++)

  {

  fnST3();

  fnPR13(0x00);//写数据

  }

  fnPR12(LC_AUT_OVR);//自动写结束

  fnPR1(LC_ADD_POS,0x00,0x00);//重置地址指针

  gCurRow=0;//置地址指针存储变量

  gCurCol=0;

  }

  //LCM初始化

  charfnLCMInit(void)

  {

  if(fnPR1(LC_TXT_STP,0x00,0x00)!=0)//文本显示区首地址

  return-1;

  fnPR1(LC_TXT_WID,0x1E,0x00);//文本显示区宽度

  fnPR1(LC_GRH_STP,0x00,0x00);//图形显示区首地址

  fnPR1(LC_GRH_WID,0x1E,0x00);//图形显示区宽度

  fnPR12(LC_CUR_SHP|0x01);//光标形状

  fnPR12(LC_MOD_OR);//显示方式设置

  fnPR12(LC_DIS_SW|0x08);//显示开关设置

  return0;

  }

  //ASCII(8*16)及汉字(16*16)显示函数

  uchardprintf(char*fmt,。。.)

  {

  va_listarg_ptr;

  charc1,c2,cData;

  chartmpBuf[64];//LCD显示数据缓冲区

  uchari=0,j,uLen,uRow,uCol;

  uintk;

  va_start(arg_ptr,fmt);

  uLen=(uchar)vsprintf(tmpBuf,fmt,arg_ptr);

  va_end(arg_ptr);

  while(i《uLen)

  {

  c1=tmpBuf[i];

  c2=tmpBuf[i+1];

  uRow=fnGetRow();

  uCol=fnGetCol();

  if(c1》=0)

  {//ASCII

  if(c1《0x20)

  {

  switch(c1)

  {

  caseCR:

  caseLF://回车或换行

  i++;

  if(uRow《112)

  fnSetPos(uRow+16,0);

  else

  fnSetPos(0,0);

  continue;

  caseBS://退格

  if(uCol》0)

  uCol--;

  fnSetPos(uRow,uCol);

  cData=0x00;

  break;

  default://其他

  c1=0x1f;

  }

  }

  for(j=0;j《16;j++)

  {

  fnPR12(LC_AUT_WR);//写数据

  if(c1》=0x1f)

  {

  if(j《(16-ASC_CHR_HEIGHT))

  fnPR13(0x00);

  else

  fnPR13(ASC_MSK[(c1-0x1f)*ASC_CHR_HEIGHT+j-(16-ASC_CHR_HEIGHT)]);

  }

  else

  fnPR13(cData);

  fnPR12(LC_AUT_OVR);

  fnSetPos(uRow+j+1,uCol);

  }

  if(c1!=BS)//非退格

  uCol++;

  }

  else

  {//中文

  for(j=0;j《sizeof(GB_16)/sizeof(GB_16[0]);j++)

  {

  if(c1==GB_16[j].Index[0]&&c2==GB_16[j].Index[1])

  break;

  }

  for(k=0;k《sizeof(GB_16[0].Msk)/2;k++)

  {

  fnSetPos(uRow+k,uCol);

  fnPR12(LC_AUT_WR);//写数据

  if(j《sizeof(GB_16)/sizeof(GB_16[0]))

  {

  fnPR13(GB_16[j].Msk[k*2]);

  fnPR13(GB_16[j].Msk[k*2+1]);

  }

  else//未找到该字

  {

  if(k《sizeof(GB_16[0].Msk)/4)

  {

  fnPR13(0x00);

  fnPR13(0x00);

  }

  else

  {

  fnPR13(0xff);

  fnPR13(0xff);

  }

  }

  fnPR12(LC_AUT_OVR);

  }

  uCol+=2;

  i++;

  }

  if(uCol》=30)//光标后移

  {

  uRow+=16;

  if(uRow《0x80)

  uCol-=30;

  else

  {

  uRow=0;

  uCol=0;

  }

  }

  fnSetPos(uRow,uCol);

  i++;

  }

  returnuLen;

  }

  voidmain(void)//测试用

  {

  fnLCMInit();

  cls();

  cursor(0,0);

  dprintf(”%s“,”Thisisatest:中文测试“);

  }


打开APP阅读更多精彩内容
声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉

全部0条评论

快来发表一下你的评论吧 !

×
20
完善资料,
赚取积分