📄 lcd_a.lst
字号:
C51 COMPILER V6.10 LCD_A 04/18/2001 16:29:05 PAGE 1
C51 COMPILER V6.10, COMPILATION OF MODULE LCD_A
OBJECT MODULE PLACED IN .\LCD_A.OBJ
COMPILER INVOKED BY: C:\KEIL\C51\BIN\C51.EXE .\LCD_A.C OPTIMIZE(6,SIZE) BROWSE NOINTPROMOTE DEBUG OBJECTEXTEND
stmt level source
1 /*------------------------------------------------------------------*-
2
3 LCD_A.C (v1.01)
4
5 ------------------------------------------------------------------
6
7 LCD LIBRARY CODE
8
9 Designed for scheduled operation,
10 in this case for a 2-line x 20-character display
11
12 '4-BIT' INTERFACE (uses 6 pins) to standard HD44780-based LCD
13
14
15 COPYRIGHT
16 ---------
17
18 This code is from the book:
19
20 PATTERNS FOR TIME-TRIGGERED EMBEDDED SYSTEMS by Michael J. Pont
21 [Pearson Education, 2001; ISBN: 0-201-33138-1].
22
23 This code is copyright (c) 2001 by Michael J. Pont.
24
25 See book for copyright details and other information.
26
27 -*------------------------------------------------------------------*/
28
29 // Hardware resources:
30 // Uses T0 (for delays) plus six I/O pins
31
32 #include "Main.h"
33 #include "Port.h"
34
35 #include "LCD_A.h"
36 #include "Delay_T0.h"
37
38
39 // ------ Public variable definitions ------------------------------
40
41 // The LCD data
42 char LCD_data_G[LCD_LINES][LCD_CHARACTERS+1]
43 = {" PLEASE WAIT "," ... "};
44
45 // ------ Private function prototypes ------------------------------
46
47 static void LCD_Send_Byte(const tByte, const bit) ;
48 static void LCD_Create_Character(const tByte, const tByte* const);
49
50 static void LCD_SetDDRAM(tByte);
51 static void LCD_Delay(void);
52
53 // ------ Private constants ----------------------------------------
54
55 // Bitmaps for user-defined characters [for demonstration purposes]
C51 COMPILER V6.10 LCD_A 04/18/2001 16:29:05 PAGE 2
56
57 // This is a UK Pound (currency) sign
58 // 765 43210
59 // ... ...11 - 3 (Decimal)
60 // ... ..1.. - 4
61 // ... .111. - 14
62 // ... ..1.. - 4
63 // ... ..1.. - 4
64 // ... ..1.. - 4
65 // ... 11111 - 31
66 // ... ..... - 0
67 const tByte LCD_UDC_Pounds[8] = {3,4,14,4,4,31,0};
68 // #define LCD_UDC_POUNDS 1 (See LCD_A.H)
69
70 // This is 'Degrees Celsius' (as in temp. of boiling water = 100oC)
71 // 765 43210
72 // ... .11.. = 12 (Decimal)
73 // ... 1..1. = 18
74 // ... .11.. = 12
75 // ... ...11 = 3
76 // ... ..1.. = 4
77 // ... ..1.. = 4
78 // ... ...11 = 3
79 // ... ..... - 0
80 const tByte LCD_UDC_Degrees_C[8] = {12,18,12,3,4,4,3,0};
81 // #define LCD_UDC_DEGREES_C 2 (See LCD_A.H)
82
83 #define LCD_DISPLAY_OFF_CURSOR_OFF_BLINKING_OFF 0x08
84 #define LCD_DISPLAY_ON_CURSOR_OFF_BLINKING_OFF 0x0C
85
86 #define LCD_INC_ADDR_NO_SCROLL 0x06
87 #define LCD_CURSOR_OFF 0x08
88 #define LCD_DISPLAY_ON 0x04
89 #define LCD_CLEAR_DISPLAY 0x01
90 #define LCD_8BIT_2LINE_5x8FONT 0x38 // 0011 1000
91 #define LCD_4BIT_2LINE_5x8FONT 0x28 // 0010 1000
92
93 // Define Timer 0 / Timer 1 reload values for ~50 us delay
94 #define PRELOAD50micros (65536 - (tWord)((OSC_FREQ / 20000)/(OSC_PER_INST)))
95 #define PRELOAD50microsH (PRELOAD50micros / 256)
96 #define PRELOAD50microsL (PRELOAD50micros % 256)
97
98 /*------------------------------------------------------------------*-
99
100 LCD_Init()
101
102 RATHER SLOW, BUT MANAGES TO INITIALISE ALL TESTED DISPLAYS
103 (and is only called at the start of the program)
104
105 NOTE: I suggest you call this function THREE TIMES.
106
107 Set TURN_DISPLAY_ON to '1' last time function is called.
108
109 -*------------------------------------------------------------------*/
110 void LCD_Init(const bit TURN_DISPLAY_ON)
111 {
112 1 tByte loop;
113 1 tByte l,c;
114 1
115 1 Hardware_Delay_T0(10);
116 1
117 1 // Set up the LCD port
C51 COMPILER V6.10 LCD_A 04/18/2001 16:29:05 PAGE 3
118 1 LCD_D4 = 1;
119 1 LCD_D5 = 1;
120 1 LCD_D6 = 1;
121 1 LCD_D7 = 1;
122 1
123 1 LCD_RS = 1;
124 1 LCD_EN = 1;
125 1
126 1 Hardware_Delay_T0(10);
127 1
128 1 LCD_RS = 0;
129 1 LCD_EN = 0;
130 1
131 1 // Now wait for the display to initialise
132 1 // - data sheet says at least 40 ms
133 1 Hardware_Delay_T0(100);
134 1
135 1 // Data sheet says send this instruction 3 times...
136 1 for (loop = 0; loop < 3; loop++)
137 1 {
138 2 // Using a 4-bit bus, 2 display lines and a 5x7 dot font
139 2 LCD_Send_Byte(LCD_4BIT_2LINE_5x8FONT,0);
140 2 Hardware_Delay_T0(1);
141 2 }
142 1
143 1 // Turn the display off and the cursor off and blinking off
144 1 LCD_Send_Byte(LCD_DISPLAY_OFF_CURSOR_OFF_BLINKING_OFF,0);
145 1 Hardware_Delay_T0(1);
146 1
147 1 // Clear the display
148 1 LCD_Send_Byte(LCD_CLEAR_DISPLAY,0);
149 1 Hardware_Delay_T0(1);
150 1
151 1 // Invisible cursor (dummy function call to avoid library error)
152 1 LCD_Control_Cursor(0,0,0);
153 1 Hardware_Delay_T0(1);
154 1
155 1 // Clear the display
156 1 LCD_Send_Byte(LCD_CLEAR_DISPLAY,0);
157 1 Hardware_Delay_T0(1);
158 1
159 1 if (TURN_DISPLAY_ON)
160 1 {
161 2 // Increment display address for each character but do not scroll
162 2 LCD_Send_Byte(LCD_INC_ADDR_NO_SCROLL,0);
163 2 Hardware_Delay_T0(1);
164 2
165 2 // Update all characters in the display
166 2 for (l = 0; l < LCD_LINES; l++)
167 2 {
168 3 for (c = 0; c < LCD_CHARACTERS; c++)
169 3 {
170 4 LCD_data_G[l][c] = ' ';
171 4 LCD_Update();
172 4 Hardware_Delay_T0(1);
173 4 }
174 3 }
175 2
176 2 // Set up user-defined character(s) - if required
177 2 LCD_Create_Character(LCD_UDC_DEGREES_C, LCD_UDC_Degrees_C);
178 2 Hardware_Delay_T0(1);
179 2
C51 COMPILER V6.10 LCD_A 04/18/2001 16:29:05 PAGE 4
180 2 LCD_Create_Character(LCD_UDC_POUNDS, LCD_UDC_Pounds);
181 2 Hardware_Delay_T0(1);
182 2
183 2 // Turn the display on and the cursor off and blinking off
184 2 LCD_Send_Byte(LCD_DISPLAY_ON_CURSOR_OFF_BLINKING_OFF,0);
185 2 Hardware_Delay_T0(1);
186 2 }
187 1 }
188
189
190 /*------------------------------------------------------------------*-
191
192 LCD_Update()
193
194 This function updates one character in the LCD panel
195 (if it requires updating).
196
197 Duration: ~0.1 ms.
198
199 Schedule roughly every 25 ms (2-line x 20-char display) to
200 force one complete display update every second.
201
202 -*------------------------------------------------------------------*/
203 void LCD_Update(void)
204 {
205 1 static tByte Line;
206 1 static tByte Character;
207 1
208 1 tByte Tests, Data;
209 1 bit Update_required;
210 1
211 1 // Find next character to be updated
212 1 Tests = LCD_CHARACTERS * LCD_LINES;
213 1 do {
214 2 if (++Character == LCD_CHARACTERS)
215 2 {
216 3 Character = 0;
217 3
218 3 if (++Line == LCD_LINES)
219 3 {
220 4 Line = 0;
221 4 }
222 3 }
223 2
224 2 // Array contents set to \0 after data is written to LCD
225 2 Update_required = (LCD_data_G[Line][Character] != '\0');
226 2 } while ((Tests-- > 0) && (!Update_required));
227 1
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -