📄 lcd.lst
字号:
C51 COMPILER V7.06 LCD 04/09/2007 22:41:17 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE LCD
OBJECT MODULE PLACED IN lcd.OBJ
COMPILER INVOKED BY: E:\Keil\C51\BIN\C51.EXE lcd.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /*----------------------------------------------------------------------------------------*/
2 //240*128液晶显示驱动程序
3 //控制器件为:AT89S52
4 //T6963C接口:直接访问形式
5 //程序设计:卢印举
6 /*----------------------------------------------------------------------------------------*/
7 #include <reg51.h>
8 #include <math.h>
9 #include <hzk.c>
10
11 //信号管脚定义(全局变量)(注意:因为液晶数据口接P0,直接访问方式)
12 unsigned char xdata Lcd_Cmd_Reg _at_ 0xfdff; // C/D-P2.0 CE-P2.1 p2.0=1 p2.1=0
13 unsigned char xdata Lcd_Data_Reg _at_ 0xfcff; // C/D-P2.0 CE-P2.1 p2.0=0 p2.1=0
14
15 //以8*8字符计算,显示屏横向、纵向可以显示的点阵坐标;左、上、右、下以及当前的位置坐标
16 #define LCD_LEFT 0
17 #define LCD_TOP 0
18 #define LCD_RIGHT 239
19 #define LCD_BOTTOM 63 ////原来程序是127
20 unsigned char data Lcd_CurrentX,Lcd_CurrentY,Lcd_Mask;
21
22 unsigned char data LeftMask[]={0xff,0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01};
23 unsigned char data RightMask[]={0xff,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe};
24
25 /*----------------------------------------------------------------------------------------*/
26 //延时子程序
27 /*----------------------------------------------------------------------------------------*/
28 void Lcddelay(unsigned int t)
29 { unsigned int i,j;
30 1 for(i=0;i<t;i++)
31 1 for(j=0;j<10;j++)
32 1 ;
33 1 }
34
35 void lcdwc(unsigned char cmdcode)
36 {
37 1 while((Lcd_Cmd_Reg & 0x3) != 0x3) ; //当Lcd_Cmd_Reg低两位不同时为1
38 1 Lcd_Cmd_Reg = cmdcode;
39 1 }
40
41 void lcdwc2(unsigned char cmdcode,unsigned char cmddata)
42 {
43 1 while((Lcd_Cmd_Reg & 0x3) != 0x3) ;
44 1 Lcd_Data_Reg = cmddata;
45 1 while((Lcd_Cmd_Reg & 0x3) != 0x3) ;
46 1 Lcd_Cmd_Reg = cmdcode;
47 1 }
48
49 void lcdwc3(unsigned char cmdcode,unsigned char cmddata,unsigned char cmddata2)
50 { while((Lcd_Cmd_Reg & 0x3) != 0x3) ;
51 1 Lcd_Data_Reg = cmddata;
52 1 while((Lcd_Cmd_Reg & 0x3) != 0x3) ;
53 1 Lcd_Data_Reg = cmddata2;
54 1 while((Lcd_Cmd_Reg & 0x3) != 0x3) ;
55 1 Lcd_Cmd_Reg = cmdcode;
C51 COMPILER V7.06 LCD 04/09/2007 22:41:17 PAGE 2
56 1 }
57
58 void lcdwd(unsigned char dispdata) //写数据
59 { while((Lcd_Cmd_Reg & 0x3) != 0x3) ;
60 1 Lcd_Data_Reg = dispdata;
61 1 while((Lcd_Cmd_Reg & 0x3) != 0x3) ;
62 1 Lcd_Cmd_Reg = 0xc0; //数据写,地址加一
63 1 }
64
65 unsigned char lcdrdata(void) //读数据
66 { while((Lcd_Cmd_Reg & 0x3) != 0x3) ;
67 1 Lcd_Cmd_Reg = 0xc5; //数据读,地址不变
68 1 while((Lcd_Cmd_Reg & 0x3) != 0x3) ;
69 1 return Lcd_Data_Reg;
70 1 }
71
72 void lcdpos(void) //内部写数指针定位
73 { unsigned int CurrentAddress;
74 1 CurrentAddress = Lcd_CurrentY * 30 ;
75 1 CurrentAddress += Lcd_CurrentX/8;
76 1 lcdwc3(0x24,CurrentAddress & 0xff,CurrentAddress/256);//设置将要进行操作的显示缓冲区(RAM)的一个地址单元
-,
77 1 //D1,D2为这个地址的低和高八位。
78 1 }
79
80 unsigned char lcdrd(void) //读数据
81 { lcdpos();
82 1 return lcdrdata();
83 1 }
84
85 void lcdcursornextbyte(void) //当前坐标移动到下一个点
86 { Lcd_CurrentX+=8;
87 1 if(Lcd_CurrentX > LCD_RIGHT)
88 1 { Lcd_CurrentX = LCD_LEFT;
89 2 Lcd_CurrentY++;
90 2 if(Lcd_CurrentY > LCD_BOTTOM)
91 2 Lcd_CurrentY = LCD_TOP;
92 2 }
93 1 }
94
95 void displaybyte(unsigned char dispdata) //不明白Lcd_Mask的含义
96 { lcdpos();
97 1 if(Lcd_Mask == 0xff)
98 1 lcdwd(dispdata);
99 1 else
100 1 { unsigned char d=lcdrd();
101 2 d&=(~Lcd_Mask);
102 2 d|=(dispdata & Lcd_Mask);
103 2 lcdwd(d);
104 2 }
105 1 lcdcursornextbyte();
106 1 }
107
108 void Fill_Scr(unsigned char FillData) //LCD整屏显示
109 { Lcd_Mask=0xff;
110 1 for(Lcd_CurrentX = LCD_LEFT,Lcd_CurrentY = LCD_TOP;1;)
111 1 { displaybyte(FillData);
112 2 if((Lcd_CurrentX == LCD_LEFT) && (Lcd_CurrentY == LCD_TOP)) break;
113 2 }
114 1 }
115
116 void lcdreset() //初始化LCD屏
C51 COMPILER V7.06 LCD 04/09/2007 22:41:17 PAGE 3
117 { lcdwc(0x80); //CGROM有效,即内部字符发生器有效。(00-7F)
118 1 lcdwc(0x98); //图形显示启用,文本显示禁止,光标显示禁止,光标闪烁禁止。
119 1 lcdwc3(0x42,0,0); //图形区首地址 0
120 1 lcdwc3(0x43,30,0); //图形区宽度30字节,即240bit
121 1 }
122
123 void displaychinesechardot(unsigned int Index);
124 void displayenglishchardot(unsigned int Index);
125 void putsizeimage(unsigned char XSIZE,unsigned char YSIZE,unsigned char code *s);
126
127 void putchar(unsigned int uChar) //信息显示
128 { unsigned int i;
129 1 if(uChar<128)
130 1 for(i=0;i != ENGLISHCHARNUMBER;i++)
131 1 { if(uChar ==EnglishCode[i])
132 2 { displayenglishchardot(i);
133 3 break;
134 3 }
135 2 }
136 1 else
137 1 for(i=0;i != CHINESECHARNUMBER;i++)
138 1 { if(uChar ==ChineseCode[i])
139 2 { displaychinesechardot(i);
140 3 break;
141 3 }
142 2 }
143 1 }
144
145 void put_str(unsigned char code *s) //显示汉字或英文字符
146 { unsigned int i;
147 1 for (;*s != 0;s++)
148 1 { i=*s;
149 2 if(*s > 127)
150 2 { s++;
151 3 i=i*256+*s;
152 3 }
153 2 if(i == '\n')
154 2 { Lcd_CurrentX = LCD_LEFT;
155 3 if(Lcd_CurrentY > LCD_BOTTOM-CHINESECHARSIZE+1)
156 3 Lcd_CurrentY=LCD_TOP;
157 3 else
158 3 Lcd_CurrentY+=CHINESECHARSIZE;
159 3 }
160 2 putchar(i);
161 2 }
162 1 }
163
164 void put_str_xy(unsigned char x,unsigned char y,unsigned char code *s)//显示汉字或英文字符
165 { Lcd_CurrentX=x;
166 1 Lcd_CurrentY=y;
167 1 put_str(s);
168 1 }
169
170 void displaychinesechardot(unsigned int Index) //显示字库里的第几个字
171 { unsigned char code *s;
172 1 s=ChineseCharDot+Index*CHINESECHARDOTSIZE;
173 1 if(Lcd_CurrentX > LCD_RIGHT-CHINESECHARSIZE+1) //是否剩余的x大于16
174 1 { Lcd_CurrentX = LCD_LEFT;
175 2 Lcd_CurrentY+=CHINESECHARSIZE; //一行放不下就另起一行。
176 2 if(Lcd_CurrentY > LCD_BOTTOM-CHINESECHARSIZE+1)
177 2 Lcd_CurrentY=LCD_TOP; //显示到最下面还是放不下就从第一行重新开始显示
178 2 }
C51 COMPILER V7.06 LCD 04/09/2007 22:41:17 PAGE 4
179 1 putsizeimage(CHINESECHARSIZE,CHINESECHARSIZE,s);
180 1 }
181
182 void displayenglishchardot(unsigned int Index)
183 { unsigned char code *s;
184 1 s=EnglishCharDot+Index*ENGLISHCHARDOTSIZE;
185 1 if(Lcd_CurrentX > LCD_RIGHT-ENGLISHCHARSIZE+1)
186 1 { Lcd_CurrentX = LCD_LEFT;
187 2 Lcd_CurrentY+=CHINESECHARSIZE;
188 2 if(Lcd_CurrentY > LCD_BOTTOM-CHINESECHARSIZE+1)
189 2 Lcd_CurrentY=LCD_TOP;
190 2 }
191 1 putsizeimage(ENGLISHCHARSIZE,CHINESECHARSIZE,s);
192 1 }
193
194 void point(unsigned char bitdata)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -