📄 lcd1602.lst
字号:
C51 COMPILER V8.08 LCD1602 07/24/2008 14:03:29 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE LCD1602
OBJECT MODULE PLACED IN lcd1602.OBJ
COMPILER INVOKED BY: E:\Program Files\kiel3\C51\BIN\C51.EXE lcd1602.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include"lcd1602.h"
2 #include"delay.h"
3
4 ///////////////////////////////////////////////////////////////////////////////
5
6 void LCD_en_write(void) //液晶使能
7 {
8 1 LCD_EN_PORT=LCD_EN;
9 1 delay_nus(10);
10 1 LCD_EN_PORT=!LCD_EN;
11 1 }
12
13 ///////////////////////////////////////////////////////////////////////////////
14
15 void LCD_write_command(unsigned char command) //写指令
16 {
17 1 delay_nus(16);
18 1 LCD_RS_PORT=!LCD_RS; //RS=0
19 1 LCD_DATA_PORT&=0X0f; //清高四位
20 1 LCD_DATA_PORT|=command&0xf0; //写高四位
21 1 LCD_en_write();
22 1 delay_nus(30);
23 1 command=command<<4; //低四位移到高四位
24 1 LCD_DATA_PORT&=0x0f; //清高四位
25 1 LCD_DATA_PORT|=command&0xf0; //写低四位
26 1 LCD_en_write();
27 1 delay_nus(30);
28 1 }
29
30 ///////////////////////////////////////////////////////////////////////////////
31
32 void LCD_write_data(unsigned char Adata) //写数据
33 {
34 1 delay_nus(16);
35 1 LCD_RS_PORT=LCD_RS; //RS=1
36 1 LCD_DATA_PORT&=0X0f; //清高四位
37 1 LCD_DATA_PORT|=Adata&0xf0; //写高四位
38 1 LCD_en_write();
39 1 //delay_nus(30);
40 1 Adata=Adata<<4; //低四位移到高四位
41 1 LCD_DATA_PORT&=0X0f; //清高四位
42 1 LCD_DATA_PORT|=Adata&0xf0; //写低四位
43 1 LCD_en_write();
44 1 delay_nus(30);
45 1 }
46
47 ///////////////////////////////////////////////////////////////////////////////
48
49 void LCD_set_xy( unsigned char x, unsigned char y ) //写地址函数
50 {
51 1 unsigned char address;
52 1 if (y == 0)
53 1 address = 0x80 + x;
54 1 else
55 1 address = 0xc0 + x;
C51 COMPILER V8.08 LCD1602 07/24/2008 14:03:29 PAGE 2
56 1 LCD_write_command( address);
57 1 delay_nus(30);
58 1 }
59
60 ////////////////////////////////////////////////////////////////////////////////
61
62 void LCD_write_string(unsigned char X,unsigned char Y,unsigned char *s)
63 {
64 1 LCD_set_xy( X, Y ); //写地址
65 1 while (*s) // 写显示字符
66 1 {
67 2 LCD_write_data( *s );
68 2 s ++;
69 2 }
70 1
71 1 }
72
73 //////////////////////////////////////////////////////////////////////////////
74
75 void LCD_write_char(unsigned char X,unsigned char Y,unsigned char Adata)
76 {
77 1 LCD_set_xy( X, Y ); //写地址
78 1 delay_nus(30);
79 1 LCD_write_data(Adata);
80 1
81 1 }
82
83 ///////////////////////////////////////////////////////////////////////////////
84 void LCD_init(void) //液晶初始化
85 {
86 1 LCD_write_command(0x28);
87 1 LCD_en_write();
88 1 delay_nus(40);
89 1 LCD_write_command(0x28); //4位显示
90 1 delay_nus(3);
91 1 LCD_write_command(0x0c); //显示开
92 1 delay_nus(3);
93 1 LCD_write_command(0x01); //清屏
94 1 delay_nus(3000);
95 1 // delay_nus(3000);
96 1 }
97
98 /*------------------------------------------------
99 16进制转换为10进制
100 -------------------------------------------------*/
101
102 uchar hexotd(uchar hexdata)
103 {
104 1 return (hexdata&0x01)+ ((hexdata&0x02)>>1)*2+ ((hexdata&0x04)>>2)*4+ ((hexdata&0x08)>>3)*8+ ((hexdata
-&0x10)>>4)*16+ ((hexdata&0x20)>>5)*32;
105 1 }
106 #if 0
/*------------------------------------------------
时间的显示
-------------------------------------------------*/
void disp_time(uchar x,uchar y,uchar dat)
{
uchar disp_dat;
uchar d2,d3;
disp_dat=hexotd(dat);
if(disp_dat>=10)
C51 COMPILER V8.08 LCD1602 07/24/2008 14:03:29 PAGE 3
{
d2=disp_dat/10;
d3=disp_dat%10;
LCD_write_char((y),x,(d2+48));
LCD_write_char((y+1),x,(d3+48));
}
else
{
LCD_write_char((y),x,'0');
LCD_write_char((y+1),x,(disp_dat+48));
}
}
#endif
131
132 /*------------------------------------------------
133 数据的显示
134 ------------------------------------------------ */
135 void disp_hex(uchar x,uchar y,uchar hex)
136 {
137 1 uchar dat;
138 1 dat=disp_char((hex&0xf0)>>4);
139 1 // LCD_write_char(y,x,disp_char((hex&0xf0)>>4));
140 1 LCD_write_char(y,x,dat);
141 1 dat=disp_char(hex&0x0f);
142 1 LCD_write_char((y+1),x,dat);
143 1
144 1 }
145 /*------------------------------------------------
146 16进制显示
147 -------------------------------------------------*/
148 uchar disp_char(uchar dat)
149 {
150 1 uchar num;
151 1
152 1 switch(dat)
153 1 {
154 2 case 0x00:
155 2 num=48;
156 2 break;
157 2 case 0x01:
158 2 num=49;
159 2 break;
160 2 case 0x02:
161 2 num=50;
162 2 break;
163 2 case 0x03:
164 2 num=51;
165 2 break;
166 2 case 0x04:
167 2 num=52;
168 2 break;
169 2 case 0x05:
170 2 num=53;
171 2 break;
172 2 case 0x06:
173 2 num=54;
174 2 break;
175 2 case 0x07:
176 2 num=55;
177 2 break;
178 2 case 0x08:
C51 COMPILER V8.08 LCD1602 07/24/2008 14:03:29 PAGE 4
179 2 num=56;
180 2 break;
181 2 case 0x09:
182 2 num=57;
183 2 break;
184 2 case 0x0A:
185 2 num=65;
186 2 break;
187 2 case 0x0B:
188 2 num=66;
189 2 break;
190 2 case 0x0C:
191 2 num=67;
192 2 break;
193 2 case 0x0D:
194 2 num=68;
195 2 break;
196 2 case 0x0E:
197 2 num=69;
198 2 break;
199 2 case 0x0F:
200 2 num=70;
201 2 break;
202 2 }
203 1 return num;
204 1 }
205 /*------------------------------------------------
206 数据的显示
207 ------------------------------------------------ */
208
209 void disp_dat(uchar x,uchar y,uchar dat)
210 {
211 1 uchar disp_dat;
212 1 uchar d1,d2,d3;
213 1 disp_dat=hexotd(dat);
214 1
215 1 if(disp_dat>=100)
216 1 {
217 2 d1=disp_dat/100;
218 2 d2=(disp_dat-d1*100)/10;
219 2 d3=disp_dat%10;
220 2
221 2 LCD_write_char(y,x,(d1+48));
222 2 LCD_write_char((y+1),x,(d2+48));
223 2 LCD_write_char((y+2),x,(d3+48));
224 2 }
225 1 else
226 1 if(disp_dat>=10)
227 1 {
228 2 d2=disp_dat/10;
229 2 d3=disp_dat%10;
230 2
231 2 LCD_write_char(y,x,' ');
232 2 LCD_write_char((y+1),x,(d2+48));
233 2 LCD_write_char((y+2),x,(d3+48));
234 2 }
235 1 else
236 1 {
237 2 LCD_write_char(y,x,' ');
238 2 LCD_write_char((y+1),x,' ');
239 2 LCD_write_char((y+2),x,(disp_dat+48));
240 2 }
C51 COMPILER V8.08 LCD1602 07/24/2008 14:03:29 PAGE 5
241 1
242 1
243 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 636 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 15
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 + -