📄 upsd_lcd.lst
字号:
C51 COMPILER V7.20 UPSD_LCD 07/21/2004 17:06:28 PAGE 1
C51 COMPILER V7.20, COMPILATION OF MODULE UPSD_LCD
OBJECT MODULE PLACED IN upsd_LCD.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE upsd_LCD.c BROWSE DEBUG OBJECTEXTEND
line level source
1 /*------------------------------------------------------------------------
2 uPSD_LCD.c
3
4 Version:
5 June 2004, Version 1.1 - Unused functions removed.
6
7 Dependencies:
8 upsd_timer.c - needed for delays used in functions that write to the LCD.
9
10 Description:
11 The uPSD3200 LCD display driver.
12
13
14 Copyright (c) 2004 ST Microelectronics
15
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 #pragma optimize(9,size)
29
30 #include "upsd3200.h"
31 #include "upsd_hardware.h"
32 #include "upsd_timer.h"
33 #include "upsd_LCD.h"
34
35 typedef xdata struct LCD_display_st {
36 unsigned char LCD_CMD_WR; // LCD_BASE+0x00
37 unsigned char LCD_CMD_RD; // +0x01
38 unsigned char LCD_RAM_WR; // +0x02
39 unsigned char LCD_RAM_RD; // +0x03
40 } LCD_DISPLAY;
41
42 // XDATA address for display
43 xdata LCD_DISPLAY LCD_reg _at_ LCD_BASE_ADDR;
44
45 //extern code char blank[];
46
47 static unsigned char Cursor_LCD;
48
49 // These are the LCD functions.
50
51 void lcd_init(void) // initialize LCD module per specs
52 {
53 1 delay_10ms();
54 1 LCD_reg.LCD_CMD_WR = 0x30;
55 1 delay_10ms();
C51 COMPILER V7.20 UPSD_LCD 07/21/2004 17:06:28 PAGE 2
56 1 LCD_reg.LCD_CMD_WR = 0x30;
57 1 delay_10ms();
58 1 LCD_reg.LCD_CMD_WR = 0x30;
59 1 delay_10ms();
60 1
61 1 LCD_reg.LCD_CMD_WR = 0x38; // 8 bits, 2 lines, 5 x 7 font
62 1 delay_10ms(); // delay 4 ms
63 1 BusyCheck();
64 1 LCD_reg.LCD_CMD_WR = 0x0C; //Display on, Cursor off, Non-Blink
65 1 BusyCheck();
66 1 LCD_reg.LCD_CMD_WR = 0x01; //Clear display
67 1 BusyCheck();
68 1 LCD_reg.LCD_CMD_WR = 0x02; //Cursor home
69 1 BusyCheck();
70 1 LCD_reg.LCD_CMD_WR = 0x06; //Cursor inc, no shift/cursor move
71 1
72 1 Cursor_LCD = DD_ADDR; //Display from 1st row, 1st column
73 1 BusyCheck();
74 1 LCD_reg.LCD_CMD_WR = Cursor_LCD;
75 1 }
76
77
78 void BusyCheck(void) // wait until BF is cleared
79 {
80 1 while (LCD_reg.LCD_CMD_RD & BF_BIT);
81 1 }
82
83 void printfLCD(unsigned char *chr_ptr, ...) {
84 1
85 1 unsigned char *var_ptr=&chr_ptr+1;
86 1 unsigned char var;
87 1
88 1 while (*chr_ptr != NULL) {
89 2
90 2 BusyCheck();
91 2
92 2 if (*chr_ptr == '\r') {
93 3 chr_ptr++;
94 3 Cursor_LCD &= 0xC0; //return to position 0 at current line
95 3 LCD_reg.LCD_CMD_WR = Cursor_LCD;
96 3 }
97 2 else
98 2 if (*chr_ptr == '\n') {
99 3 chr_ptr++;
100 3 Cursor_LCD ^= 0x40; //goto next line
101 3 Cursor_LCD &= 0xC0; //return to position 0
102 3 LCD_reg.LCD_CMD_WR = Cursor_LCD;
103 3 }
104 2 else
105 2 if (*chr_ptr == '%') {
106 3 chr_ptr++;
107 3 if (*chr_ptr == 'd') { // display 1 digit decimal 0-9
108 4 chr_ptr++;
109 4
110 4 var = *var_ptr++;
111 4 LCD_reg.LCD_RAM_WR = (var & 0x0F)+'0';
112 4 }
113 3 else
114 3 if (*chr_ptr == 'x') { // display 1 byte hex 00-FF
115 4 chr_ptr++;
116 4
117 4 var = *var_ptr++;
C51 COMPILER V7.20 UPSD_LCD 07/21/2004 17:06:28 PAGE 3
118 4 //LCD_reg.LCD_RAM_WR = Bin2Hex(var>>4);
119 4 LCD_reg.LCD_RAM_WR = htoa_hi(var);
120 4 BusyCheck();
121 4 //LCD_reg.LCD_RAM_WR = Bin2Hex(var&0x0F);
122 4 LCD_reg.LCD_RAM_WR = htoa_lo(var);
123 4 }
124 3 else
125 3 if (*chr_ptr == 'w') { // display 1 word hex 0000-FFFF
126 4 chr_ptr++;
127 4
128 4 var = *var_ptr++;
129 4 //LCD_reg.LCD_RAM_WR = Bin2Hex(var>>4);
130 4 LCD_reg.LCD_RAM_WR = htoa_hi(var);
131 4 BusyCheck();
132 4 //LCD_reg.LCD_RAM_WR = Bin2Hex(var&0x0F);
133 4 LCD_reg.LCD_RAM_WR = htoa_lo(var);
134 4
135 4 BusyCheck();
136 4
137 4 var = *var_ptr++;
138 4 //LCD_reg.LCD_RAM_WR = Bin2Hex(var>>4);
139 4 LCD_reg.LCD_RAM_WR = htoa_hi(var);
140 4 BusyCheck();
141 4 //LCD_reg.LCD_RAM_WR = Bin2Hex(var&0x0F);
142 4 LCD_reg.LCD_RAM_WR = htoa_lo(var);
143 4 }
144 3 else {
145 4 LCD_reg.LCD_RAM_WR = *chr_ptr++; //out character to LCD Diaplay RAM
146 4 }
147 3 }
148 2 else
149 2 {
150 3 LCD_reg.LCD_RAM_WR = *chr_ptr++; //out character to LCD Diaplay RAM
151 3 }
152 2 }
153 1 }
154
155
156 // this is a collection of conversion routines used in conjunction with the LCD display
157
158
159 char htoa_lo(byte) // converts low nibble of unsigned byte
160 // (0-F hex) to ascii
161 unsigned char byte;
162 {
163 1 byte = byte & 0x0F; // keep lower nibble only
164 1 if (byte <= 0x09)
165 1 return(byte + 0x30);
166 1 else
167 1 return (byte + 0x37);
168 1 }
169
170 char htoa_hi(byte) // converts hi nibble of unsigned byte
171 // (0-F hex) to ascii
172 unsigned char byte;
173 {
174 1 byte = byte & 0xF0; // keep upper nibble only
175 1 byte = byte >> 4;
176 1 if (byte <= 0x09)
177 1 return(byte + 0x30);
178 1 else
179 1 return (byte + 0x37);
C51 COMPILER V7.20 UPSD_LCD 07/21/2004 17:06:28 PAGE 4
180 1 }
181
182
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 334 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 1 22
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -