1、89C52单片机液晶汉字显示c语言程序*液晶屏分为4行*12列汉字,全部使用模拟接口方式。 /* TGLCMLIMIT64A接口程序(模拟方式) ;*单片机液晶汉字显示c语言程序* ;连线图: ;*LCM-89C52* *LCM-89C52* *LCM-89C52* *LCM-89C52* * ;*DB0-P0.0* *DB4-P0.4* *D/I-P2.6* *CS1-P2.4* * ;*DB1-P0.1* *DB5-P0.5* *R/W-P2.7* *CS2-P2.5* * ;*DB2-P0.2* *DB6-P0.6* *RST-VCC* *CS3-P3.2* * ;*DB3-P0.3*
2、*DB7-P0.7* *E-P2.3* * ;注:89C52的晶振频率为12MHz * ;*单片机液晶汉字显示c语言程序*/ /画线部分请参照avr的c程序。 /*#pragma src /*生成ASM文件开关,必要时打开 */ #include #include #include #define Uchar unsigned char /*液晶显示器接口引脚定义*/ sbit Elcm= P23; / sbit CS1LCM= P24; / sbit CS2LCM= P25; / sbit CS3LCM= P32; /*这个连接只是做实验的临时接法。*/ sbit Dilcm= P26; /
3、 sbit Rwlcm= P27; / sfr Datalcm= 0x80; /数据口 unsigned char testi=“浸渠叁绳漱塔烃威牺晓玄瑶“; /*常用操作命令和参数定义*/ #define DISPON 0x3f /*显示on */ #define DISPOFF 0x3e /*显示off */ #define DISPFIRST 0xc0 /*显示起始行定义 */ #define SETX 0x40 /*X定位设定指令(页) */ #define SETY 0xb8 /*Y定位设定指令(列) */ #define Lcdbusy 0x80 /*LCM忙判断位 */ /*显示
4、分区边界位置*/ #define MODL 0x00 /*左区 */ #define MODM 0x40 /*左区和中区分界 */ #define MODR 0x80 /*中区和右区分界 */ #define LCMLIMIT 0xC0 /*显示区的右边界 */ /*全局变量定义*/ Uchar col,row,cbyte; /*列x,行(页)y,输出数据 */ bit xy; /*画线方向标志:1水平 */ /*函数列表*/ void Lcminit(void); /*液晶模块初始化 */ void Delay(Uchar); /*延时,入口数为Ms */ void lcdbusyL(voi
5、d); /*busy判断、等待(左区) */ void lcdbusyM(void); /*busy判断、等待(中区) */ void lcdbusyR(void); /*busy判断、等待(右区) */ void Putedot(Uchar); /*半 字 输出 */ void Putcdot(Uchar); /*全 (汉字)输出 */ void Wrdata(Uchar); /*数据输出 LCM */ void Lcmcls( void ); /*LCM全屏 ( 0) */ void wtcom(void); /* 用busy等待 */ void Locatexy(void); /* 标定
6、位 */ void WrcmdL(Uchar); /*左区命令输出 */ void WrcmdM(Uchar); /*中区命令输出 */ void WrcmdR(Uchar); /*右区命令输出 */ void Putstr(Uchar *puts,Uchar i); /*中 文字 输出 */ void Rollscreen(Uchar x); /*屏 向 示 */ void Rddata(void); /* 液晶片 数据 */ void Linehv(Uchar length); /* ( )方向画线 */ void point(void); /*打 */ void Linexy(Uchar
7、 endx,Uchar endy); /*数 列表*/ Uchar code Ezk; /*ASCII常 字 表 */ Uchar code Hzk; /* 用汉字 表 */ Uchar code STR1; /* 定义字 */ Uchar code STR2; / Uchar code STR3; / Uchar code STR4; / /*/ /* 单片机液晶汉字显示c语言程序 */ /*/ void main(void) Uchar x,y; col=0; row=0; Delay(40); /*延时 40Ms,等待 设 */ Lcminit(); /*液晶模块初始化, 全屏 屏*/
8、Putstr(STR2,24); /*行字 输出,24字 */ col=0; row=2; Putstr(STR1,12); /*行字 输出,12字 */ col=0; row=4; Putstr(STR3,24); /*行字 输出,24字 */ col=0; row=6; Putstr(STR4,24); /*行字 输出,12字 */ x=0; col=0; row=0; xy = 1; /*方向标志。定为水平方向 */ Linehv(192); /*画currency1 线(0,0)-(191,0) */ col=0; row=15; xy = 1; Linehv(192); /*画cur
9、rency1 线(0,15)-(191,15) */ col=0; row=32; xy = 1; Linehv(192); /*画currency1 线(0,32)-(191,32) */ col=0; row=1; xy = 0; /*方向标志。定为“方向 */ Linehv(31); /*画currency1 线(0,1)-(0,31) */ col=191; row=1; xy = 0; Linehv(31); /*画currency1 线(191,1)-(191,31) */ col=0; /*设定线的起 标 */ row=63; Linexy(44,31); /*画线(0,63)-
10、(44,31) */ col=44; row=31; Linexy(190,62); /*fifl画线(44,31)-(191,63) */ while(1) Rollscreen(y); /*定位 的显示起*/ y+; y %=8; x=testiy; Delay(100); /*延时, */ ; /*/ /*画线。 方向的线,“的”水平线 */ /*/ void Linexy(Uchar endx,Uchar endy) register Uchar t; int xerr=0,yerr=0,delta_x,delta_y,distance; Uchar incx,incy; /* com
11、pute the distance in both directions */ delta_x=endx-col; delta_y=endy-row; /* compute the direction of the increment , an increment of “0“ means either a vertical or horizontal lines */ if(delta_x0) incx=1; else if( delta_x=0 ) incx=0; else incx=-1; if(delta_y0) incy=1; else if( delta_y=0 ) incy=0;
12、 else incy=-1; /* determine which distance is greater */ delta_x = cabs( delta_x ); delta_y = cabs( delta_y ); if( delta_x delta_y ) distance=delta_x; else distance=delta_y; /* draw the line */ for( t=0;t distance ) xerr-=distance; col+=incx; if( yerr distance ) yerr-=distance; row+=incy; /*/ /*画线。只
13、X”Y方向的,线 */ /*/ void Linehv(Uchar length) Uchar xs,ys; if (xy)ys = col; for (xs=0;xs3; /*Y方向分页 */ Rddata(); y=y1 /*字 位置 */ x=0x01; x=x7) row=0; /* 行 界, 行 */ /* 半个字 输出 */ col = bakerx; /*列 */ row = bakery+1; /*指向 半个字 行 */ /* 半个字 输出,8列 */ for(i=0;i7) row=1; /* 行 界, 行 */ /* 半个字 输出 */ row=bakery; /* 个字
14、输出 */ /*/ /* 全 字 数据输出 */ /*/ void Putcdot(Uchar Order) Uchar i,bakerx,bakery; /*定义3个局部变量 */ int x; /*量,字 量 的定义为UCHAR */ bakerx = col; /*x,y标, 半个字 使用 */ bakery = row; x=Order * 0x20; /* 个字 32字 */ /* 半个字 输出,16列 */ for(i=0;i6) row=0; /* 行 界, 行 */ /* 半个字 输出 */ /* 半个字 输出,16列 */ col = bakerx; row = bakery
15、+1; for(i=0;i7) row=1; /* 行 界, 行 */ /* 半个字 输出 */ row = bakery; /* 个字 输出 */ /*/ /* 屏,全屏 */ /*/ void Lcmcls( void ) for(row=0;row- */ 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00, 0x00,0x20,0x10,0x08,0x04,0x02,0x01,0x00, /*-文字:?- */ 0x00,0x30,0x08,0x08,0x08,0x88,0x70,0x00, 0x00,0x00,0x00,0x26,0x01,0x00,0x0
16、0,0x00, /*-文字:- */ 0xC0,0x30,0xC8,0x28,0xE8,0x10,0xE0,0x00, 0x07,0x18,0x27,0x28,0x27,0x28,0x07,0x00, /*-文字:A- */ 0x00,0x00,0xE0,0x18,0x18,0xE0,0x00,0x00, 0x30,0x0F,0x04,0x04,0x04,0x04,0x0F,0x30, /*-文字:B- */ 0xF8,0x08,0x08,0x08,0x08,0x90,0x60,0x00, 0x3F,0x21,0x21,0x21,0x21,0x12,0x0C,0x00, /*-文字:C- */
17、 0xE0,0x10,0x08,0x08,0x08,0x10,0x60,0x00, 0x0F,0x10,0x20,0x20,0x20,0x10,0x0C,0x00, /*-文字:D- */ 0xF8,0x08,0x08,0x08,0x08,0x10,0xE0,0x00, 0x3F,0x20,0x20,0x20,0x20,0x10,0x0F,0x00, /*-文字:E- */ 0x00,0xF8,0x08,0x08,0x08,0x08,0x08,0x00, 0x00,0x3F,0x21,0x21,0x21,0x21,0x20,0x00, /*-文字:F- */ 0xF8,0x08,0x08,0x
18、08,0x08,0x08,0x08,0x00, 0x3F,0x01,0x01,0x01,0x01,0x01,0x00,0x00, /*-文字:G- */ 0xE0,0x10,0x08,0x08,0x08,0x10,0x60,0x00, 0x0F,0x10,0x20,0x20,0x21,0x11,0x3F,0x00, /*-文字:H- */ 0x00,0xF8,0x00,0x00,0x00,0x00,0xF8,0x00, 0x00,0x3F,0x01,0x01,0x01,0x01,0x3F,0x00, /*-文字:I- */ 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,
19、0x00, 0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00, /*-文字:J- */ 0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x00, 0x00,0x1C,0x20,0x20,0x20,0x20,0x1F,0x00, /*-文字:K- */ 0x00,0xF8,0x00,0x80,0x40,0x20,0x10,0x08, 0x00,0x3F,0x01,0x00,0x03,0x04,0x18,0x20, /*-文字:L- */ 0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x3F,0x20,0x
20、20,0x20,0x20,0x20,0x20,0x00, /*-文字:M- */ 0xF8,0xE0,0x00,0x00,0x00,0xE0,0xF8,0x00, 0x3F,0x00,0x0F,0x30,0x0F,0x00,0x3F,0x00, /*-文字:N- */ 0x00,0xF8,0x30,0xC0,0x00,0x00,0xF8,0x00, 0x00,0x3F,0x00,0x01,0x06,0x18,0x3F,0x00, /*-文字:O- */ 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00, 0x00,0x0F,0x10,0x20,0x20,0x10,
21、0x0F,0x00, /*-文字:P- */ 0xF8,0x08,0x08,0x08,0x08,0x10,0xE0,0x00, 0x3F,0x02,0x02,0x02,0x02,0x01,0x00,0x00, /*-文字:Q- */ 0x00,0xE0,0x10,0x08,0x08,0x10,0xE0,0x00, 0x00,0x0F,0x10,0x20,0x2C,0x10,0x2F,0x00, /*-文字:R- */ 0xF8,0x08,0x08,0x08,0x08,0x90,0x60,0x00, 0x3F,0x01,0x01,0x01,0x07,0x18,0x20,0x00, /*-文字:S
22、- */ 0x60,0x90,0x88,0x08,0x08,0x10,0x20,0x00, 0x0C,0x10,0x20,0x21,0x21,0x12,0x0C,0x00, /*-文字:T- */ 0x08,0x08,0x08,0xF8,0x08,0x08,0x08,0x00, 0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00, /*-文字:U- */ 0xF8,0x00,0x00,0x00,0x00,0x00,0xF8,0x00, 0x0F,0x10,0x20,0x20,0x20,0x10,0x0F,0x00, /*-文字:V- */ 0x18,0xE0,0x0
23、0,0x00,0x00,0xE0,0x18,0x00, 0x00,0x01,0x0E,0x30,0x0E,0x01,0x00,0x00, /*-文字:W- */ 0xF8,0x00,0xC0,0x38,0xC0,0x00,0xF8,0x00, 0x03,0x3C,0x03,0x00,0x03,0x3C,0x03,0x00, /*-文字:X- */ 0x08,0x30,0xC0,0x00,0xC0,0x30,0x08,0x00, 0x20,0x18,0x06,0x01,0x06,0x18,0x20,0x00, /*-文字:Y- */ 0x08,0x30,0xC0,0x00,0xC0,0x30,0
24、x08,0x00, 0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00, /*-文字:Z- */ 0x08,0x08,0x08,0x08,0xC8,0x28,0x18,0x00, 0x30,0x2C,0x22,0x21,0x20,0x20,0x20,0x00, /*-文字:- */ 0x00,0x00,0x00,0x80,0x7E,0x02,0x00,0x00, 0x00,0x00,0x00,0x00,0x3F,0x20,0x00,0x00, /*-文字:- */ 0x00,0x08,0x70,0x80,0x00,0x00,0x00,0x00, 0x00,0x00,
25、0x00,0x01,0x0E,0x30,0xC0,0x00, /*-文字:- */ 0x00,0x02,0x7E,0x80,0x00,0x00,0x00,0x00, 0x00,0x20,0x3F,0x00,0x00,0x00,0x00,0x00, /*-文字:- */ 0x00,0x08,0x04,0x02,0x02,0x04,0x08,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*-文字:_- */ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x80,0x80,0x80,0x80,0x80,0x80,
26、0x80,0x80, /*-文字:- */ 0x00,0x00,0x02,0x06,0x04,0x08,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /*-文字:a- */ 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00, 0x00,0x19,0x24,0x24,0x24,0x14,0x3F,0x00, /*-文字:b- */ 0x00,0xF8,0x00,0x80,0x80,0x80,0x00,0x00, 0x00,0x3F,0x11,0x20,0x20,0x20,0x1F,0x00, /*-文字:c-
27、 */ 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00, 0x0E,0x11,0x20,0x20,0x20,0x20,0x11,0x00, /*-文字:d- */ 0x00,0x00,0x80,0x80,0x80,0x00,0xF8,0x00, 0x00,0x1F,0x20,0x20,0x20,0x11,0x3F,0x00, /*-文字:e- */ 0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00, 0x0E,0x15,0x24,0x24,0x24,0x25,0x16,0x00, /*-文字:f- */ 0x00,0x80,0x80
28、,0xF0,0x88,0x88,0x88,0x00, 0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00, /*-文字:g- */ 0x00,0x00,0x80,0x80,0x80,0x80,0x80,0x00, 0x40,0xB7,0xA8,0xA8,0xA8,0xA7,0x40,0x00, /*-文字:h- */ 0x00,0xF8,0x00,0x80,0x80,0x80,0x00,0x00, 0x00,0x3F,0x01,0x00,0x00,0x00,0x3F,0x00, /*-文字:i- */ 0x00,0x00,0x00,0x98,0x00,0x00,0x
29、00,0x00, 0x00,0x00,0x00,0x3F,0x00,0x00,0x00,0x00, /*-文字:j- */ 0x00,0x00,0x00,0x00,0x98,0x00,0x00,0x00, 0x00,0x80,0x80,0x80,0x7F,0x00,0x00,0x00, /*-文字:k- */ 0x00,0xF8,0x00,0x00,0x00,0x80,0x00,0x00, 0x00,0x3F,0x04,0x02,0x0D,0x10,0x20,0x00, /*-文字:l- */ 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00, 0x00,0x00
30、,0x00,0x3F,0x00,0x00,0x00,0x00, /*-文字:m- */ 0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x00, 0x3F,0x00,0x00,0x3F,0x00,0x00,0x3F,0x00, /*-文字:n- */ 0x00,0x80,0x00,0x80,0x80,0x80,0x00,0x00, 0x00,0x3F,0x01,0x00,0x00,0x00,0x3F,0x00, /*-文字:o- */ 0x00,0x00,0x80,0x80,0x80,0x00,0x00,0x00, 0x0E,0x11,0x20,0x20,0x20,0x
31、11,0x0E,0x00, /*-文字:p- */ 0x00,0x80,0x00,0x80,0x80,0x80,0x00,0x00, 0x00,0xFF,0x11,0x20,0x20,0x20,0x1F,0x00, /*-文字:q- */ 0x00,0x00,0x80,0x80,0x80,0x00,0x80,0x00, 0x00,0x1F,0x20,0x20,0x20,0x11,0xFF,0x00, /*-文字:r- */ 0x00,0x00,0x80,0x00,0x00,0x80,0x80,0x00, 0x00,0x00,0x3F,0x01,0x01,0x00,0x00,0x00, /*-文
32、字:s- */ 0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00, 0x00,0x13,0x24,0x24,0x24,0x24,0x19,0x00, /*-文字:t- */ 0x00,0x80,0x80,0xE0,0x80,0x80,0x80,0x00, 0x00,0x00,0x00,0x1F,0x20,0x20,0x20,0x00, /*-文字:u- */ 0x00,0x80,0x00,0x00,0x00,0x00,0x80,0x00, 0x00,0x1F,0x20,0x20,0x20,0x10,0x3F,0x00, /*-文字:v- */ 0x80,0x00,
33、0x00,0x00,0x00,0x00,0x80,0x00, 0x00,0x07,0x18,0x20,0x18,0x07,0x00,0x00, /*-文字:w- */ 0x80,0x00,0x00,0x80,0x00,0x00,0x80,0x00, 0x0F,0x30,0x0E,0x01,0x0E,0x30,0x0F,0x00, /*-文字:x- */ 0x80,0x00,0x00,0x00,0x00,0x00,0x80,0x00, 0x20,0x11,0x0A,0x04,0x0A,0x11,0x20,0x00, /*-文字:y- */ 0x80,0x00,0x00,0x00,0x00,0x0
34、0,0x80,0x00, 0x00,0x87,0x98,0x60,0x18,0x07,0x00,0x00, /*-文字:z- */ 0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x00, 0x00,0x30,0x28,0x24,0x22,0x21,0x20,0x00, /*-文字:- */ 0x00,0x00,0x00,0x80,0x7E,0x02,0x00,0x00, 0x00,0x00,0x00,0x00,0x3F,0x20,0x00,0x00, /*-文字:|- */ 0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00, /*-文字:- */ 0x00,0x02,0x7E,0x80,0x00,0x00,0x00,0x00, 0x00,0x20,0x3F,0x00,0x00,0x00,0x00,0x00, /*-文字:- */ 0x00,0x06,0x01,0x01,0x06,0x04,0x03,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, ;