📄 dog_glcd.lst
字号:
C51 COMPILER V8.00 DOG_GLCD 11/17/2008 10:50:29 PAGE 1
C51 COMPILER V8.00, COMPILATION OF MODULE DOG_GLCD
OBJECT MODULE PLACED IN dog_glcd.OBJ
COMPILER INVOKED BY: C:\Program Files\Keil\C51\BIN\C51.exe dog_glcd.c DB OE BR
line level source
1 /*
2 ** ============================================================================
3 **
4 ** FILE
5 ** dog_lcd.c
6 **
7 ** DESCRIPTION
8 ** Main file for controlling the DOG LCD thorugh SPI interface.
9 **
10 ** CREATED
11 ** Silicon Laboratories Hungary Ltd
12 **
13 ** COPYRIGHT
14 ** Copyright 2008 Silicon Laboratories, Inc.
15 ** http://www.silabs.com
16 **
17 ** ============================================================================
18 */
19
20 /*------------------------------------------------------------------------*/
21 /* INCLUDE */
22 /*------------------------------------------------------------------------*/
23 #include "dog_glcd.h"
24
25
26
27 /*------------------------------------------------------------------------*/
28 /* GLOBAL variables */
29 /*------------------------------------------------------------------------*/
30 extern code uint8 ascii_table5x7[][5];
31
32 idata uint8 CurrentLine, CurrentChPos, CurrentPage, CurrentColumn;
33 idata uint8 lcd_data[22];
34
35 #define LCD_BACKLIGHT_IS_USED
36
37
38 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
39 +
40 + FUNCTION NAME: void LcdDelay_2ms(void)
41 +
42 + DESCRIPTION: wait about 20ms, it uses only a for cycle
43 +
44 + RETURN: None
45 +
46 + NOTES: the delay depends on the clock of the MCU
47 +
48 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
49 void LcdDelay_2ms(void)
50 {
51 1 UU16 Delay;
52 1
53 1 Delay.U16 = 1400;
54 1 StartTmr3(DELAY_2MS_DIV, Delay, FALSE);
55 1 while( Tmr3Expired() == FALSE );
C51 COMPILER V8.00 DOG_GLCD 11/17/2008 10:50:29 PAGE 2
56 1 }
57
58 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
59 +
60 + FUNCTION NAME: void LcdInit(void)
61 +
62 + DESCRIPTION: Initialize the LCD for 3.3V operation voltage and SPI comm.
63 +
64 + RETURN: None
65 +
66 + NOTES: it can be called only 40ms later than the VDD stabilized
67 +
68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
69 void LcdInit(void)
70 {
71 1 #ifdef LCD_BACKLIGHT_IS_USED
72 1 LCD_BL_PIN = 1;
73 1 #endif
74 1 LCD_NSEL_PIN = 1;
75 1 LCD_A0_PIN = 0;
76 1 //perform reset
77 1 LCD_RESET_PIN = 0;
78 1 LcdDelay_2ms();
79 1 LCD_RESET_PIN = 1;
80 1 LcdDelay_2ms();
81 1 LcdDelay_2ms();
82 1 LcdDelay_2ms();
83 1
84 1
85 1 LCD_NSEL_PIN = 0;
86 1 SpiWrite(0x40); //display start line 0
87 1 SpiWrite(0xA1); //ADC reverse
88 1 SpiWrite(0xC0); //normal COM0~COM63
89 1 SpiWrite(0xA6); //display normal
90 1 SpiWrite(0xA2); //set bias 1/9 (Duty 1/65)
91 1 SpiWrite(0x2F); //booster, regulator and follower on
92 1 SpiWrite(0xF8); //set internal bosster to 4x
93 1 SpiWrite(0x00);
94 1 SpiWrite(0x27); //contrast set
95 1 SpiWrite(0x81);
96 1 SpiWrite(0x16);
97 1 SpiWrite(0xAC); //no indicator
98 1 SpiWrite(0x00);
99 1 LCD_NSEL_PIN = 1;
100 1 LcdOff();
101 1 LcdClearDisplay();
102 1 LcdOn();
103 1 }
104
105 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
106 +
107 + FUNCTION NAME: void LcdOn(void)
108 +
109 + DESCRIPTION: turns on the LCD screen
110 +
111 + RETURN: None
112 +
113 + NOTES:
114 +
115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
116 void LcdOn(void)
117 {
C51 COMPILER V8.00 DOG_GLCD 11/17/2008 10:50:29 PAGE 3
118 1 LCD_NSEL_PIN = 0;
119 1 SpiWrite( 0xAF );
120 1 LCD_NSEL_PIN = 1;
121 1 }
122
123 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
124 +
125 + FUNCTION NAME: void LcdOff(void)
126 +
127 + DESCRIPTION: turns off the LCD screen (the DDRAM content will be kept)
128 +
129 + RETURN: None
130 +
131 + NOTES:
132 +
133 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
134 void LcdOff(void)
135 {
136 1 LCD_NSEL_PIN = 0;
137 1 SpiWrite( 0xAE );
138 1 LCD_NSEL_PIN = 1;
139 1 }
140
141 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
142 +
143 + FUNCTION NAME: void LcdSetPage(uint8 data_in)
144 +
145 + DESCRIPTION: it sets the page address (0...7)
146 +
147 + INPUT: page address (the LCD is separated to 8x8 rows
148 + and 8 row is calles as a page)
149 + page0 is the top 8 rows
150 +
151 + RETURN: None
152 +
153 + NOTES:
154 +
155 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
156 void LcdSetPage(uint8 data_in)
157 {
158 1 LCD_NSEL_PIN = 0;
159 1 SpiWrite( 0xB0 | data_in );
160 1 LCD_NSEL_PIN = 1;
161 1 }
162
163 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
164 +
165 + FUNCTION NAME: void LcdSetColumn(uint8 data_in)
166 +
167 + DESCRIPTION: it sets the column address (0...127)
168 +
169 + INPUT: address of the column
170 +
171 + RETURN: None
172 +
173 + NOTES:
174 +
175 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
176 void LcdSetColumn(uint8 data_in)
177 {
178 1 LCD_NSEL_PIN = 0;
179 1 SpiWrite( 0x10 | ((data_in & 0x70) >> 4) );
C51 COMPILER V8.00 DOG_GLCD 11/17/2008 10:50:29 PAGE 4
180 1 SpiWrite( 0x00 | (data_in & 0x0F) );
181 1 LCD_NSEL_PIN = 1;
182 1 }
183
184 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
185 +
186 + FUNCTION NAME: void LcdClearDisplay(void)
187 +
188 + DESCRIPTION: it clears the display (the content of the DDRAM!)
189 +
190 + INPUT: None
191 +
192 + RETURN: None
193 +
194 + NOTES:
195 +
196 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
197 void LcdClearDisplay(void)
198 {
199 1 uint8 page;
200 1
201 1 for(page=1;page<9;page++)
202 1 {
203 2 LcdClearLine(page);
204 2 }
205 1 }
206
207 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
208 +
209 + FUNCTION NAME: void LcdClearLine(uint8 page)
210 +
211 + DESCRIPTION: it clears one line on the LCD
212 +
213 + INPUT: None
214 +
215 + RETURN: None
216 +
217 + NOTES:
218 +
219 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
220 void LcdClearLine(uint8 line)
221 {
222 1 uint8 column;
223 1
224 1 if( (line < LCD_MIN_LINE) || (line > LCD_MAX_LINE) )
225 1 {
226 2 return;
227 2 }
228 1 //select the page
229 1 LcdSetPage(line-1);
230 1 //set to the first column
231 1 LcdSetColumn(0);
232 1 //set A0 to 1 -> access to the DDRAM
233 1 LCD_A0_PIN = 1;
234 1 LCD_NSEL_PIN = 0;
235 1 for(column=0;column<128;column++)
236 1 {
237 2 //clear the selected column
238 2 SpiWrite(0x00);
239 2 }
240 1 LCD_A0_PIN = 0;
241 1 LCD_NSEL_PIN = 1;
C51 COMPILER V8.00 DOG_GLCD 11/17/2008 10:50:29 PAGE 5
242 1 }
243
244 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
245 +
246 + FUNCTION NAME: void LcdSetCharCursor(uint8 line, uint8 ch_pos)
247 +
248 + DESCRIPTION: it sets the character position
249 +
250 + INPUT: line - number of the line (1...8
251 + the LCD is divided to 8 lines
252 + line1 is the top line
253 + ch_pos - character position
254 + up to 21 character (1...21) could be in a line
255 + character 1 is the first on left hand side
256 +
257 + RETURN: TRUE - operation was successfull
258 + FALSE - operation was ignored
259 +
260 + NOTES: If the position is invalid, the function returns without
261 + changing the registers.
262 + The function sets the CurrentLine, CurrentChPos variables!
263 +
264 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
265 uint8 LcdSetCharCursor(uint8 line, uint8 ch_pos)
266 {
267 1 //check whether the line and ch_pos valid or not
268 1 if( ((line < LCD_MIN_LINE) || (line > LCD_MAX_LINE)) || ((ch_pos < LCD_MIN_CHAR) || (ch_pos > LCD_MAX_CHA
-R)) )
269 1 {
270 2 return FALSE;
271 2 }
272 1
273 1 //set page address
274 1 LcdSetPage(line-1);
275 1 //set column address
276 1 LcdSetColumn( ((ch_pos-1)*6) );
277 1 CurrentLine = line;
278 1 CurrentChPos = ch_pos;
279 1
280 1 return TRUE;
281 1 }
282
283
284 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
285 +
286 + FUNCTION NAME: void LcdPutInvCh(uint8 ch)
287 +
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -