?? lcd_driver.lst
字號:
C51 COMPILER V8.05a LCD_DRIVER 09/22/2009 20:36:57 PAGE 1
C51 COMPILER V8.05a, COMPILATION OF MODULE LCD_DRIVER
OBJECT MODULE PLACED IN LCD_Driver.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE LCD_Driver.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /*
2 控制器:st7565
3 串行驅(qū)動方式,唯一要注意的一點就是WR和RD這兩個引腳雖然用不到,但是要接地,
4 否則無法正常顯示。當(dāng)時調(diào)了很久。不知道其他廠家的是否也這樣。
5
6 */
7 #include <AT89X52.H>
8 #include <INTRINS.H>
9
10 #include "LCD_Driver.h"
11 //字庫
12 #include "hzk.h"
13
14 //當(dāng)前字符顯示的位置
15 //unsigned char Lcd_Charcter_CurrentX,Lcd_Charcter_CurrentY;
16 //當(dāng)前像素顯示位置
17 unsigned char Lcd_CurrentX,Lcd_CurrentY;
18 //圖像反色顯示 0 否 1是
19 bit LCD_DisplayReserve_Driver;
20
21 //定義LCD顯示的全局變量
22 #define CS_Port P3_0
23 #define A0_Port P3_1
24 #define SI_Port P3_2
25 #define SCL_Port P3_3
26 #define RST_Port P3_4
27 enum PINDefine{CS,A0,SI,SCL,RST};
28
29 //設(shè)置某一位
30 void SETBit(unsigned char PIN)
31 {
32 1
33 1 switch (PIN)
34 1 {
35 2 case CS :
36 2 CS_Port=1;
37 2 break;
38 2
39 2 case A0 :
40 2 A0_Port=1;
41 2 break;
42 2
43 2 case SI :
44 2 SI_Port=1;
45 2 break;
46 2
47 2 case SCL :
48 2 SCL_Port=1;
49 2 break;
50 2
51 2 case RST :
52 2 RST_Port=1;
53 2 break;
54 2 }
55 1
C51 COMPILER V8.05a LCD_DRIVER 09/22/2009 20:36:57 PAGE 2
56 1
57 1 }
58
59 //清某一位
60 void CLRBit(unsigned char PIN)
61 {
62 1 switch (PIN)
63 1 {
64 2 case CS :
65 2 CS_Port=0;
66 2 break;
67 2
68 2 case A0 :
69 2 A0_Port=0;
70 2 break;
71 2
72 2 case SI :
73 2 SI_Port=0;
74 2 break;
75 2
76 2 case SCL :
77 2 SCL_Port=0;
78 2 break;
79 2
80 2 case RST :
81 2 RST_Port=0;
82 2 break;
83 2 }
84 1 }
85
86
87 /***********************************
88 ** 函數(shù)名稱: Delay
89 ** 功能描述: 延時時間=(n*9+17)*12/F
90 ** 輸 入: n
91 ** 輸 出 : 無
92 ** 全局變量:無
93 ** 調(diào)用模塊: 無
94 ******************************************/
95
96 void LCD_DelayMS(unsigned int n)
97 {
98 1 while(n--);
99 1 return;
100 1 }
101
102 //--------------------------------------------------------------------------
103 //串口移位輸出
104 //--------------------------------------------------------------------------
105 void LCDShiftWrite(char datain)
106 {
107 1 unsigned char i;
108 1 unsigned char Series,Temp;
109 1 Series = datain;
110 1
111 1 for(i=8;i>0;i--)
112 1 {
113 2 CLRBit(SCL); //SCL=0
114 2 Temp=Series & 0x80;
115 2 if(Temp)
116 2 {
117 3 SETBit(SI);//SI=1
C51 COMPILER V8.05a LCD_DRIVER 09/22/2009 20:36:57 PAGE 3
118 3 }
119 2 else
120 2 {
121 3 CLRBit(SI);//SI=0
122 3 }
123 2 SETBit(SCL); //SCL=1
124 2 Series = Series << 1;
125 2 }
126 1
127 1 }
128 /***********************************
129 ** 函數(shù)名稱: Write_Data
130 ** 功能描述: 傳送數(shù)據(jù)
131 ** 輸 入: dat
132 ** 輸 出 : 無
133 ** 全局變量:無
134 ** 調(diào)用模塊: Busy,
135 ******************************************/
136
137 void Write_Data(unsigned char dat)
138 {
139 1 CLRBit(CS); //CS=0
140 1 SETBit(A0); //A0=1,數(shù)據(jù)
141 1 LCDShiftWrite(dat);
142 1 SETBit(CS); //CS=1;
143 1 return;
144 1 }
145
146 /***********************************
147 ** 函數(shù)名稱: Write_Instruction
148 ** 功能描述: 傳送命令
149 ** 輸 入: dat
150 ** 輸 出 : 無
151 ** 全局變量:無
152 ** 調(diào)用模塊: Busy,
153 ******************************************/
154
155 void Write_Instruction(unsigned char cmd)
156 {
157 1 CLRBit(CS); //CS=0
158 1 CLRBit(A0); //A0=0,命令
159 1 LCDShiftWrite(cmd);
160 1 SETBit(CS); //CS=1;
161 1 return;
162 1 }
163
164 //==============================================================================高一級函數(shù)
165 //設(shè)置像素顯示坐標(biāo)(x:0-127,y:0-7)
166 void LCD_setpos_Driver(unsigned char Lx,unsigned char Ly)
167 {
168 1 Write_Instruction(0xB0|Ly);// Page(Row)
169 1 Write_Instruction((0x10|(Lx>>4)));
170 1 Write_Instruction((0x0f&Lx));
171 1 Lcd_CurrentX=Lx;
172 1 Lcd_CurrentY=Ly;
173 1
174 1 }
175 /*
176 //設(shè)置像素顯示坐標(biāo)(x:0-127)
177 void LCD_setposX_Driver(unsigned char Lx)
178 {
179 Write_Instruction((0x10|(Lx>>4)));
C51 COMPILER V8.05a LCD_DRIVER 09/22/2009 20:36:57 PAGE 4
180 Write_Instruction((0x0f&Lx));
181 }
182 //設(shè)置像素顯示坐標(biāo)(y:0-7)
183 void LCD_setposY_Driver(unsigned char Ly)
184 {
185 Write_Instruction(0xB0|Ly);// Page(Row)
186 }
187 */
188
189 //設(shè)置字符位置(x:0-8,y:0-3)
190 void LCD_setCharpos_Driver(unsigned char Lx,unsigned char Ly)
191 {
192 1 //當(dāng)前像素顯示位置
193 1 Lcd_CurrentX=Lx*16;
194 1 Lcd_CurrentY=Ly*2;
195 1 LCD_setpos_Driver(Lcd_CurrentX,Lcd_CurrentY);
196 1 }
197
198
199 //清屏
200 void LCD_CLS_Driver(char value)
201 {
202 1 unsigned char i,n;
203 1
204 1 for(i=0;i<9;i++)
205 1 {
206 2 LCD_setpos_Driver(0,i);
207 2
208 2 for(n=0;n<128;n++)
209 2 {
210 3 Write_Data(value);
211 3 }
212 2 }
213 1
214 1 }
215 //顯示BMP圖片
216 void LCD_DisplayBMP_Driver(unsigned char *PicData) //信息顯示
217 {
218 1 unsigned char BMPwithLen,BMPheightLen;
219 1 unsigned char BMPwith;
220 1 unsigned char BMPheight;
221 1 BMPwith=*PicData;
222 1 PicData++;
223 1 BMPheight=(*PicData)/8;
224 1 PicData++;
225 1
226 1 //BMPLen=BMPheight/8*BMPwith
227 1
228 1 for(BMPheightLen=0;BMPheightLen<BMPheight;BMPheightLen++)
229 1 {
230 2 Lcd_CurrentY++;
231 2 LCD_setpos_Driver(Lcd_CurrentX,Lcd_CurrentY);
232 2 for(BMPwithLen=0;BMPwithLen<BMPwith;BMPwithLen++)
233 2 {
234 3 //圖像反色顯示 0 否 1是
235 3 if (LCD_DisplayReserve_Driver==0)
236 3 {
237 4 Write_Data(*PicData);
238 4 }
239 3 else
240 3 {
241 4 Write_Data(~(*PicData));
C51 COMPILER V8.05a LCD_DRIVER 09/22/2009 20:36:57 PAGE 5
242 4 }
243 3 PicData++;
244 3 };
245 2 }
246 1
247 1 }
248
249 void LCD_disp_DisplayImage_Driver(unsigned char * PicData,unsigned char PicLen) //信息顯示
250 {
251 1
252 1 for(;PicLen>0;PicLen--)
253 1 {
254 2
255 2 //圖像反色顯示 0 否 1是
256 2 if (LCD_DisplayReserve_Driver==0)
257 2 {
258 3 Write_Data(*PicData);
259 3 }
260 2 else
261 2 {
262 3 Write_Data(~(*PicData));
263 3 }
264 2
265 2
266 2 PicData++;
267 2 };
268 1
269 1 }
270
271
272
273
274 //顯示一個Unicode
275 void LCD_disp_Putchar_Driver(unsigned int uChar)
276 {
277 1 unsigned int i;
278 1 unsigned char *p;
279 1 if(uChar<128)
280 1 {
281 2 //for(i=0;i != ENGLISHCHARNUMBER;i++)
282 2 //{
283 2 //if(uChar==EnglishCode[i][0])
284 2 //{
285 2 p=(uChar-0x20)*(ENGLISHCHARLegth)+&nAsciiDot[0];
286 2
287 2 LCD_disp_DisplayImage_Driver(p, ENGLISHCHARLegth/2);
288 2 Lcd_CurrentY++;
289 2 //設(shè)置像素顯示坐標(biāo)(y:0-7)
290 2 LCD_setpos_Driver(Lcd_CurrentX,Lcd_CurrentY);
291 2 LCD_disp_DisplayImage_Driver(p+(ENGLISHCHARLegth/2),(ENGLISHCHARLegth/2));
292 2 Lcd_CurrentY--;
293 2 Lcd_CurrentX+=8;
294 2 //設(shè)置像素顯示坐標(biāo)(y:0-7)
295 2 LCD_setpos_Driver(Lcd_CurrentX,Lcd_CurrentY);
296 2 //break;
297 2 //}
298 2 //}
299 2 }
300 1 else
301 1 {
302 2 for(i=0;i!=GB_ZK_NUM;i++)
303 2 {
C51 COMPILER V8.05a LCD_DRIVER 09/22/2009 20:36:57 PAGE 6
304 3 if(uChar==(GB_16[i].Index[0]*256+GB_16[i].Index[1]))
305 3 {
306 4 //分別在兩頁顯示
307 4 LCD_disp_DisplayImage_Driver(GB_16[i].Msk,(CHINESECHARlegth/2));
308 4 Lcd_CurrentY++;
309 4 //設(shè)置像素顯示坐標(biāo)(y:0-7)
310 4 LCD_setpos_Driver(Lcd_CurrentX,Lcd_CurrentY);
311 4 LCD_disp_DisplayImage_Driver(GB_16[i].Msk+(CHINESECHARlegth/2),(CHINESECHARlegth/2));
312 4 Lcd_CurrentY--;
313 4 Lcd_CurrentX+=16;
314 4 //設(shè)置像素顯示坐標(biāo)(y:0-7)
315 4 LCD_setpos_Driver(Lcd_CurrentX,Lcd_CurrentY);
316 4 break;
317 4 }
318 3 }
319 2 }
320 1 }
321
322
323 //圖像反色顯示 0 否 1是,執(zhí)行此命令后的所有操作均是按照設(shè)置顯示
324 void LCD_disp_SetReverse_Driver(unsigned char ReverseTrue)
325 {
326 1 //圖像反色顯示 0 否 1是
327 1 if (ReverseTrue==0)
328 1 {
329 2 LCD_DisplayReserve_Driver=0;
330 2 }
331 1 else
332 1 {
333 2 LCD_DisplayReserve_Driver=1;
334 2 }
335 1 }
336 //對比度設(shè)置
337 void Set_Contrast_Control_Register(unsigned char Level)
338 {
339 1 unsigned char Num,Temp1,Temp2;
340 1 Temp1 = (Level/16)<<4;
341 1 switch(Level%16)
342 1 {
343 2 case 10:
344 2 Temp2 = 0x0a;
345 2 break;
346 2 case 11:
347 2 Temp2 = 0x0b;
348 2 break;
349 2 case 12:
350 2 Temp2 = 0x0c;
351 2 break;
352 2 case 13:
353 2 Temp2 = 0x0d;
354 2 break;
355 2 case 14:
356 2 Temp2 = 0x0e;
357 2 break;
358 2 case 15:
359 2 Temp2 = 0x0f;
360 2 break;
361 2 default:
362 2 Temp2 = Level%16;
363 2 break;
364 2 }
365 1 Num = Temp1|Temp2;
C51 COMPILER V8.05a LCD_DRIVER 09/22/2009 20:36:57 PAGE 7
366 1 Write_Instruction(0x81);
367 1 Write_Instruction(Num);
368 1 }
369
370
371
372
373 //初始化LCD屏
374 void init_LCD_Driver()
375 {
376 1
377 1 CLRBit(RST); // RST=0;
378 1 LCD_DelayMS(50);
379 1 SETBit(RST); // RST=1;
380 1 LCD_DelayMS(50);
381 1 Write_Instruction(0xa2); //lcd bias select 1/9 BIAS
382 1 Write_Instruction(0xa1); //ADC select,REVERSE 127-->0(a0,a1)
383 1 Write_Instruction(0xc0); //com select,NORMAL 0-->63(c8,c0)
384 1 Write_Instruction(0x26); //RESISTOR RATIO
385 1 Write_Instruction(0x81); //ELECTRONIC VOLUME mode setting 100B 對比度命令
386 1 Write_Instruction(0x10); //Set reference voltagel register 對比度數(shù)值
387 1 Write_Instruction(0x2f); //power control(VB,VR,VF=1,1,1)
388 1 LCD_DelayMS(50);
389 1 Write_Instruction(0xaf); //set display on
390 1 Write_Instruction(0xf8); //set booster ratio
391 1 Write_Instruction(0x00);
392 1 //當(dāng)前像素顯示位置
393 1 Lcd_CurrentX=0;
394 1 Lcd_CurrentY=0;
395 1 //圖像反色顯示 0 否 1是
396 1 LCD_DisplayReserve_Driver=0;
397 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 766 ----
CONSTANT SIZE = 3406 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 2 13
IDATA SIZE = ---- ----
BIT SIZE = 1 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -