📄 lcd_io.lst
字号:
C51 COMPILER V7.00 Beta 6 LCD_IO 02/19/2003 15:59:28 PAGE 1
C51 COMPILER V7.00 Beta 6, COMPILATION OF MODULE LCD_IO
OBJECT MODULE PLACED IN lcd_io.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE lcd_io.c LARGE BROWSE DEBUG OBJECTEXTEND
stmt level source
1 // A collection of I/O functions for WSi eval boards which include
2 // LED's, LCD, UART.
3 // Mark Rootz 3/30/98 */
4 // debugged for eval boards T. Wilkerson 7-9/98
5 //
6 // Modified by William Chin for uPSD3234 from ST Microelectronics
7 // on June 14, 2002
8 // collection of LCD functions only
9 //
10 // Revision History
11 //
12 // 7/22/02 (JAM) - Added LCD buffer for mirroring LCD data to PC app.
13
14 /*---------------------------------------------------------------------------
15 Copyright (c) 2002 ST Microelectronics
16 This example demo code is provided as is and has no warranty,
17 implied or otherwise. You are free to use/modify any of the provided
18 code at your own risk in your applications with the expressed limitation
19 of liability (see below) so long as your product using the code contains
20 at least one uPSD products (device).
21
22 LIMITATION OF LIABILITY: NEITHER STMicroelectronics NOR ITS VENDORS OR
23 AGENTS SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
24 INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
25 CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
26 OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
27 --------------------------------------------------------------------------*/
28
29 //-- Includes ----------------------------------------------------------------
30
31 #include "general.h"
32 #include "upsd3200.h"
33 #include "upsd_xreg.h"
34
35 #include "lcd_io.h"
36 #include "timer_func.h"
37 #include "app_intr.h"
38
39 //-- Variables ---------------------------------------------------------------
40
41 extern DISPLAY LCD_reg;
42
43 static idata uchar Cursor_LCD;
44
45 // User design CG data
46 static uchar code cg_data[] = {
47
48 0x1F, //14%
49 0x11,
50 0x11,
51 0x11,
52 0x11,
53 0x11,
54 0x11,
55 0x1F,
C51 COMPILER V7.00 Beta 6 LCD_IO 02/19/2003 15:59:28 PAGE 2
56
57 0x1F, //28%
58 0x11,
59 0x11,
60 0x11,
61 0x11,
62 0x11,
63 0x1F,
64 0x1F,
65
66 0x1F, //43%
67 0x11,
68 0x11,
69 0x11,
70 0x11,
71 0x1F,
72 0x1F,
73 0x1F,
74
75 0x1F, //57%
76 0x11,
77 0x11,
78 0x11,
79 0x1F,
80 0x1F,
81 0x1F,
82 0x1F,
83
84 0x1F, //71%
85 0x11,
86 0x11,
87 0x1F,
88 0x1F,
89 0x1F,
90 0x1F,
91 0x1F,
92
93 0x1F, //86%
94 0x11,
95 0x1F,
96 0x1F,
97 0x1F,
98 0x1F,
99 0x1F,
100 0x1F,
101
102 0x1F, //100%
103 0x1F,
104 0x1F,
105 0x1F,
106 0x1F,
107 0x1F,
108 0x1F,
109 0x1F,
110
111 -1
112 };
113
114 char LCD_buffer[LCD_BUFFER_SIZE + 1]; // LCD mirror buffer
115 static char LCD_index; // Cursor pos in LCD_buffer
116
117 //-- Prototypes----------------------------------------------------------------
C51 COMPILER V7.00 Beta 6 LCD_IO 02/19/2003 15:59:28 PAGE 3
118
119 static void SetUserCG(uchar *); // initialize user character pattern
120 static void BusyCheck(void); // wait until BF is cleared
121 static char htoa_lo(uchar); // converts low nibble of unsigned byte
122 static char htoa_hi(uchar); // converts hi nibble of unsigned byte
123
124
125 //-- Functions ----------------------------------------------------------------
126
127 void initLCD(void) // initialize LCD module per specs
128 {
129 1 int i;
130 1
131 1 delay_ms(15);
132 1 LCD_reg.LCD_CMD_WR = 0x30;
133 1 delay_ms(4);
134 1 LCD_reg.LCD_CMD_WR = 0x30;
135 1 delay_ms(1);
136 1 LCD_reg.LCD_CMD_WR = 0x30;
137 1 delay_ms(1);
138 1
139 1 LCD_reg.LCD_CMD_WR = 0x38; // 8 bits, 2 lines, 5 x 7 font
140 1 delay_ms(4); // delay 4 ms
141 1 BusyCheck();
142 1 LCD_reg.LCD_CMD_WR = 0x0C; //Display on, Cursor off, Non-Blink
143 1 BusyCheck();
144 1 LCD_reg.LCD_CMD_WR = 0x01; //Clear display
145 1 BusyCheck();
146 1 LCD_reg.LCD_CMD_WR = 0x02; //Cursor home
147 1 BusyCheck();
148 1 LCD_reg.LCD_CMD_WR = 0x06; //Cursor inc, no shift/cursor move
149 1
150 1 SetUserCG(&cg_data); //set user desfined character
151 1
152 1 Cursor_LCD = DD_ADDR; //Display from 1st row, 1st column
153 1 BusyCheck();
154 1 LCD_reg.LCD_CMD_WR = Cursor_LCD;
155 1
156 1 // Initialize mirror buffer
157 1
158 1 for (i = 0; i < LCD_BUFFER_SIZE; i++)
159 1 {
160 2 LCD_buffer[i] = ' ';
161 2 }
162 1
163 1 LCD_buffer[LCD_BUFFER_SIZE] = 0;
164 1 LCD_index = 0;
165 1 }
166
167
168 static void SetUserCG(uchar *data_ptr) // initialize user character pattern
169 {
170 1 BusyCheck();
171 1 LCD_reg.LCD_CMD_WR = CG_ADDR | (8*1); //from character code 1
172 1
173 1 while (*data_ptr != -1) {
174 2 BusyCheck();
175 2 LCD_reg.LCD_RAM_WR = *data_ptr++;
176 2 }
177 1 }
178
179 static void BusyCheck(void) // wait until BF is cleared
C51 COMPILER V7.00 Beta 6 LCD_IO 02/19/2003 15:59:28 PAGE 4
180 {
181 1 while (LCD_reg.LCD_CMD_RD & BF_BIT);
182 1 }
183
184 /*
185 void setXY_LCD (uchar row, uchar col) {
186 Cursor_LCD = (DD_ADDR | ((row & 0x01) << 6)) + (col & LCD_LINE_LENGTH);
187 BusyCheck();
188 LCD_reg.LCD_CMD_WR = Cursor_LCD;
189 }
190
191 void putch_LCD(uchar ch) {
192 BusyCheck();
193 LCD_reg.LCD_RAM_WR = ch;
194 }
195 */
196
197 void printfLCD(uchar *chr_ptr, ...)
198 {
199 1 uchar *var_ptr=&chr_ptr+1;
200 1 uchar var;
201 1
202 1 while (*chr_ptr != NULL)
203 1 {
204 2 BusyCheck();
205 2
206 2 if (*chr_ptr == '\r')
207 2 {
208 3 // Return to position 0 at current line
209 3 chr_ptr++;
210 3 Cursor_LCD &= 0xC0;
211 3 LCD_reg.LCD_CMD_WR = Cursor_LCD;
212 3 LCD_index -= LCD_index % LCD_LINE_SIZE;
213 3 }
214 2 else if (*chr_ptr == '\n')
215 2 {
216 3 chr_ptr++;
217 3 Cursor_LCD ^= 0x40; //goto next line
218 3 Cursor_LCD &= 0xC0; //return to position 0
219 3 LCD_reg.LCD_CMD_WR = Cursor_LCD;
220 3 if (LCD_index < (LCD_BUFFER_SIZE - LCD_LINE_SIZE))
221 3 {
222 4 LCD_index += LCD_LINE_SIZE;
223 4 }
224 3 }
225 2 else if (*chr_ptr == '%')
226 2 {
227 3 chr_ptr++;
228 3 if (*chr_ptr == 'd')
229 3 {
230 4 // Display 1 digit decimal 0-9
231 4 chr_ptr++;
232 4 var = *var_ptr++;
233 4 LCD_reg.LCD_RAM_WR = LCD_buffer[LCD_index++] = (var & 0x0F)+'0';
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -