📄 lcd.lst
字号:
C51 COMPILER V8.02 LCD 04/26/2008 21:37:30 PAGE 1
C51 COMPILER V8.02, COMPILATION OF MODULE LCD
OBJECT MODULE PLACED IN lcd.OBJ
COMPILER INVOKED BY: D:\Keil1\C51\BIN\C51.EXE lcd.c BROWSE DEBUG OBJECTEXTEND
line level source
1
2 #include "lcd.h"
3 #include <REGX51.H>
4
5
6
7
8 #define LCD_E P3_5
9 #define LCD_RS P3_7
10 #define LCD_RW P3_6
11 #define LCD_DBX P1
12
13
14
15
16 ////////////////////////////////////////////////////////////////////////////
17 //
18 // 物理接口层
19
20
21 void lcdSetBus(BIT rs, BYTE dbx)
22 {
23 1 LCD_E = 1;
24 1
25 1 LCD_RS = rs;
26 1 LCD_RW = 0;
27 1 LCD_DBX = dbx;
28 1
29 1 LCD_E = 0;
30 1 }
31
32 /*
33 BYTE lcdGetBus(BIT rs)
34 {
35 LCD_E = 1;
36
37 LCD_RS = rs;
38 LCD_RW = 1;
39
40 LCD_E = 0;
41 LCD_E = 0;
42
43 LCD_DBX = 0xff;
44 return LCD_DBX;
45 }
46 */
47
48
49
50 ////////////////////////////////////////////////////////////////////////////
51 //
52 // 逻辑控制层
53
54 /*
55 BYTE lcdReadBusyFlagAddress(void)
C51 COMPILER V8.02 LCD 04/26/2008 21:37:30 PAGE 2
56 {
57 return lcdGetBus(0);
58 }
59 */
60
61 void lcdClearDisplay(void)
62 {
63 1 // while ( lcdReadBusyFlagAddress() & 0x80 );
64 1 DelayX1ms(2);
65 1 lcdSetBus(0,0x01);
66 1 DelayX1ms(2);
67 1 }
68
69 /*
70 void lcdReturnHome(void)
71 {
72 // while ( lcdReadBusyFlagAddress() & 0x80 );
73
74 lcdSetBus(0,0x02);
75 }
76 */
77
78 void lcdEntryModeSet(BIT id, BIT s)
79 {
80 1 // while ( lcdReadBusyFlagAddress() & 0x80 );
81 1
82 1 lcdSetBus(0, 0x04|(id?0x02:0)|(s?0x01:0) );
83 1 DelayX1ms(1);
84 1 }
85
86 void lcdDisplayOnOffControl(BIT d, BIT c, BIT b)
87 {
88 1 // while ( lcdReadBusyFlagAddress() & 0x80 );
89 1
90 1 lcdSetBus(0,0x08|(d?0x04:0)|(c?0x02:0)|(b?0x01:0));
91 1 DelayX1ms(1);
92 1 }
93
94 /*
95 void lcdCursorDisplayShift(BIT sc, BIT rl)
96 {
97 // while ( lcdReadBusyFlagAddress() & 0x80 );
98
99 lcdSetBus(0,0x10|(sc?0x08:0)|(rl?0x04:0));
100 }
101 */
102
103 void lcdFunctionSet(BIT dl, BIT n, BIT f)
104 {
105 1 // while ( lcdReadBusyFlagAddress() & 0x80 );
106 1
107 1 lcdSetBus(0,0x20|(dl?0x10:0)|(n?0x08:0)|(f?0x04:0));
108 1 DelayX1ms(1);
109 1 }
110
111 /*
112 void lcdSetCGRAMAddress(BYTE acg)
113 {
114 // while ( lcdReadBusyFlagAddress() & 0x80 );
115
116 lcdSetBus(0,0x40|(acg&0x3f));
117 }
C51 COMPILER V8.02 LCD 04/26/2008 21:37:30 PAGE 3
118 */
119
120 void lcdSetDDRAMAddress(BYTE add)
121 {
122 1 // while ( lcdReadBusyFlagAddress() & 0x80 );
123 1 lcdSetBus(0,0x80|(add&0x7f));
124 1 DelayX1ms(1);
125 1 }
126
127
128 void lcdWriteDataToCGDDRAM(BYTE bData)
129 {
130 1 // while ( lcdReadBusyFlagAddress() & 0x80 );
131 1 lcdSetBus(1,bData);
132 1 DelayX1ms(1);
133 1 }
134
135 /*
136 BYTE lcdReadDataFromCGDDRAM(void)
137 {
138 // while ( lcdReadBusyFlagAddress() & 0x80 );
139
140 return lcdGetBus(1);
141 }
142 */
143
144
145 ////////////////////////////////////////////////////////////////////////////
146 //
147 // 应用接口层
148
149
150 void lcdInit(void)
151 {
152 1 /////////////////////////
153 1 // 软复位
154 1
155 1 DelayX1ms(50);
156 1
157 1 lcdSetBus(0,0x30); DelayX1ms(5);
158 1 lcdSetBus(0,0x30); DelayX1ms(1);
159 1 lcdSetBus(0,0x30); DelayX1ms(1);
160 1
161 1 lcdFunctionSet(1,1,0); //(BIT dl, BIT n, BIT f) set n(lines) & f(font)
162 1 lcdDisplayOnOffControl(1,0,0); //(BIT d, BIT c, BIT b)
163 1 lcdClearDisplay();
164 1 lcdEntryModeSet(1,0); //(BIT id, BIT s)
165 1
166 1
167 1 /////////////////////////
168 1 // 初始化
169 1
170 1 DelayX1ms(10);
171 1 }
172
173
174 void lcdTextAddOut(char* pStr)
175 {
176 1 BYTE i = 0;
177 1 while (pStr[i])
178 1 {
179 2 lcdWriteDataToCGDDRAM( pStr[i] );
C51 COMPILER V8.02 LCD 04/26/2008 21:37:30 PAGE 4
180 2 i++;
181 2 if (i>200) break;
182 2 }
183 1 }
184
185
186 void lcdTextOut(BYTE x, BYTE y, char* pStr)
187 {
188 1 BYTE i;
189 1
190 1 if (y & 0x01) x+=0x40;
191 1 if (y & 0x02) x+=20;
192 1 lcdSetDDRAMAddress( x );
193 1
194 1 i = 0;
195 1 while (pStr[i])
196 1 {
197 2 lcdWriteDataToCGDDRAM( pStr[i] );
198 2 i++;
199 2 if (i>200) break;
200 2 }
201 1 }
202
203
204 void lcdHexOut(BYTE byte)
205 {
206 1 BYTE h;
207 1
208 1 h = (byte>>4)&0x0f;
209 1 if (h < 0x0a) h += '0';
210 1 else h += ('A' - 0x0a);
211 1 lcdWriteDataToCGDDRAM( h );
212 1
213 1 h = byte&0x0f;
214 1 if (h < 0x0a) h += '0';
215 1 else h += ('A' - 0x0a);
216 1 lcdWriteDataToCGDDRAM( h );
217 1 }
218
219
220 void lcdUIntOut(BYTE byte, BYTE width)
221 {
222 1 while (width)
223 1 {
224 2 switch (width)
225 2 {
226 3 case 1: // x1
227 3 lcdWriteDataToCGDDRAM( '0'+ (byte % 10) );
228 3 break;
229 3 case 2: // x10
230 3 lcdWriteDataToCGDDRAM( '0'+ ((byte/10) % 10) );
231 3 break;
232 3 case 3: // x100
233 3 lcdWriteDataToCGDDRAM( '0'+ ((byte/100) % 10) );
234 3 break;
235 3 default:;
236 3 }
237 2 width--;
238 2 }
239 1 }
240
241
C51 COMPILER V8.02 LCD 04/26/2008 21:37:30 PAGE 5
242 void lcdDateOut(DATETIME * pDtt)
243 {
244 1 //year
245 1 lcdTextAddOut("20");
246 1 lcdUIntOut(pDtt->yy,2);
247 1 lcdTextAddOut("-");
248 1
249 1 //month
250 1 lcdUIntOut(pDtt->mo,2);
251 1 lcdTextAddOut("-");
252 1
253 1 //day
254 1 lcdUIntOut(pDtt->dd,2);
255 1 }
256
257
258 void lcdTimeOut(DATETIME * pDtt)
259 {
260 1 //year
261 1 lcdUIntOut(pDtt->hh,2);
262 1 lcdTextAddOut(":");
263 1
264 1 //month
265 1 lcdUIntOut(pDtt->mi,2);
266 1 lcdTextAddOut(":");
267 1
268 1 //day
269 1 lcdUIntOut(pDtt->ss,2);
270 1 }
271
272
273 void lcdTempeOut(TEMPE* pT, BIT bConvertToF)
274 //-mmm.nn
275 {
276 1 BYTE m,n;
277 1 TEMPE tempe;
278 1 // 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
279 1 const BYTE code div[] = { 00, 06, 13, 19, 25, 31, 38, 44, 50, 56, 63, 69, 75, 81, 88, 94,
- };
280 1 // const BYTE -div[] = { 94, 88, 81, 75, 69, 63, 56, 50, 44, 38, 31, 25, 19, 16, 06, 00, }
-; //正的倒序
281 1
282 1 tempe = *pT;
283 1 if (bConvertToF) ConvertCtoF(pT);
284 1
285 1
286 1 m = ((pT->th << 4) & 0xf0) | ((pT->tl >> 4) & 0x0f);
287 1
288 1 if (pT->th & 0x80)
289 1 {
290 2 lcdTextAddOut("-");
291 2 m = ~m;
292 2 n = div[(16 - pT->tl) & 0x0f];
293 2 }
294 1 else
295 1 {
296 2 lcdTextAddOut("+");
297 2 n = div[pT->tl & 0x0f];
298 2 }
299 1
300 1 lcdUIntOut( m / 100, 1 );
301 1 m%=100;
C51 COMPILER V8.02 LCD 04/26/2008 21:37:30 PAGE 6
302 1 lcdUIntOut( m / 10, 1 );
303 1 m%=10;
304 1 lcdUIntOut( m, 1 );
305 1
306 1 lcdTextAddOut( "." );
307 1
308 1 lcdUIntOut( n / 10, 1 );
309 1 lcdUIntOut( n % 10, 1 );
310 1
311 1 lcdTextAddOut( bConvertToF ? "F" : "C" );
312 1
313 1 *pT = tempe;
314 1 }
315
316
317
318
319
320
321
322
323
324
325
326 // keyboard.c
327 #include "keyboard.h"
328 #include <REGX51.H>
329 #include "lcd.h"
330
331
332
333 #define KBD P0
334
335
336
337 BYTE kbdReadPort(void)
338 {
339 1 BYTE in,out;
340 1 out = 0;
341 1
342 1 KBD = 0x0f;
343 1 in = KBD;
344 1 while (in & 0x08)
345 1 {
346 2 in<<=1;
347 2 out++;
348 2 if (out>=4) return 0xff;
349 2 }
350 1
351 1 KBD = 0xf0;
352 1 in = KBD;
353 1 while (in & 0x80)
354 1 {
355 2 in<<=1;
356 2 out+=4;
357 2 if (out>=16) return 0xff;
358 2 }
359 1
360 1 // lcdTextOut(15,3,""); lcdHexOut(out); // for debug only
361 1 return out;
362 1 }
363
C51 COMPILER V8.02 LCD 04/26/2008 21:37:30 PAGE 7
364
365 BYTE kbdGetKeyPress(void)
366 {
367 1 static BYTE lastStatus = 0xff;
368 1 BYTE now,rt;
369 1
370 1 rt = 0xff;
371 1
372 1 now = kbdReadPort();
373 1 if (now < 16)
374 1 {
375 2 if (lastStatus >= 16)
376 2 {
377 3 //key down
378 3 rt = now;
379 3 DelayX1ms(50);
380 3 }
381 2 }
382 1 else
383 1 {
384 2 if (lastStatus < 16)
385 2 {
386 3 //key up
387 3 DelayX1ms(50);
388 3 }
389 2 }
390 1
391 1 lastStatus = now;
392 1 return rt;
393 1 }
394
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 953 ----
CONSTANT SIZE = 31 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 1 27
IDATA SIZE = ---- ----
BIT SIZE = ---- 10
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -