《LCD字符中文显示程序》由会员分享,可在线阅读,更多相关《LCD字符中文显示程序(11页珍藏版)》请在金锄头文库上搜索。
1、#define PD1 61 / 122/2 分成左右两半屏(122x32)unsigned char Column;unsigned char Page_ ; / 页地址寄存器 D1,DO:页地址unsigned char Code_ ; / 字符代码寄存器unsigned char Command; / 指令寄存器unsigned char LCDData; / 数据寄存器unsigned char tmp;sbit e1 = P33;sbit e2 = P34;sbit rw = P31;sbit a0 = P30;sfr conr=0xB0;/*即p3口*/sfr din=0x90;
2、/*即p1口*/unsigned char CWADD1 ; / 写指令代码地址(E1)xdata unsigned char DWADD1 _at_ 0x8001; / 写显示数据地址(E1)xdata unsigned char CRADD1 _at_ 0x8002; / 读状态字地址(E1)xdata unsigned char DRADD1 _at_ 0x8003; / 读显示数据地址(E1)xdata unsigned char CWADD2 _at_ 0x8004; / 写指令代码地址(E2)xdata unsigned char DWADD2 _at_ 0x8005; / 写显示
3、数进地址(E2)xdata unsigned char CRADD2 _at_ 0x8006; / 读状态字地址(E2)xdata unsigned char DRADD2 _at_ 0x8007; / 读显示数据地址(E2)/英文字模库 宽*高 8x16 点阵code unsigned char EETAB8=0x00,0x07,0x08,0x10,0x10,0x08,0x07,0x00,0x00,0xF0,0x08,0x04,0x04,0x08,0xF0,0x00, / 00x00,0x08,0x08,0x1F,0x00,0x00,0x00,0x00,0x00,0x04,0x04,0xFC
4、,0x04,0x04,0x00,0x00, / 10x00,0x0E,0x10,0x10,0x10,0x11,0x0E,0x00,0x00,0x0C,0x14,0x24,0x44,0x84,0x0C,0x00, / 20x00,0x0C,0x10,0x11,0x11,0x12,0x0C,0x00,0x00,0x18,0x04,0x04,0x04,0x88,0x70,0x00; / 30x00,0x00,0x03,0x04,0x08,0x1F,0x00,0x00,0x00,0xE0,0x20,0x24,0x24,0xFC,0x24,0x00;/40x00,0x1F,0x10,0x11,0x11,
5、0x10,0x10,0x00,0x00,0x98,0x84,0x04,0x04,0x88,0x70,0x00; /50x00,0x07,0x08,0x11,0x11,0x18,0x00,0x00,0x00,0xF0,0x88,0x04,0x04,0x88,0x70,0x00; /60x00,0x1C,0x10,0x10,0x13,0x1C,0x10,0x00,0x00,0x00,0x00,0xFC,0x00,0x00,0x00,0x00; /7;/ 中文字模库 16x16点阵code unsigned char CCTAB32 =0x00,0x04,0xe4,0x24,0x24,0x64,0x
6、b4,0x2f, / 南0x24,0xa4,0x64,0x24,0x24,0xe6,0x04,0x00,0x00,0x00,0x7f,0x04,0x05,0x05,0x05,0x7f,0x05,0x05,0x05,0x25,0x44,0x3f,0x00,0x00, 0x00,0x04,0x04,0xe4,0x24,0x24,0x25,0x26, / 京0x24,0x24,0x24,0xe4,0x06,0x04,0x00,0x00,0x00,0x20,0x10,0x19,0x0D,0x41,0x81,0x7f,0x01,0x01,0x05,0x0d,0x38,0x10,0x00,0x00,0x0
7、0,0x80,0x60,0xf8,0x07,0x0a,0x28,0x28, / 伟0x28,0xff,0x28,0x28,0x28,0x28,0x00,0x00,0x01,0x00,0x00,0xfF,0x00,0x01,0x01,0x01,0x01,0xff,0x01,0x21,0x41,0x3f,0x00,0x00,0x08,0x08,0x89,0xce,0x28,0x18,0x02,0x7a, / 福0x4a,0x4a,0x4a,0x4a,0x4a,0x7a,0x02,0x00,0x02,0x01,0x00,0xff,0x01,0x02,0xff,0x49,0x49,0x49,0x7f,
8、0x49,0x49,0x49,0xff,0x00;/ 1.写指令代码子程序(E1)void WriteCommandE1()Contr = 0x02;do Din = 0xff;e1 = 1;tmp = Din;e1 = 0;while(tmp & 0x80);Contr = 0x00;Din = Command;e1 = 1;e1 = 0;/ 2.写显示数据子程序(E1)void WriteDataE1()Contr = 0x02;do Din = 0xff;e1 = 1;tmp = Din;e1 = 0;while(tmp & 0x80);Contr = 0x01;Din = LCDDat
9、a;e1 = 1;e1 = 0;/ 3.读显示数据子程序(E1)void ReadDataE1()Contr = 0x02;do Din = 0xff;e1 = 1;tmp = Din;e1 = 0;while(tmp & 0x80);a0 = 1; Din = 0xff;e1 = 1;LCDData = Din;e1 = 0;e1 = 0;/ 4.写指令代码子程序(E2)void WriteCommandE2()Contr = 0x02;do Din = 0xff;e2 = 1;tmp = Din;e2 = 0;while(tmp & 0x80);Contr = 0x00;Din = Com
10、mand;e2 = 1;e2 = 0;/ 5.写显示数据子程序(E2)void WriteDataE2()Contr = 0x02;do Din = 0xff;e2 = 1;tmp = Din;e2 = 0;while(tmp & 0x80);Contr = 0x01;Din = LCDData;e2 = 1;e2 = 0;/ 6.读显示数据子程序(E2)void ReadDataE2()Contr = 0x02;do Din = 0xff;e2 = 1;tmp = Din;e2 = 0;while(tmp & 0x80);a0 = 1;Din = 0xff;e2 = 1;LCDData =
11、Din;e2 = 0;e2 = 0;/ 初始化程序void Init()Command = 0xe2;WriteCommandE1();WriteCommandE2();Command = 0xa4;WriteCommandE1();WriteCommandE2();Command = 0xa9;WriteCommandE1();WriteCommandE2();Command = 0xa0;WriteCommandE1();WriteCommandE2();Command = 0xc0;WriteCommandE1();WriteCommandE2();Command = 0xaf;Writ
12、eCommandE1();WriteCommandE2();/ 清屏void Clear()unsigned char i,j;i = 0;do Command = (i + 0xb8); / 页地址设置WriteCommandE1();WriteCommandE2();Command = 0x00; / 列地址设置为0WriteCommandE1();WriteCommandE2();j = 0x50; / 一页清 80个字节do LCDData = 0x00; / 显示数据为0WriteDataE1();WriteDataE2();while(-j !=0); / 页内字节清零循环whil
13、e(+i !=4); / 页地址暂存器加一/ 显示区清零循环/ 延时程序void Delay(unsigned char i)unsigned char j;while(i-) j = 383;while(-j); / 中文显示子程序void WriteCHN16x16()unsigned char i,j,k;i = 0;j = 0;while(j= PD1 * 2) break; / 列地址是否超出显示范围 ;j+;/ 中文显示程序void main()Init();Clear();Page_ = 0x02;Column = 0x00;Code_ = 0x00;WriteCHN16x16(
14、);Page_ = 0x02;Column = 0x10;Code_ = 0x01;WriteCHN16x16();h24aa#include #define PD1 61 / 122/2 分成左右两半屏(122x32)unsigned char Column;unsigned char Page_ ; / 页地址寄存器 D1,DO:页地址unsigned char Code_ ; / 字符代码寄存器unsigned char Command; / 指令寄存器unsigned char LCDData; / 数据寄存器xdata unsigned char CWADD1 _at_ 0x8000
15、; / 写指令代码地址(E1)xdata unsigned char DWADD1 _at_ 0x8001; / 写显示数据地址(E1)xdata unsigned char CRADD1 _at_ 0x8002; / 读状态字地址(E1)xdata unsigned char DRADD1 _at_ 0x8003; / 读显示数据地址(E1)xdata unsigned char CWADD2 _at_ 0x8004; / 写指令代码地址(E2)xdata unsigned char DWADD2 _at_ 0x8005; / 写显示数进地址(E2)xdata unsigned char CRADD2 _at_ 0x8006; / 读状态字地址(E2)xdata unsigned char DRADD2 _at_ 0x8007; / 读显示数据地址(E2)/英文字模库 8x8 点阵code unsigned char EETAB8=0x00,0xFF,0x81,0x81,0x81,0x81,0xFF,0x00, / 00x00,0xF8,0x08,0x08,0xFE,0x08,0x08,0x00,