📄 lcd_io.lst
字号:
C51 COMPILER V7.00 LCD_IO 11/13/2002 09:49:12 PAGE 1
C51 COMPILER V7.00, COMPILATION OF MODULE LCD_IO
OBJECT MODULE PLACED IN lcd_io.OBJ
COMPILER INVOKED BY: E:\KEIL\C51\BIN\C51.EXE lcd_io.c BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /*------------------------------------------------------------------------------
2 LCD_IO.C
3
4 uPSD LCD Display Device Driver Functions
5 06/2002 Ver 0.1 - Initial Version
6
7 Copyright 2002 ST Microelectronics
8 This example demo code is provided as is and has no warranty,
9 implied or otherwise. You are free to use/modify any of the provided
10 code at your own risk in your applications with the expressed limitation
11 of liability (see below) so long as your product using the code contains
12 at least one uPSD products (device).
13
14 LIMITATION OF LIABILITY: NEITHER STMicroelectronics NOR ITS VENDORS OR
15 AGENTS SHALL BE LIABLE FOR ANY LOSS OF PROFITS, LOSS OF USE, LOSS OF DATA,
16 INTERRUPTION OF BUSINESS, NOR FOR INDIRECT, SPECIAL, INCIDENTAL OR
17 CONSEQUENTIAL DAMAGES OF ANY KIND WHETHER UNDER THIS AGREEMENT OR
18 OTHERWISE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
19 ------------------------------------------------------------------------------*/
20 #include "upsd3200.h"
21 #include "upsd_hardware.h"
22 #include "lcd_io.h"
23 #include "upsd_timer.h"
24
25
26 // XDATA address for display
27 xdata LCD_DISPLAY LCD_reg _at_ LCD_BASE_ADDR;
28
29 extern code char blank[];
30
31 static unsigned char Cursor_LCD;
32
33 // These are the LCD functions.
34
35 static code unsigned char cg_data[] = {
36
37 0x1E, //db 00011110b
38 0x1C, //db 00011100b
39 0x18, //db 00011000b
40 0x11, //db 00010001b
41 0x13, //db 00010011b
42 0x1F, //db 00011111b
43 0x0F, //db 00001111b
44 0x06, //db 00000110b
45
46 0x0F, //db 00001111b
47 0x1E, //db 00011110b
48 0x1C, //db 00011100b
49 0x19, //db 00011001b
50 0x13, //db 00010011b
51 0x0F, //db 00001111b
52 0x0F, //db 00001111b
53 0x06, //db 00000110b
54
55 0x07, //db 00000111b
C51 COMPILER V7.00 LCD_IO 11/13/2002 09:49:12 PAGE 2
56 0x0F, //db 00001111b
57 0x1E, //db 00011110b
58 0x1C, //db 00011100b
59 0x18, //db 00011000b
60 0x13, //db 00010011b
61 0x03, //db 00000011b
62 0x03, //db 00000011b
63
64 0x00, //db 00000000b
65 0x01, //db 00000001b
66 0x03, //db 00000011b
67 0x07, //db 00000111b
68 0x0F, //db 00001111b
69 0x1E, //db 00011110b
70 0x1C, //db 00011100b
71 0x18, //db 00011000b
72
73 0x1E, //db 00011110b
74 0x1E, //db 00011110b
75 0x1E, //db 00011110b
76 0x10, //db 00010000b
77 0x00, //db 00000000b
78 0x00, //db 00000000b
79 0x00, //db 00000000b
80 0x00, //db 00000000b
81
82 0x1C, //db 00011100b
83 0x1C, //db 00011100b
84 0x1C, //db 00011100b
85 0x00, //db 00000000b
86 0x1C, //db 00011100b
87 0x1C, //db 00011100b
88 0x1C, //db 00011100b
89 0x1C, //db 00011100b
90
91 0x00, //db 00000000b // data for '\'
92 0x10, //db 00010000b
93 0x08, //db 00001000b
94 0x04, //db 00000100b
95 0x02, //db 00000010b
96 0x01, //db 00000001b
97 0x00, //db 00000000b
98 0x00, //db 00000000b
99
100 -1
101 };
102
103
104 void SetUserCG(unsigned char *data_ptr) // initialize user character pattern
105 {
106 1 BusyCheck();
107 1 LCD_reg.LCD_CMD_WR = CG_ADDR | (8*1); //from character code 1
108 1
109 1 while (*data_ptr != -1) {
110 2 BusyCheck();
111 2 LCD_reg.LCD_RAM_WR = *data_ptr++;
112 2 }
113 1 }
114
115 void lcd_init(void) // initialize LCD module per specs
116 {
117 1 delay_10ms();
C51 COMPILER V7.00 LCD_IO 11/13/2002 09:49:12 PAGE 3
118 1 LCD_reg.LCD_CMD_WR = 0x30;
119 1 delay_10ms();
120 1 LCD_reg.LCD_CMD_WR = 0x30;
121 1 delay_10ms();
122 1 LCD_reg.LCD_CMD_WR = 0x30;
123 1 delay_10ms();
124 1
125 1 LCD_reg.LCD_CMD_WR = 0x38; // 8 bits, 2 lines, 5 x 7 font
126 1 delay_10ms(); // delay 4 ms
127 1 BusyCheck();
128 1 LCD_reg.LCD_CMD_WR = 0x0C; //Display on, Cursor off, Non-Blink
129 1 BusyCheck();
130 1 LCD_reg.LCD_CMD_WR = 0x01; //Clear display
131 1 BusyCheck();
132 1 LCD_reg.LCD_CMD_WR = 0x02; //Cursor home
133 1 BusyCheck();
134 1 LCD_reg.LCD_CMD_WR = 0x06; //Cursor inc, no shift/cursor move
135 1
136 1 SetUserCG(&cg_data); //set user desfined character
137 1
138 1 Cursor_LCD = DD_ADDR; //Display from 1st row, 1st column
139 1 BusyCheck();
140 1 LCD_reg.LCD_CMD_WR = Cursor_LCD;
141 1 }
142
143
144 void BusyCheck(void) // wait until BF is cleared
145 {
146 1 while (LCD_reg.LCD_CMD_RD & BF_BIT);
147 1 }
148
149 /*
150 void setXY_LCD (unsigned char row, unsigned char col) {
151 Cursor_LCD = (DD_ADDR | ((row & 0x01) << 6)) + (col & LCD_LINE_LENGTH);
152 BusyCheck();
153 LCD_reg.LCD_CMD_WR = Cursor_LCD;
154 }
155 */
156
157 void putch_LCD(unsigned char ch) {
158 1 BusyCheck();
159 1 LCD_reg.LCD_RAM_WR = ch;
160 1 }
161
162
163 void printfLCD(unsigned char *chr_ptr, ...) {
164 1
165 1 unsigned char *var_ptr=&chr_ptr+1;
166 1 unsigned char var;
167 1
168 1 while (*chr_ptr != NULL) {
169 2
170 2 BusyCheck();
171 2
172 2 if (*chr_ptr == '\r') {
173 3 chr_ptr++;
174 3 Cursor_LCD &= 0xC0; //return to position 0 at current line
175 3 LCD_reg.LCD_CMD_WR = Cursor_LCD;
176 3 }
177 2 else
178 2 if (*chr_ptr == '\n') {
179 3 chr_ptr++;
C51 COMPILER V7.00 LCD_IO 11/13/2002 09:49:12 PAGE 4
180 3 Cursor_LCD ^= 0x40; //goto next line
181 3 Cursor_LCD &= 0xC0; //return to position 0
182 3 LCD_reg.LCD_CMD_WR = Cursor_LCD;
183 3 }
184 2 else
185 2 if (*chr_ptr == '%') {
186 3 chr_ptr++;
187 3 if (*chr_ptr == 'd') { // display 1 digit decimal 0-9
188 4 chr_ptr++;
189 4
190 4 var = *var_ptr++;
191 4 LCD_reg.LCD_RAM_WR = (var & 0x0F)+'0';
192 4 }
193 3 else
194 3 if (*chr_ptr == 'x') { // display 1 byte hex 00-FF
195 4 chr_ptr++;
196 4
197 4 var = *var_ptr++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -