#define width 30 //显示区宽度 #define addr_w 0x0000 //文本显示区首地址 #define addr_t 0x01e0 //图形显示区首地址 #define uchar unsigned char #define uint unsigned int #define data_ora P1 //MCU P1<------> LCM sbit wr = P2 ^ 0; //Data Write into T6963C,L有效 sbit rd = P2 ^ 1; //Data Read from T6963C,L有效 sbit ce = P2 ^ 2; //使能信号,L有效 sbit cd = P2 ^ 3; //当wr=L,cd=H:写命令,cd=L:写数据;当rd=L,cd=H:读状态,cd=L:读数据 sbit rst = P2 ^ 4; //Lcm reset,低有效 sbit fs = P2 ^ 5; //字体选择,H:6*8点阵;L:8*8点阵 sbit bf0 = P1 ^ 0; sbit bf1 = P1 ^ 1; sbit bf3 = P1 ^ 3; uchar t[128] = { 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, 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, 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, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; uchar code num[] = { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19 }; void wr_comm(uchar comm); void wr_data(uchar dat); void chk_busy(uchar autowr); /*---------------延时子程序----------------*/ void delay1(uint ms) { uint i, j; for (i = 0; i < ms; i++) for (j = 0; j < 1000; j++) ; } /*------------写命令或数据到LCD--------------*/ //写一个数据和一个命令 void wr_od(uchar dat, uchar comm) { wr_data(dat); wr_comm(comm); } //写两个数据和一个命令 void wr_td(uchar datl, uchar dath, uchar comm) { wr_data(datl); wr_data(dath); wr_comm(comm); } //写一个16进制数据和一个命令 void wr_xd(uint dat, uchar comm) { uchar datl, dath; datl = dat; dath = dat >> 8; wr_data(datl); wr_data(dath); wr_comm(comm); } //自动写数据 void wr_auto(uchar dat) { chk_busy(1); cd = 0; rd = 1; data_ora = dat; wr = 0; wr = 1; } //写命令 void wr_comm(uchar comm) { chk_busy(0); cd = 1; rd = 1; data_ora = comm; wr = 0; wr = 1; } //写数据 void wr_data(uchar dat) { chk_busy(0); cd = 0; rd = 1; data_ora = dat; wr = 0; wr = 1; } //测状态 void chk_busy(uchar autowr) { data_ora = 0xff; cd = 1; wr = 1; rd = 0; if (autowr) { while (bf3 == 0) ; } else { while ((bf0 == 0) || (bf1 == 0)) ; } rd = 1; } /*------------------初始化-----------------*/ void init_lcd(void) { rst = 0; ; rst = 1; fs = 0; ce = 0; wr = 1; rd = 1; wr_xd(addr_w, 0x40); //文本显示区首地址 wr_xd(addr_t, 0x42); //图形显示区首地址 wr_td(width, 0x00, 0x41); //文本显示区宽度 wr_td(width, 0x00, 0x43); //图形显示区宽度 wr_comm(0x81); //逻辑"异或" wr_td(0x02, 0x00, 0x22); //CGRAM偏置地址设置 wr_comm(0x9c); //启用文本显示,启用图形显示 } /*--------------清RAM------------------*/ void clrram(void) { uchar i, j; wr_xd(addr_w, 0x24); wr_comm(0xb0); for (j = 0; j < 144; j++) { for (i = 0; i < width; i++) wr_auto(0x00); } wr_comm(0xb2); } /*--------------在addr处显示8xl*yl的图形-------------- void disp_img(uint addr,uchar xl,uchar yl,uchar code*img) { uchar i,j ; for(j=0;j