350 likes | 512 Views
第 23 章点阵图形液晶模块及 C51 驱动. 23.1 、 128X64 图形液晶特性及引脚功 23.2 、 128X64 控制 器指令 23.3 、 128X64 点阵图形液晶的应用举例. 128X64 点阵图形液晶模块的特性. 128X64 点阵图形液晶模块的特性 ( 1 ) +5V 电压,明暗对比度可调整 ( 2 )背光分为两种:冷光背光和 LED 背光 ( 3 )行驱动: COM1~COM64 为行地址,由芯片 HD61203 做行驱动 ( 4 )列驱动: Y1~Y128 为为列地址,由 2 颗芯片 HD61202 做列驱动
E N D
第23章点阵图形液晶模块及C51驱动 23.1、128X64图形液晶特性及引脚功 23.2、128X64控制器指令 23.3、128X64点阵图形液晶的应用举例
128X64点阵图形液晶模块的特性 • 128X64点阵图形液晶模块的特性 • (1)+5V电压,明暗对比度可调整 • (2)背光分为两种:冷光背光和LED背光 • (3)行驱动:COM1~COM64为行地址,由芯片HD61203做行驱动 • (4)列驱动:Y1~Y128为为列地址,由2颗芯片HD61202做列驱动 • (5)左半屏/右半屏控制由CS1/CS2片选定。CS1=1,CS2=0时选择左半屏: CS1=0,CS2=1时选择右半屏
128X64点阵图形液晶模块的应用举例 • 例1;利用128X64点阵图形液晶显示汉字,第1行显示“朝辞白帝彩云间”,第2行显示“千里江陵一日还”,第3行显示“两岸猿声啼不住”,第4行显示“轻舟已过万重山”其中3、4行反白显示,源程序如下:#include <REG51.H> • #define uchar unsigned char • #define uint unsigned int • sbit CS1=P2^4; • sbit CS2=P2^3; • sbit RS=P2^7; • sbit RW=P2^6; • sbit EN=P2^5; • sbit RST=P2^2; • #define DataPort P0
128X64点阵图形液晶模块的应用举例 • void delay(unsigned long v); • void wcode(uchar c,uchar csl,uchar csr); • void wdata(uchar c,uchar csl,uchar csr); • void set_startline(uchar i); • void set_xy(uchar x,uchar y); • void dison_off(uchar o); • void reset(); • void lcd_init(void); • void lw(uchar x, uchar y, uchar dd); • void display_hz(uchar x, uchar y, uchar n, uchar fb); • uchar code hz[]; • /*******************************************************/ • void main(void) • { • uchar loop; • lcd_init(); • delay(1000); • while(1) • { • /************显示第一行(8个字)***********/ • for(loop=0;loop<8;loop++) • {display_hz(2*loop,0,loop,0); • display_hz(2*loop,0,loop,0); • display_hz(2*loop,0,loop,0); • display_hz(2*loop,0,loop,0); • display_hz(2*loop,0,loop,0); • display_hz(2*loop,0,loop,0); • display_hz(2*loop,0,loop,0); • display_hz(2*loop,0,loop,0);}
128X64点阵图形液晶模块的应用举例 • /*************显示第二行(8个字)**********/ • for(loop=0;loop<8;loop++) • {display_hz(2*loop,2,loop+8,0); • display_hz(2*loop,2,loop+8,0); • display_hz(2*loop,2,loop+8,0); • display_hz(2*loop,2,loop+8,0); • display_hz(2*loop,2,loop+8,0); • display_hz(2*loop,2,loop+8,0); • display_hz(2*loop,2,loop+8,0); • display_hz(2*loop,2,loop+8,0);} • /**************显示第三行(8个字)*************/ • for(loop=0;loop<8;loop++) • {display_hz(2*loop,4,loop+16,1); • display_hz(2*loop,4,loop+16,1); • display_hz(2*loop,4,loop+16,1); • display_hz(2*loop,4,loop+16,1); • display_hz(2*loop,4,loop+16,1); • display_hz(2*loop,4,loop+16,1); • display_hz(2*loop,4,loop+16,1); • display_hz(2*loop,4,loop+16,1);}
128X64点阵图形液晶模块的应用举例 • /*************显示第四行(8个字)*************/ • for(loop=0;loop<8;loop++) • {display_hz(2*loop,6,loop+24,1); • display_hz(2*loop,6,loop+24,1); • display_hz(2*loop,6,loop+24,1); • display_hz(2*loop,6,loop+24,1); • display_hz(2*loop,6,loop+24,1); • display_hz(2*loop,6,loop+24,1); • display_hz(2*loop,6,loop+24,1); • display_hz(2*loop,6,loop+24,1);} • /*************************/ • delay(10000); • } • } • /*---------------------------------------------------------*/ • void delay(unsigned long v) • { • while(v!=0)v--; • }
128X64点阵图形液晶模块的应用举例 • void lcd_busy(void) • { • RS=0;RW=1;DataPort=0xff; • while(1){ • EN=1; • if(DataPort<0x80) break; • EN=0; • } • EN=0; • } • /*-----------------------------------------------------------*/ • void wcode(uchar c,uchar csl,uchar csr) • { • CS1=csl; • CS2=csr; • lcd_busy(); • RS=0; • RW=0; • DataPort=c; • EN=1; • EN=0; • }
128X64点阵图形液晶模块的应用举例 • void wdata(uchar c,uchar csl,uchar csr) • { • CS1=csl; • CS2=csr; • lcd_busy(); • RS=1; • RW=0; • DataPort=c; • EN=1; • EN=0; • } • /*------------------------------------------------------*/ • void lw(uchar x, uchar y, uchar dd) • { • if(x>=64) • {set_xy(x-64,y); • wdata(dd,0,1);} • else • {set_xy(x,y); • wdata(dd,1,0);} • } • /*---------------------------------------------------*/ • void set_startline(uchar i) • { • i=0xc0+i; • wcode(i,1,1); • }
128X64点阵图形液晶模块的应用举例 • void set_xy(uchar x,uchar y) • { • x=x+0x40; • y=y+0xb8; • wcode(x,1,1); • wcode(y,1,1); • } • /*-------------------------------------------------------------*/ • void dison_off(uchar o) • { • o=o+0x3e; • wcode(o,1,1); • } • /*----------------------------------------------------------------------*/ • void reset() • { • RST=0; • delay(20); • RST=1; • delay(20); • }
128X64点阵图形液晶模块的应用举例 • void lcd_init(void) • {uchar x,y; • reset(); • set_startline(0); • dison_off(0); • for(y=0;y<8;y++) • { • for(x=0;x<128;x++)lw(x,y,0); • } • dison_off(1); • } • /*----------------------------------------------------------------------------*/ • void display_hz(uchar xx, uchar yy, uchar n, uchar fb) • { • uchar i,dx; • for(i=0;i<16;i++) • {dx=hz[2*i+n*32]; • if(fb)dx=255-dx; • lw(xx*8+i,yy,dx); • dx=hz[(2*i+1)+n*32]; • if(fb)dx=255-dx; • lw(xx*8+i,yy+1,dx); • } • }
128X64点阵图形液晶模块的应用举例 • uchar code hz[]= • {0x00,0x04,0x00,0x04,0x00,0x04,0xFE,0x04,0x92,0x04,0x92,0x04,0x92,0x04,0x92,0xFF, • 0x92,0x04,0x92,0x04,0x92,0x04,0x92,0x04,0xFE,0x04,0x00,0x04,0x00,0x04,0x00,0x00,/*"早",0*/ • 0x24,0x00,0x24,0x7E,0x24,0x22,0xFC,0x23,0x22,0x22,0x22,0x7E,0xA0,0x00,0x84,0x04, • 0x94,0x04,0xA5,0x04,0x86,0xFF,0x84,0x04,0xA4,0x04,0x94,0x04,0x84,0x04,0x00,0x00,/*"辞",1*/ • 0x00,0x00,0x00,0x00,0xF8,0x7F,0x08,0x21,0x08,0x21,0x0C,0x21,0x0B,0x21,0x08,0x21, • 0x08,0x21,0x08,0x21,0x08,0x21,0x08,0x21,0xF8,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,/*"白",2*/ • 0x80,0x00,0x64,0x00,0x24,0x00,0x24,0x3F,0x2C,0x01,0x34,0x01,0x25,0x01,0xE6,0xFF, • 0x24,0x01,0x24,0x11,0x34,0x21,0x2C,0x1F,0xA4,0x00,0x64,0x00,0x24,0x00,0x00,0x00,/*"帝",3*/ • 0x82,0x20,0x8A,0x10,0xB2,0x08,0x86,0x06,0xDB,0xFF,0xA1,0x02,0x91,0x04,0x8D,0x58, • 0x88,0x48,0x20,0x20,0x10,0x22,0x08,0x11,0x86,0x08,0x64,0x07,0x40,0x02,0x00,0x00,/*"彩",4*/ • 0x40,0x00,0x40,0x20,0x44,0x70,0x44,0x38,0x44,0x2C,0x44,0x27,0xC4,0x23,0xC4,0x31, • 0x44,0x10,0x44,0x12,0x46,0x14,0x46,0x18,0x64,0x70,0x60,0x20,0x40,0x00,0x00,0x00,/*"云",5*/ • 0x00,0x00,0xF8,0xFF,0x01,0x00,0x06,0x00,0x00,0x00,0xF0,0x07,0x92,0x04,0x92,0x04, • 0x92,0x04,0x92,0x04,0xF2,0x07,0x02,0x40,0x02,0x80,0xFE,0x7F,0x00,0x00,0x00,0x00,/*"间",6*/ • 0x00,0x00,0x00,0x00,0x00,0x58,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, • 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*",",7*/ • 0x40,0x00,0x40,0x00,0x44,0x00,0x44,0x00,0x44,0x00,0x44,0x00,0x44,0x00,0xFC,0x7F, • 0x42,0x00,0x42,0x00,0x42,0x00,0x43,0x00,0x42,0x00,0x60,0x00,0x40,0x00,0x00,0x00,/*"千",8*/
128X64点阵图形液晶模块的应用举例 • 0x00,0x40,0x00,0x40,0xFF,0x44,0x91,0x44,0x91,0x44,0x91,0x44,0x91,0x44,0xFF,0x7F, • 0x91,0x44,0x91,0x44,0x91,0x44,0x91,0x44,0xFF,0x44,0x00,0x40,0x00,0x40,0x00,0x00,/*"里",9*/ • 0x10,0x04,0x60,0x04,0x01,0x7E,0xC6,0x01,0x30,0x20,0x00,0x20,0x04,0x20,0x04,0x20, • 0x04,0x20,0xFC,0x3F,0x04,0x20,0x04,0x20,0x04,0x20,0x04,0x20,0x00,0x20,0x00,0x00,/*"江",10*/ • 0x00,0x00,0xFE,0xFF,0x22,0x02,0x5A,0x04,0x86,0x43,0x10,0x48,0x94,0x24,0x74,0x22, • 0x94,0x15,0x1F,0x09,0x34,0x15,0x54,0x23,0x94,0x60,0x94,0xC0,0x10,0x40,0x00,0x00,/*"陵",11*/ • 0x00,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00, • 0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0x80,0x00,0xC0,0x00,0x80,0x00,0x00,0x00,/*"一",12*/ • 0x00,0x00,0x00,0x00,0x00,0x00,0xFE,0x3F,0x42,0x10,0x42,0x10,0x42,0x10,0x42,0x10, • 0x42,0x10,0x42,0x10,0x42,0x10,0xFE,0x3F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*"日",13*/ • 0x40,0x40,0x41,0x20,0xCE,0x1F,0x04,0x20,0x00,0x42,0x02,0x41,0x82,0x40,0x42,0x40, • 0xF2,0x5F,0x0E,0x40,0x42,0x40,0x82,0x40,0x02,0x47,0x02,0x42,0x00,0x40,0x00,0x00,/*"还",14*/ • 0x00,0x00,0x00,0x00,0x00,0x58,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, • 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*",",15*/ • 0x02,0x00,0xF2,0x7F,0x12,0x08,0x12,0x04,0x12,0x03,0xFE,0x00,0x92,0x10,0x12,0x09, • 0x12,0x06,0xFE,0x01,0x12,0x01,0x12,0x26,0x12,0x40,0xFB,0x3F,0x12,0x00,0x00,0x00,/*"两",16*/
128X64点阵图形液晶模块的应用举例 • 0x00,0x40,0x00,0x20,0xE0,0x1F,0x2E,0x04,0xA8,0x04,0xA8,0x04,0xA8,0x04,0xA8,0x04, • 0xAF,0xFF,0xA8,0x04,0xA8,0x04,0xA8,0x04,0xA8,0x04,0xAE,0x04,0x20,0x04,0x00,0x00,/*"岸",17*/ • 0x20,0x04,0x12,0x42,0x0C,0x81,0x9C,0x40,0xE3,0x3F,0x10,0x10,0x14,0x08,0xD4,0xFD, • 0x54,0x43,0x5F,0x27,0x54,0x09,0x54,0x11,0xD4,0x69,0x14,0xC4,0x10,0x44,0x00,0x00,/*"猿",18*/ • 0x02,0x40,0x12,0x30,0xD2,0x0F,0x52,0x02,0x52,0x02,0x52,0x02,0x52,0x02,0xDF,0x03, • 0x52,0x02,0x52,0x02,0x52,0x02,0x52,0x02,0xD2,0x07,0x12,0x00,0x02,0x00,0x00,0x00,/*"声",19*/ • 0xFC,0x0F,0x04,0x02,0x04,0x02,0xFC,0x07,0x80,0x00,0x64,0x00,0x24,0x3F,0x2C,0x01, • 0x35,0x01,0xE6,0xFF,0x24,0x11,0x34,0x21,0xAC,0x1F,0x66,0x00,0x24,0x00,0x00,0x00,/*"啼",20*/ • 0x00,0x00,0x02,0x08,0x02,0x04,0x02,0x02,0x02,0x01,0x82,0x00,0x42,0x00,0xFE,0x7F, • 0x06,0x00,0x42,0x00,0xC2,0x00,0x82,0x01,0x02,0x07,0x03,0x02,0x02,0x00,0x00,0x00,/*"不",21*/ • 0x40,0x00,0x20,0x00,0xF0,0x7F,0x0C,0x00,0x03,0x20,0x08,0x21,0x08,0x21,0x09,0x21, • 0x0A,0x21,0xFC,0x3F,0x08,0x21,0x08,0x21,0x8C,0x21,0x08,0x31,0x00,0x20,0x00,0x00,/*"住",22*/ • 0x00,0x00,0x00,0x00,0x00,0x58,0x00,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, • 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*",",23*/ • 0xC4,0x08,0xB4,0x08,0x8F,0x08,0xF4,0xFF,0x84,0x04,0x84,0x44,0x04,0x41,0x82,0x41, • 0x42,0x41,0x22,0x41,0x12,0x7F,0x2A,0x41,0x46,0x41,0xC2,0x41,0x00,0x41,0x00,0x00,/*"轻",24*/ • 0x80,0x00,0x80,0x80,0x80,0x40,0x80,0x30,0xFC,0x0F,0x84,0x00,0x86,0x02,0x95,0x04, • 0xA4,0x0C,0x84,0x40,0x84,0x80,0xFC,0x7F,0x80,0x00,0x80,0x00,0x80,0x00,0x00,0x00,/*"舟",25*/ • 0x00,0x00,0x00,0x00,0xE2,0x3F,0x42,0x20,0x42,0x20,0x42,0x20,0x42,0x20,0x42,0x20, • 0x42,0x20,0x42,0x20,0x42,0x20,0x7E,0x20,0x00,0x20,0x00,0x3C,0x00,0x10,0x00,0x00,/*"已",26*/
128X64点阵图形液晶模块的应用举例 • 0x80,0x40,0x81,0x20,0x8E,0x1F,0x04,0x20,0x00,0x20,0x10,0x40,0x50,0x40,0x90,0x43, • 0x10,0x41,0x10,0x48,0x10,0x50,0xFF,0x4F,0x10,0x40,0x10,0x40,0x10,0x40,0x00,0x00,/*"过",27*/ • 0x00,0x00,0x02,0x40,0x02,0x20,0x02,0x10,0x02,0x0C,0x82,0x03,0x7E,0x00,0x22,0x00, • 0x22,0x20,0x22,0x60,0x22,0x20,0xF2,0x1F,0x22,0x00,0x02,0x00,0x02,0x00,0x00,0x00,/*"万",28*/ • 0x08,0x40,0x08,0x40,0x0A,0x48,0xEA,0x4B,0xAA,0x4A,0xAA,0x4A,0xAA,0x4A,0xFF,0x7F, • 0xA9,0x4A,0xA9,0x4A,0xA9,0x4A,0xE9,0x4B,0x08,0x48,0x08,0x40,0x08,0x40,0x00,0x00,/*"重",29*/ • 0x00,0x00,0x00,0x20,0xE0,0x7F,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0xFF,0x3F, • 0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0x00,0x20,0xE0,0x7F,0x00,0x00,0x00,0x00,/*"山",30*/ • 0x00,0x00,0x00,0x18,0x00,0x24,0x00,0x24,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x00, • 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/*"。",31*/
128X64点阵图形液晶模块的应用举例 • 例2:在128X64点阵图形上显示图像,这幅图像为小舢舨,源程序如下: • #include <REG51.H> • #include<math.h> • #define uchar unsigned char • #define uint unsigned int • sbit CS1=P2^4; • sbit CS2=P2^3; • sbit RS=P2^7; • sbit RW=P2^6; • sbit EN=P2^5; • sbit RST=P2^2; • #define DataPort P0 • /**********常用操作命令和参数定义***********/ • #define DISPON 0x3f //显示屏开 • #define DISPOFF 0x3e //显示屏关 • #define DISPFIRST 0xc0 //起始行显示定义
128X64点阵图形液晶模块的应用举例 • #define SETX 0x40 //X定位(页) • #define SETY 0xb8 //Y定位(列) • #define Lcdbusy 0x80 //LCM忙判断定义 • /***********************************************/ • #define MODL 0x00 //左区 • #define MODM 0x40 //左区与中区分界 • //#define MODR 0x80 //中区与右区分界 • #define LCMLIMIT 0x80 //中区的边界 • //#define LCMLIMIT 0xc0 //右区的边界(这里不用) • /*************************************************/ • uchar col,row,cbyte; //列、行、数据的变量定义 • bit xy; //画线标志,"1"水平线,"0"垂直线。 • /**************************************************/ • void Lcminit(void); //液晶模块初始化子函数 • void Delay(unsigned long MS); //延时子函数 • void lcdbusyL(void); //左区判忙子函数 • void lcdbusyM(void); //中区判忙子函数 • //void lcdbusyR(void); //右区判忙子函数(这里不用) • void Wrdata(uchar X); //写数据至LCM • void Lcmcls(void); //LCM清屏 • void Lcmclsxx(void); //LCM全屏置黑 • void wtcom(void); //公用判忙等待子函数
128X64点阵图形液晶模块的应用举例 • void Locatexy(void); //光标定义 • void WrcmdL(uchar X); //写命令至左区 • void WrcmdM(uchar X); //写命令至中区 • //void WrcmdR(uchar X); //写命令至右区(这里不用) • void Rddata(void); //读LCM状态子函数 • void Linehv(uchar length); //水平、垂直画线子函数 • void point(void); //画点子函数 • void Linexy(uchar endx, uchar endy); //画斜线子函数 • /************************复位子函数*************************/ • void reset() //复位子函数 • { //复位子函数开始 • RST=0; //复位端置0 • Delay(20); //延时20ms • RST=1; //复位端置1 • Delay(20); //延时20ms • } //复位子函数结束 • /*********************主函数**********************/
128X64点阵图形液晶模块的应用举例 • void main(void) • { //主函数开始 • col=0; //定位0列、0页 • row=0; • Delay(10); //延时一会 • Lcminit(); //液晶模块初始化 • Delay(1000); //延时一会 • /***********以下使用画直线与斜线的方法,画出一条小舢舨*********/ • /****************先画出船上建筑**************/ • col=0; //定位x方位0、y方位32 • row=32; • xy=1; //水平线 • Linehv(127); //画线,长度127 • /*----------------------------------------------*/ • col=33; //定位x方位33、y方位48 • row=48; • xy=1; //水平线 • Linehv(30); //画线,长度30 • col=36; //定位x方位36、y方位32 • row=32; • xy=0; //垂直线 • Linehv(16); //画线,长度16
128X64点阵图形液晶模块的应用举例 • col=10; //定位x方位10、y方位32 • row=32; • xy=0; //垂直线 • Linehv(27); //画线,长度27 • /************以下画出船底的弧形***********/ • col=0; //定位x方位0、y方位32 • row=32; • Linexy(10,16); //画斜线,终点为x方位10、y方位16 • col=10; //定位x方位10、y方位16 • row=16; • Linexy(30,8); //画斜线,终点为x方位30、y方位8 • col=30; //定位x方位30、y方位8 • row=8; • Linexy(64,5); //画斜线,终点为x方位64、y方位5 • /*-----------------------------------------------------------------*/ • col=65; //定位x方位65、y方位5 • row=5; • Linexy(97,8); //画斜线,终点为x方位97、y方位8 • col=97; //定位x方位97、y方位8 • row=8; • Linexy(117,16); //画斜线,终点为x方位117、y方位16 • col=117; //定位x方位117、y方位16 • row=16; • Linexy(127,32); //画斜线,终点为x方位127、y方位32 • /*----------------------------------画舢舨结束------------------------------------*/
128X64点阵图形液晶模块的应用举例 • while(1); //死循环 • } //主函数结束 • /*************************画斜线子函数************************/ • void Linexy(uchar endx, uchar endy) • { • register uchar t; • char xerr=0,yerr=0,delta_x,delta_y,distance; • uchar incx,incy; • delta_x=endx-col; • delta_y=endy-row; • if(delta_x>0)incx=1; • else if(delta_x==0)incx=0; • else incx=-1; • if(delta_y>0)incy=1; • else if(delta_y==0)incy=0; • else incy=-1; • delta_x=cabs(delta_x); • delta_y=cabs(delta_y); • if(delta_x>delta_y) distance=delta_x; • else distance=delta_y;
128X64点阵图形液晶模块的应用举例 • /*-----------开始画线-------------*/ • for(t=0;t<=distance+1;t++){ • point(); • xerr+=delta_x; • yerr+=delta_y; • if(xerr>distance){ • xerr-=distance; • col+=incx; • } • if(yerr>distance){ • yerr-=distance; • row+=incy; • } • } • } • /*********************画水平、垂直线子函数***********************/ • void Linehv(uchar length) /*函数名为Linehv的画水平、垂直线子函数,定义 • length 为线段长度的无符号字符型变量。*/ • { //画水平、垂直线子函数开始 • uchar xs,ys; //定义xs、ys 为无符号字符型变量。 • if(xy){ys=col;
128X64点阵图形液晶模块的应用举例 • //若xy为1,则为水平划线 • for(xs=0;xs<length;xs++){ • col=ys+xs; • point();} • } • else {xs=row; //否则为垂直划线 • for(ys=0;ys<length;ys++) • { • row=xs+ys; • point();} • } • } //画水平、垂直线子函数结束 • /**********************画点子函数***************************/ • void point(void) //画点子函数 • { //画点子函数开始 • uchar x1,y1,x,y; //定义x1、y1、x、y 为无符号字符型变量 • x1=col; //x方向座标col赋予x1(暂存) • y1=row; //y方向座标row赋予y1(暂存) • row=y1>>3; //y1右移3位后赋予row,获得y方向的页地址 • Rddata(); //读取列(x)地址、页(y)地址处的数据 • y=y1&0x07; //计算出该页(1字节)内的y轴点位置地址 • x=0x01; • x=x<<y; //移入所画点 • Wrdata(cbyte|x);
128X64点阵图形液晶模块的应用举例 • //画上屏幕 • col=x1; //恢复x、y座标 • row=y1; • } //画点子函数结束 • /***************全屏幕清屏子函数**********************/ • void Lcmcls(void) //函数名为Lcmcls的全屏幕清屏子函数 • { //函数开始 • for(row=0;row<8;row++) • {for(col=0;col<LCMLIMIT;col++) • Wrdata(0);} //将数据0写到屏幕 • } //函数结束 • /**********************全屏幕置黑子函数**********************/ • void Lcmclsxx(void) //函数名为Lcmclsxx的全屏幕置黑子函数 • { //函数开始 • for(row=0;row<8;row++) • for(col=0;col<LCMLIMIT;col++) • Wrdata(255); //将8位数据全1(255)写到屏幕 • } //函数结束 • /*************读取液晶x列、y页座标处的数据至全局变量cbyte中************/ • void Rddata(void) //函数名为Rddata的子函数 • { //函数开始 • Locatexy(); //座标定位 • DataPort=0xff; //LCM口置全1 • RS=1; //选择数据寄存器 • RW=1;
128X64点阵图形液晶模块的应用举例 • EN=1; //使能 • cbyte=DataPort; //虚读一次 • EN=0; //禁能 • Locatexy(); //座标定位 • DataPort=0xff; //LCM口置全1 • RS=1; //选择数据寄存器 • RW=1; //选择读 • EN=1; //使能 • cbyte=DataPort; //读取数据(真读) • EN=0; //禁能 • } • //函数结束 • /**************将数据X写入液晶x列、y页座标处***********/ • void Wrdata(uchar X) //函数名为Wrdata 的子函数,定义X为无符号字符型变量 • { //函数开始 • Locatexy(); //座标定位 • RS=1; //选择数据寄存器 • RW=0; //选择写 • DataPort=X; //将数据X写入LCM口 • EN=1; //使能 • EN=0; //禁能 • } //函数结束
128X64点阵图形液晶模块的应用举例 • /******************写命令至左区********************/ • void WrcmdL(uchar X) //函数名为WrcmdL 的子函数,定义X为无符号字符型变量 • { //函数开始 • lcdbusyL(); //调用左区判忙子函数 • RS=0; //选择指令寄存器 • RW=0; //选择写 • DataPort=X; //数据输出至数据口 • EN=1;EN=0; //使能,禁能 • } //函数结束 • /********************写命令至中区************************/ • void WrcmdM(uchar X) //函数名为WrcmdM的子函数,定义X为无符号字符型变量 • { //函数开始 • lcdbusyM(); //调用中区判忙子函数 • RS=0; //选择指令寄存器 • RW=0; //选择写 • DataPort=X; //数据输出至数据口 • EN=1;EN=0; //使能,禁能 • } //函数结束 • /**************写命令至右区**************** • void WrcmdR(uchar X) //函数名为WrcmdR的子函数,定义X为无符号字符型变量 • { //函数开始 • lcdbusyR(); //调用右区判忙子函数 • RS=0; //选择指令寄存器 • RW=0; //选择写 • DataPort=X;
128X64点阵图形液晶模块的应用举例 • //数据输出至数据口 • EN=1;EN=0; //使能,禁能 • } //函数结束 • ***********************左区判忙子函数***********************/ • void lcdbusyL(void) //函数名为lcdbusyL 的左区判忙子函数 • { //函数开始 • CS1=1;CS2=0; //选中左区 • wtcom(); //调用判忙等待子函数 • } //函数结束 • void lcdbusyM(void) //函数名为lcdbusyM的中区判忙子函数 • { //函数开始 • CS1=0;CS2=1; //选中中区 • wtcom(); //调用判忙等待子函数 • } //函数结束 • /*void lcdbusyR(void) //函数名为lcdbusyR的右区判忙子函数(这里不用) • { //函数开始 • CS1=?;CS2=?; //根据所用LCM器件决定取值 • wtcom(); //调用判忙等待子函数 • }*/
128X64点阵图形液晶模块的应用举例 • void wtcom(void) //函数名为wtcom 的公用判忙等待子函数 • { //函数开始 • RS=0; //选择指令寄存器 • RW=1; //选择读 • DataPort=0xff; //数据0xff输出至数据口 • EN=1; //使能 • while(DataPort&Lcdbusy);// 若LCM忙则等待 • EN=0; //禁能 • } //函数结束 • /************根据设定的col、row座标数据,定位LCM下一个操作单元************/ • void Locatexy(void) //函数名为Locatexy 的子函数 • { //函数开始 • uchar x,y; //定义x,y为无符号字符型变量
128X64点阵图形液晶模块的应用举例 • switch(col&0xc0) //限定x列最大值为192 • { • case 0:{lcdbusyL();break;} //判左区忙 • case 0x40:{lcdbusyM();break;} //判中区忙 • //case 0x80:{lcdbusyR();break;} //判右区忙(这里不用) • } • x=col&0x3f|SETX; //获得x列(0~63)地址 • y=row&0x07|SETY; //获得y页(0~7)地址 • wtcom(); //调用判忙等待子函数 • RS=0; //选择指令寄存器 • RW=0; //选择写 • DataPort=y; //y页地址传送至LCM口 • EN=1;EN=0; //使能,禁能 • wtcom(); //调用判忙等待子函数 • RS=0; //选择指令寄存器 • RW=0; //选择写 • DataPort=x; //x列地址传送至LCM口 • EN=1;EN=0; //使能,禁能 • } //函数结束
128X64点阵图形液晶模块的应用举例 • void Lcminit(void) //函数名为Lcminit的液晶屏初始化子函数 • { //函数开始 • reset(); //调用复位子函数 • cbyte=DISPFIRST; //定义起始行为0行 • WrcmdL(cbyte); //写命令至左区 • WrcmdM(cbyte); //写命令至中区 • //WrcmdR(cbyte); //写命令至右区(这里不用) • cbyte=DISPOFF; //关闭显示屏 • WrcmdL(cbyte); //写命令至左区 • WrcmdM(cbyte); //写命令至中区 • //WrcmdR(cbyte); //写命令至右区(这里不用) • cbyte=DISPON; //打开显示屏 • WrcmdL(cbyte); //写命令至左区 • WrcmdM(cbyte); //写命令至中区 • //WrcmdR(cbyte); //写命令至右区(这里不用) • Lcmcls(); //清屏 • Delay(10000); //延时一会 • Lcmclsxx(); //全屏置黑 • Delay(10000); //延时一会 • Lcmcls(); //清屏 • Delay(30000); //延时一会 • col=0; //定位x方向为0列 • row=0; //定位y方向为0页 • Locatexy(); //定位0列、0页为LCM下一个操作单元 • }
128X64点阵图形液晶模块的应用举例 • void Delay(unsigned long MS) • { • while(MS!=0)MS--; • }