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