📄 51
字号:
C51 COMPILER V8.09 YIDONG 07/12/2010 14:32:27 PAGE 1
C51 COMPILER V8.09, COMPILATION OF MODULE YIDONG
OBJECT MODULE PLACED IN yidong.OBJ
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE yidong.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include <reg52.h>
2 #include <intrins.h>
3
4 #define uchar unsigned char
5 #define uint unsigned int
6
7 sbit LCD_RS = P2^7;
8 sbit LCD_RW = P2^6;
9 sbit LCD_EN = P2^5;
10
11 uchar code dis1[] = {" CHINESE "};
12 uchar code dis2[] = {" NEW YEAR "};
13
14
15 /*******************************************************************/
16 /*
- */
17 /* 延时子程序
- */
18 /*
- */
19 /*******************************************************************/
20
21 void delay(int ms)
22 {
23 1 int i;
24 1 while(ms--)
25 1 {
26 2 for(i = 0; i< 250; i++)
27 2 {
28 3 _nop_();
29 3 _nop_();
30 3 _nop_();
31 3 _nop_();
32 3 }
33 2 }
34 1 }
35
36 /*******************************************************************/
37 /*
- */
38 /*检查LCD忙状态
- */
39 /*lcd_busy为1时,忙,等待。lcd-busy为0时,闲,可写指令与数据。 */
40 /*
- */
41 /*******************************************************************/
42
43 bit lcd_busy()
44 {
45 1 bit result;
46 1 LCD_RS = 0;
47 1 LCD_RW = 1;
48 1 LCD_EN = 1;
49 1 _nop_();
C51 COMPILER V8.09 YIDONG 07/12/2010 14:32:27 PAGE 2
50 1 _nop_();
51 1 _nop_();
52 1 _nop_();
53 1 result = (bit)(P0&0x80);
54 1 LCD_EN = 0;
55 1 return result;
56 1 }
57
58 /*******************************************************************/
59 /*
- */
60 /*写指令数据到LCD
- */
61 /*RS=L,RW=L,E=高脉冲,D0-D7=指令码。 *
-/
62 /*
- */
63 /*******************************************************************/
64
65 void lcd_wcmd(uchar cmd)
66 {
67 1 while(lcd_busy());
68 1 LCD_RS = 0;
69 1 LCD_RW = 0;
70 1 LCD_EN = 0;
71 1 _nop_();
72 1 _nop_();
73 1 P0 = cmd;
74 1 _nop_();
75 1 _nop_();
76 1 _nop_();
77 1 _nop_();
78 1 LCD_EN = 1;
79 1 _nop_();
80 1 _nop_();
81 1 _nop_();
82 1 _nop_();
83 1 LCD_EN = 0;
84 1 }
85
86 /*******************************************************************/
87 /*
- */
88 /*写显示数据到LCD
- */
89 /*RS=H,RW=L,E=高脉冲,D0-D7=数据。 *
-/
90 /*
- */
91 /*******************************************************************/
92
93 void lcd_wdat(uchar dat)
94 {
95 1 while(lcd_busy());
96 1 LCD_RS = 1;
97 1 LCD_RW = 0;
98 1 LCD_EN = 0;
99 1 P0 = dat;
100 1 _nop_();
101 1 _nop_();
102 1 _nop_();
103 1 _nop_();
C51 COMPILER V8.09 YIDONG 07/12/2010 14:32:27 PAGE 3
104 1 LCD_EN = 1;
105 1 _nop_();
106 1 _nop_();
107 1 _nop_();
108 1 _nop_();
109 1 LCD_EN = 0;
110 1 }
111
112 /*******************************************************************/
113 /*
- */
114 /* 设定显示位置
- */
115 /*
- */
116 /*******************************************************************/
117
118 void lcd_pos(uchar pos)
119 {
120 1 lcd_wcmd(pos|0x80); //数据指针=80+地址变量
121 1 }
122
123 /*******************************************************************/
124 /*
- */
125 /* LCD初始化设定
- */
126 /*
- */
127 /*******************************************************************/
128
129 void lcd_init()
130 {
131 1 delay(15); //等待LCD电源稳定
132 1 lcd_wcmd(0x38); //16*2显示,5*7点阵,8位数据
133 1 delay(5);
134 1 lcd_wcmd(0x38);
135 1 delay(5);
136 1 lcd_wcmd(0x38);
137 1 delay(5);
138 1
139 1 lcd_wcmd(0x0c); //显示开,关光标
140 1 delay(5);
141 1 lcd_wcmd(0x06); //移动光标
142 1 delay(5);
143 1 lcd_wcmd(0x01); //清除LCD的显示内容
144 1 delay(5);
145 1 }
146
147 /*******************************************************************/
148 /*
- */
149 /* 清屏子程序
- */
150 /*
- */
151 /*******************************************************************/
152
153 void lcd_clr()
154 {
155 1 lcd_wcmd(0x01); //清除LCD的显示内容
156 1 delay(5);
C51 COMPILER V8.09 YIDONG 07/12/2010 14:32:27 PAGE 4
157 1 }
158
159 /*******************************************************************/
160 /*
- */
161 /* 闪动子程序
- */
162 /*
- */
163 /*******************************************************************/
164
165 void flash()
166 {
167 1 delay(600); //控制停留时间
168 1 lcd_wcmd(0x08); //关闭显示
169 1 delay(200); //延时
170 1 lcd_wcmd(0x0c); //开显示
171 1 delay(200);
172 1 lcd_wcmd(0x08); //关闭显示
173 1 delay(200); //延时
174 1 lcd_wcmd(0x0c); //开显示
175 1 delay(200);
176 1 }
177
178 /*******************************************************************/
179 /*
- */
180 /* 主程序
- */
181 /*
- */
182 /*******************************************************************/
183
184 main()
185 {
186 1 uchar i,j;
187 1 delay(10);
188 1 lcd_init(); //初始化LCD
189 1
190 1 while(1)
191 1 {
192 2 lcd_clr();
193 2
194 2 lcd_pos(0x10); //设置显示位置为第一行第17列
195 2 i = 0;
196 2
197 2 while(dis1[i] != '\0')
198 2 { //显示字符" CHINESE "
199 3 lcd_wdat(dis1[i]);
200 3 i++;
201 3 }
202 2
203 2 lcd_pos(0x50); //设置显示位置为第二行第17列
204 2 i = 0;
205 2
206 2 while(dis2[i] != '\0')
207 2 {
208 3 lcd_wdat(dis2[i]); //显示字符" NEW YEAR "
209 3 i++;
210 3 }
211 2
212 2 /*for(j=0;j<16;j++) //左移动16格
C51 COMPILER V8.09 YIDONG 07/12/2010 14:32:27 PAGE 5
213 2 {
214 2 lcd_wcmd(0x18); //字符同时左移一格
215 2 delay(100); //控制移动时间
216 2 }
217 2
218 2 flash(); */ //闪动二次
219 2
220 2 for(j=0;j<29;j++) //向左移动29格
221 2 {
222 3 lcd_wcmd(0x18) ; //字符同时左移一格
223 3 delay(100) ; //控制移动时间
224 3 }
225 2
226 2 for(j=0;j<13;j++) //向右移动13格
227 2 {
228 3 lcd_wcmd(0x1C) ; //字符同时左移一格
229 3 delay(100) ; //控制移动时间
230 3 }
231 2 flash() ; //闪动二次
232 2
233 2
234 2 }
235 1
236 1
237 1
238 1
239 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 334 ----
CONSTANT SIZE = 34 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -