lcd3.lst
来自「这是一段开始学单片机时写的LCD程序」· LST 代码 · 共 294 行
LST
294 行
C51 COMPILER V7.50 LCD3 12/27/2007 23:17:22 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE LCD3
OBJECT MODULE PLACED IN LCD3.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE LCD3.C BROWSE DEBUG OBJECTEXTEND
line level source
1 //*******************************************************
2 //该程序实现用液晶显示器LCD显示已定义的字符串中的某一字符
3 //程序启发:用查表法把数据送到LCD显示
4 //作者:李锡坚
5 //完成时间:2007.07.24.21:43
6 //*******************************************************
7 /********************************************************
8 与前两个程序LCD1.C,LCD2.C的不同处:
9 sbit LCD_RS=P3^4; //定义LCD的RS控制位
10 sbit LCD_RW=P3^5; //定义LCD的RW控制位
11 sbit LCD_DISPLAY_START=P1^0; //LCD开始显示的指示灯
12 sbit LCD_E=P1^1; //定义LCD的E控制位
13 写操作时用:LCD_E=1;
14 _nop_();
15 LCD_E=0;
16 代替
17 *********************************************************/
18 //****************************************
19 #include<reg52.h> //包含常用头文件
20 #include<stdio.h>
21 #include<intrins.h>
22 #include<absacc.h>
23 #define uchar unsigned char //定义常用数据类型
24 int cnt;
25 void LCD_INIT(void); //LCD的初始化函数
26 void LCD_DISPLAY_STR(uchar *DATA);//在指定的位置显示字符串
27 void LCD_CLR(uchar y); //清除LCD指定的行
28 void LCD_SEND_COMMAND(uchar COMMAND); //向LCD发送命令
29 void LCD_SEND_DATA(uchar DATA); //向LCD发送数据
30 void LCD_WAIT(void); //检查LCD空闲
31 uchar LCD_GET_FLAG(void); //检查LCD状态
32 void DELAY(void); //延时
33 /*定义所要显示的数据*/
34 char code DISPLAY[]="asdf ghjk";//{1,2,3,0x1f,0x04,0x1f,0x04,0x04};//"It goes without saying that this pic
-ture aims at revealing a current problem: what kind of attitude we will choose when facing difficulties and challenges.
-In this drawing, a football-player is prepared to kick a ball towards the net, where a goal-keeper keeps guard. However,
- in the player’s mind appears a scene in which the keeper becomes a giant covering the net completely, while the latter
- imagines that he turns out to be a dwarf standing below the huge net. Obviously, both of them lack courage and confiden
-ce in front of challenges.These two players represent those who often choose to magnify their enemies and dangers, and l
-ose their confidence to fight against them. As a result, what they can achieve in the end is nothing but failure. This s
-ad situation can be best illustrated in the fact that some people lose their chance of success in the entrance examinati
-on for the MA program. When preparing for the exam, they often feel depressed thinking that they are never well-prepared
-. In fact, they will soon realize that it is not as difficult as they thought before. In a word, they suffer from undere
-stimating their abilities.In our life, what we need most is self-insurance and a proper view of challenges before us. Th
-erefore, we should bear in mind that our competitors may not be as terrible as expected, and our painstaking efforts wil
-l pay off as long as we arm ourselves with courage and confidence. Only in this way can we overcome any difficulties and
- challenges.";
35 /*定义LCD控制字*/
36 #define LCD_MODE 0x3C /* 接口数据8位,显示2行,字体为1号 */
37 #define LCD_NO_FLASH 0x0C /* 屏幕显示开,无光标 */
38 #define LCD_HIDE 0x08 /* 屏幕显示关 */
39 #define LCD_FLASH 0x0D /* 屏幕显示开,并打开闪烁光标 */
40 #define LCD_SHIFT 0x07 /* 模块数据输入为增量方式,显示内容移动 */
41 #define LCD_NO_SHIFT 0x06 /* 模块数据输入为增量方式,显示光标移动 */
42 #define LCD_SH 0x14 /* 移动光标及整体显示 */
C51 COMPILER V7.50 LCD3 12/27/2007 23:17:22 PAGE 2
43 #define LCD_LINE1 0x80 /*第一行DDRAM起始地址*/
44 #define LCD_LINE2 0xc0 /*第二行DDRAM起始地址*/
45 #define SEND_IN P0 /*XBYTE[0xff00] /*定义LCD的实际地址*/
46 sbit LCD_RS=P3^6; //定义LCD的RS控制位
47 sbit LCD_RW=P3^7; //定义LCD的RW控制位
48 sbit LCD_DISPLAY_START=P1^0; //LCD开始显示的指示灯
49 sbit LCD_E=P1^4; //定义LCD的E控制位
50 int t=0; //中断计数
51 //*************************************************
52 //LCD显示字符串的主程序
53 //利用中断间隔循环显示
54 //
55 //*************************************************
56 main()
57 {
58 1 LCD_INIT(); //初始化LCD
59 1 do
60 1 {
61 2 LCD_DISPLAY_START=0; //开LCD显示的指示灯
62 2 DELAY();
63 2 LCD_DISPLAY_START=1; //灭LCD显示的指示灯
64 2 LCD_DISPLAY_STR(DISPLAY); //显示字符串
65 2 }while(1);
66 1 }
67 //*************************************************
68 //函数功能:LCD初始化
69 //输入变量:无
70 //输出变量:无
71 //调用模块:LCD_SEND_COMMAND(),LCD_CLR()
72 //*************************************************
73 void LCD_INIT(void)
74 {
75 1 LCD_SEND_COMMAND(LCD_MODE); //设置工作方式
76 1 LCD_SEND_COMMAND(LCD_NO_FLASH); //设置显示方式
77 1 LCD_SEND_COMMAND(LCD_NO_SHIFT); //设置光标画面滚动方式
78 1 LCD_SEND_COMMAND(LCD_SH); //设置输入方式
79 1 LCD_CLR(1); //清除LCD第一行
80 1 LCD_CLR(2); //清除LCD第二行
81 1 }
82 //*************************************************
83 //函数功能:清除LCD指定行
84 //输入变量:y
85 //输出变量:无
86 //调用模块:LCD_SEND_COMMAND(),LCD_SEND_DATA()
87 //*************************************************
88 void LCD_CLR(uchar y)
89 {
90 1 uchar i;
91 1 i=0;
92 1 if(y==1)
93 1 {
94 2 LCD_SEND_COMMAND(LCD_LINE1); //发送命令使LCD指向第一行
95 2 i=16;
96 2 }
97 1 if(y==2)
98 1 {
99 2 LCD_SEND_COMMAND(LCD_LINE2); //发送命令使LCD指向第二行
100 2 i=16;
101 2 }
102 1 if(i!=0)
103 1 {
104 2 do
C51 COMPILER V7.50 LCD3 12/27/2007 23:17:22 PAGE 3
105 2 {
106 3 LCD_SEND_DATA(' '); //让LCD的相应位置显示空格
107 3 }while(--i!=0);
108 2 }
109 1 }
110 //*************************************************
111 //函数功能:向LCD发送命令
112 //输入变量:COMMAND
113 //输出变量:无
114 //调用模块:LCD_WAIT()
115 //*************************************************
116 void LCD_SEND_COMMAND(uchar COMMAND)
117 {
118 1 LCD_WAIT(); //等待空闲
119 1 LCD_RS=0; //命令方式
120 1 LCD_RW=0; //写方式
121 1 LCD_E=1;
122 1 SEND_IN=COMMAND;//写实际的命令到LCD
123 1 LCD_E=0;
124 1 }
125 //*************************************************
126 //函数功能:向LCD发送数据
127 //输入变量:DATA
128 //输出变量:无
129 //调用模块:LCD_WAIT()
130 //*************************************************
131 void LCD_SEND_DATA(uchar DATA)
132 {
133 1 LCD_WAIT(); //等待空闲
134 1 LCD_RS=1; //数据方式
135 1 LCD_RW=0; //写方式
136 1 LCD_E=1;
137 1 SEND_IN=DATA;//写实际的数据到LCD
138 1 LCD_E=0;
139 1 }
140 //*************************************************
141 //函数功能:等待LCD空闲
142 //输入变量:无
143 //输出变量:无
144 //调用模块:LCD_GET_FLAG()
145 //*************************************************
146 void LCD_WAIT(void)
147 {
148 1 uchar i;
149 1 i=1000; //定义等待时间,可以防止由于LCD损坏而使程序死循环
150 1 do
151 1 {
152 2 if((LCD_GET_FLAG()&0x80)==0) //判断BF是否为0
153 2 {
154 3 break;
155 3 }
156 2 }while(--i!=0);
157 1
158 1 }
159 //*************************************************
160 //函数功能:检查LCD状态
161 //输入变量:无
162 //输出变量:LCD显示的当前状态
163 //调用模块:无
164 //*************************************************
165 uchar LCD_GET_FLAG(void)
166 {
C51 COMPILER V7.50 LCD3 12/27/2007 23:17:22 PAGE 4
167 1 SEND_IN=0xff;
168 1 LCD_RS=0;
169 1 LCD_RW=1;
170 1 LCD_E=1;
171 1 _nop_();
172 1 _nop_();
173 1 return(SEND_IN);
174 1 }
175 //*************************************************
176 //函数功能:检查LCD状态
177 //输入变量:无
178 //输出变量:LCD显示的当前状态
179 //调用模块:无
180 //*************************************************
181 void LCD_DISPLAY_STR(uchar *DATA)
182 {
183 1 int x=1,y=1,i=0;
184 1 // do
185 1 // {
186 1 if(y==1)
187 1 {
188 2 LCD_CLR(1);
189 2 LCD_SEND_COMMAND(LCD_LINE1);//发送显示位置命令
190 2 //for(;x<(17)&&*DATA!='\0';x++)
191 2 //for(;x<(17)&&i<8;x++)
192 2 //{
193 2 LCD_SEND_DATA(DATA[7]); //发送数据
194 2 // }
195 2 /* if(*DATA!='\0') //判断是否发送完毕
196 2 {
197 2 x=1;
198 2 y=2; //未完毕转到第二行显示
199 2 } */
200 2 DELAY();
201 2 /* }
202 2 if(y==2)
203 2 {
204 2 LCD_CLR(2);
205 2 LCD_SEND_COMMAND(LCD_LINE2);
206 2 for(;x<(17)&&*DATA!='\0';x++)
207 2 {
208 2 LCD_SEND_DATA(DATA[i++]);
209 2 }
210 2 if(*DATA!='\0') //判断是否发送完毕
211 2 {
212 2 x=1;
213 2 y=1; //未完毕转到第一行显示
214 2 }
215 2 DELAY();
216 2 }
217 2 }while(*DATA!='\0'); */
218 2 }
219 1 }
220 //*************************************************
221 //函数功能:延时3秒
222 //输入变量:无
223 //输出变量:无
224 //调用模块:无
225 //*************************************************
226 void DELAY(void)
227 {
228 1 TMOD=0x02;
C51 COMPILER V7.50 LCD3 12/27/2007 23:17:22 PAGE 5
229 1 TH0=0x06;
230 1 TL0=0x06;
231 1 TR0=1;
232 1 ET0=1;
233 1 EA=1;
234 1 while(t!=8000); //延时2秒
235 1 TR0=0;
236 1 ET0=0;
237 1 EA=0;
238 1 t=0;
239 1 }
240 //*****************************************
241 //
242 //定时器0的溢出中断程序
243 //
244 //*****************************************
245 void timer0(void) interrupt 1 using 0
246 {
247 1 t++;
248 1
249 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 259 ----
CONSTANT SIZE = 10 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 4 12
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?