?? lcd3.lst
字號(hào):
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 //該程序?qū)崿F(xiàn)用液晶顯示器LCD顯示已定義的字符串中的某一字符
3 //程序啟發(fā):用查表法把數(shù)據(jù)送到LCD顯示
4 //作者:李錫堅(jiān)
5 //完成時(shí)間:2007.07.24.21:43
6 //*******************************************************
7 /********************************************************
8 與前兩個(gè)程序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 寫操作時(shí)用: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 //定義常用數(shù)據(jù)類型
24 int cnt;
25 void LCD_INIT(void); //LCD的初始化函數(shù)
26 void LCD_DISPLAY_STR(uchar *DATA);//在指定的位置顯示字符串
27 void LCD_CLR(uchar y); //清除LCD指定的行
28 void LCD_SEND_COMMAND(uchar COMMAND); //向LCD發(fā)送命令
29 void LCD_SEND_DATA(uchar DATA); //向LCD發(fā)送數(shù)據(jù)
30 void LCD_WAIT(void); //檢查L(zhǎng)CD空閑
31 uchar LCD_GET_FLAG(void); //檢查L(zhǎng)CD狀態(tài)
32 void DELAY(void); //延時(shí)
33 /*定義所要顯示的數(shù)據(jù)*/
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 /* 接口數(shù)據(jù)8位,顯示2行,字體為1號(hào) */
37 #define LCD_NO_FLASH 0x0C /* 屏幕顯示開,無(wú)光標(biāo) */
38 #define LCD_HIDE 0x08 /* 屏幕顯示關(guān) */
39 #define LCD_FLASH 0x0D /* 屏幕顯示開,并打開閃爍光標(biāo) */
40 #define LCD_SHIFT 0x07 /* 模塊數(shù)據(jù)輸入為增量方式,顯示內(nèi)容移動(dòng) */
41 #define LCD_NO_SHIFT 0x06 /* 模塊數(shù)據(jù)輸入為增量方式,顯示光標(biāo)移動(dòng) */
42 #define LCD_SH 0x14 /* 移動(dòng)光標(biāo)及整體顯示 */
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的實(shí)際地址*/
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; //中斷計(jì)數(shù)
51 //*************************************************
52 //LCD顯示字符串的主程序
53 //利用中斷間隔循環(huán)顯示
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 //函數(shù)功能:LCD初始化
69 //輸入變量:無(wú)
70 //輸出變量:無(wú)
71 //調(diào)用模塊:LCD_SEND_COMMAND(),LCD_CLR()
72 //*************************************************
73 void LCD_INIT(void)
74 {
75 1 LCD_SEND_COMMAND(LCD_MODE); //設(shè)置工作方式
76 1 LCD_SEND_COMMAND(LCD_NO_FLASH); //設(shè)置顯示方式
77 1 LCD_SEND_COMMAND(LCD_NO_SHIFT); //設(shè)置光標(biāo)畫面滾動(dòng)方式
78 1 LCD_SEND_COMMAND(LCD_SH); //設(shè)置輸入方式
79 1 LCD_CLR(1); //清除LCD第一行
80 1 LCD_CLR(2); //清除LCD第二行
81 1 }
82 //*************************************************
83 //函數(shù)功能:清除LCD指定行
84 //輸入變量:y
85 //輸出變量:無(wú)
86 //調(diào)用模塊: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); //發(fā)送命令使LCD指向第一行
95 2 i=16;
96 2 }
97 1 if(y==2)
98 1 {
99 2 LCD_SEND_COMMAND(LCD_LINE2); //發(fā)送命令使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的相應(yīng)位置顯示空格
107 3 }while(--i!=0);
108 2 }
109 1 }
110 //*************************************************
111 //函數(shù)功能:向LCD發(fā)送命令
112 //輸入變量:COMMAND
113 //輸出變量:無(wú)
114 //調(diào)用模塊: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;//寫實(shí)際的命令到LCD
123 1 LCD_E=0;
124 1 }
125 //*************************************************
126 //函數(shù)功能:向LCD發(fā)送數(shù)據(jù)
127 //輸入變量:DATA
128 //輸出變量:無(wú)
129 //調(diào)用模塊:LCD_WAIT()
130 //*************************************************
131 void LCD_SEND_DATA(uchar DATA)
132 {
133 1 LCD_WAIT(); //等待空閑
134 1 LCD_RS=1; //數(shù)據(jù)方式
135 1 LCD_RW=0; //寫方式
136 1 LCD_E=1;
137 1 SEND_IN=DATA;//寫實(shí)際的數(shù)據(jù)到LCD
138 1 LCD_E=0;
139 1 }
140 //*************************************************
141 //函數(shù)功能:等待LCD空閑
142 //輸入變量:無(wú)
143 //輸出變量:無(wú)
144 //調(diào)用模塊:LCD_GET_FLAG()
145 //*************************************************
146 void LCD_WAIT(void)
147 {
148 1 uchar i;
149 1 i=1000; //定義等待時(shí)間,可以防止由于LCD損壞而使程序死循環(huán)
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 //函數(shù)功能:檢查L(zhǎng)CD狀態(tài)
161 //輸入變量:無(wú)
162 //輸出變量:LCD顯示的當(dāng)前狀態(tài)
163 //調(diào)用模塊:無(wú)
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 //函數(shù)功能:檢查L(zhǎng)CD狀態(tài)
177 //輸入變量:無(wú)
178 //輸出變量:LCD顯示的當(dāng)前狀態(tài)
179 //調(diào)用模塊:無(wú)
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);//發(fā)送顯示位置命令
190 2 //for(;x<(17)&&*DATA!='\0';x++)
191 2 //for(;x<(17)&&i<8;x++)
192 2 //{
194 2 // }
195 2 /* if(*DATA!='\0') //判斷是否發(fā)送完畢
196 2 {
197 2 x=1;
198 2 y=2; //未完畢轉(zhuǎn)到第二行顯示
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') //判斷是否發(fā)送完畢
211 2 {
212 2 x=1;
213 2 y=1; //未完畢轉(zhuǎn)到第一行顯示
214 2 }
215 2 DELAY();
216 2 }
217 2 }while(*DATA!='\0'); */
218 2 }
219 1 }
220 //*************************************************
221 //函數(shù)功能:延時(shí)3秒
222 //輸入變量:無(wú)
223 //輸出變量:無(wú)
224 //調(diào)用模塊:無(wú)
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); //延時(shí)2秒
235 1 TR0=0;
236 1 ET0=0;
237 1 EA=0;
238 1 t=0;
239 1 }
240 //*****************************************
241 //
242 //定時(shí)器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)
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -