?? lcd2.lst
字號:
C51 COMPILER V7.50 LCD2 07/24/2007 16:45:13 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE LCD2
OBJECT MODULE PLACED IN LCD2.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE LCD2.C BROWSE DEBUG OBJECTEXTEND
line level source
1 //****************************************
2 //該程序實現用液晶顯示器LCD顯示一篇英語作文
3 //作者:李錫堅
4 //完成時間:2007.07.24.16:43
5 //****************************************
6 #include<reg51.h> //包含常用頭文件
7 #include<stdio.h>
8 #include<intrins.h>
9 #include<absacc.h>
10 #define uchar unsigned char //定義常用數據類型
11 int cnt;
12 void LCD_INIT(void); //LCD的初始化函數
13 void LCD_DISPLAY_STR(char *DATA);//在指定的位置顯示字符串
14 void LCD_CLR(uchar y); //清除LCD指定的行
15 void LCD_SEND_COMMAND(uchar COMMAND); //向LCD發送命令
16 void LCD_SEND_DATA(uchar DATA); //向LCD發送數據
17 void LCD_WAIT(void); //檢查LCD空閑
18 uchar LCD_GET_FLAG(void); //檢查LCD狀態
19 void DELAY(void); //延時
20 /*定義所要顯示的數據*/
21 char code DISPLAY[]="It goes without saying that this picture aims at revealing a current problem: what ki
-nd 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 t
-he keeper becomes a giant covering the net completely, while the latter imagines that he turns out to be a dwarf standin
-g below the huge net. Obviously, both of them lack courage and confidence in front of challenges.These two players repre
-sent those who often choose to magnify their enemies and dangers, and lose their confidence to fight against them. As a
-result, what they can achieve in the end is nothing but failure. This sad situation can be best illustrated in the fact
-that some people lose their chance of success in the entrance examination for the MA program. When preparing for the exa
-m, 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 underestimating their abilities.In our life, what we ne
-ed most is self-insurance and a proper view of challenges before us. Therefore, we should bear in mind that our competit
-ors may not be as terrible as expected, and our painstaking efforts will pay off as long as we arm ourselves with courag
-e and confidence. Only in this way can we overcome any difficulties and challenges.";
22 /*定義LCD控制字*/
23 #define LCD_MODE 0x3C /* 接口數據8位,顯示2行,字體為1號 */
24 #define LCD_NO_FLASH 0x0C /* 屏幕顯示開,無光標 */
25 #define LCD_HIDE 0x08 /* 屏幕顯示關 */
26 #define LCD_FLASH 0x0D /* 屏幕顯示開,并打開閃爍光標 */
27 #define LCD_SHIFT 0x07 /* 模塊數據輸入為增量方式,顯示內容移動 */
28 #define LCD_NO_SHIFT 0x06 /* 模塊數據輸入為增量方式,顯示光標移動 */
29 #define LCD_SH 0x14 /* 移動光標及整體顯示 */
30 #define LCD_LINE1 0x80 /*第一行DDRAM起始地址*/
31 #define LCD_LINE2 0xc0 /*第二行DDRAM起始地址*/
32 #define SEND_IN XBYTE[0xff00] /*定義LCD的實際地址*/
33 sbit LCD_RS=P3^4; //定義LCD的RS控制位
34 sbit LCD_RW=P3^5; //定義LCD的RW控制位
35 sbit LCD_DISPLAY_START=P1^0; //LCD開始顯示的指示燈
36 int t=0; //中斷計數
37 //*************************************************
38 //LCD顯示字符串的主程序
39 //利用中斷間隔循環顯示
40 //
41 //*************************************************
42 main()
43 {
C51 COMPILER V7.50 LCD2 07/24/2007 16:45:13 PAGE 2
44 1 LCD_INIT(); //初始化LCD
45 1 do
46 1 {
47 2 LCD_DISPLAY_START=0; //開LCD顯示的指示燈
48 2 DELAY();
49 2 LCD_DISPLAY_START=1; //滅LCD顯示的指示燈
50 2 LCD_DISPLAY_STR(DISPLAY); //顯示字符串
51 2 }while(1);
52 1 }
53 //*************************************************
54 //函數功能:LCD初始化
55 //輸入變量:無
56 //輸出變量:無
57 //調用模塊:LCD_SEND_COMMAND(),LCD_CLR()
58 //*************************************************
59 void LCD_INIT(void)
60 {
61 1 LCD_SEND_COMMAND(LCD_MODE); //設置工作方式
62 1 LCD_SEND_COMMAND(LCD_NO_FLASH); //設置顯示方式
63 1 LCD_SEND_COMMAND(LCD_NO_SHIFT); //設置光標畫面滾動方式
64 1 LCD_SEND_COMMAND(LCD_SH); //設置輸入方式
65 1 LCD_CLR(1); //清除LCD第一行
66 1 LCD_CLR(2); //清除LCD第二行
67 1 }
68 //*************************************************
69 //函數功能:清除LCD指定行
70 //輸入變量:y
71 //輸出變量:無
72 //調用模塊:LCD_SEND_COMMAND(),LCD_SEND_DATA()
73 //*************************************************
74 void LCD_CLR(uchar y)
75 {
76 1 uchar i;
77 1 i=0;
78 1 if(y==1)
79 1 {
80 2 LCD_SEND_COMMAND(LCD_LINE1); //發送命令使LCD指向第一行
81 2 i=16;
82 2 }
83 1 if(y==2)
84 1 {
85 2 LCD_SEND_COMMAND(LCD_LINE2); //發送命令使LCD指向第二行
86 2 i=16;
87 2 }
88 1 if(i!=0)
89 1 {
90 2 do
91 2 {
92 3 LCD_SEND_DATA(' '); //讓LCD的相應位置顯示空格
93 3 }while(--i!=0);
94 2 }
95 1 }
96 //*************************************************
97 //函數功能:向LCD發送命令
98 //輸入變量:COMMAND
99 //輸出變量:無
100 //調用模塊:LCD_WAIT()
101 //*************************************************
102 void LCD_SEND_COMMAND(uchar COMMAND)
103 {
104 1 LCD_WAIT(); //等待空閑
105 1 LCD_RS=0; //命令方式
C51 COMPILER V7.50 LCD2 07/24/2007 16:45:13 PAGE 3
106 1 LCD_RW=0; //寫方式
107 1 SEND_IN=COMMAND;//寫實際的命令到LCD
108 1 }
109 //*************************************************
110 //函數功能:向LCD發送數據
111 //輸入變量:DATA
112 //輸出變量:無
113 //調用模塊:LCD_WAIT()
114 //*************************************************
115 void LCD_SEND_DATA(uchar DATA)
116 {
117 1 LCD_WAIT(); //等待空閑
118 1 LCD_RS=1; //數據方式
119 1 LCD_RW=0; //寫方式
120 1 SEND_IN=DATA;//寫實際的數據到LCD
121 1 }
122 //*************************************************
123 //函數功能:等待LCD空閑
124 //輸入變量:無
125 //輸出變量:無
126 //調用模塊:LCD_GET_FLAG()
127 //*************************************************
128 void LCD_WAIT(void)
129 {
130 1 uchar i;
131 1 i=1000; //定義等待時間,可以防止由于LCD損壞而使程序死循環
132 1 do
133 1 {
134 2 if((LCD_GET_FLAG()&0x80)==0) //判斷BF是否為0
135 2 {
136 3 break;
137 3 }
138 2 }while(--i!=0);
139 1
140 1 }
141 //*************************************************
142 //函數功能:檢查LCD狀態
143 //輸入變量:無
144 //輸出變量:LCD顯示的當前狀態
145 //調用模塊:無
146 //*************************************************
147 uchar LCD_GET_FLAG(void)
148 {
149 1 LCD_RS=0;
150 1 LCD_RW=1;
151 1 return(SEND_IN);
152 1 }
153 //*************************************************
154 //函數功能:檢查LCD狀態
155 //輸入變量:無
156 //輸出變量:LCD顯示的當前狀態
157 //調用模塊:無
158 //*************************************************
159 void LCD_DISPLAY_STR(char *DATA)
160 {
161 1 int x=1,y=1;
162 1 do
163 1 {
164 2 if(y==1)
165 2 {
166 3 LCD_CLR(1);
167 3 LCD_SEND_COMMAND(LCD_LINE1);//發送顯示位置命令
C51 COMPILER V7.50 LCD2 07/24/2007 16:45:13 PAGE 4
168 3 for(;x<(17)&&*DATA!='\0';x++)
169 3 {
170 4 LCD_SEND_DATA(*DATA++); //發送數據
171 4 }
172 3 if(*DATA!='\0') //判斷是否發送完畢
173 3 {
174 4 x=1;
175 4 y=2; //未完畢轉到第二行顯示
176 4 }
177 3 DELAY();
178 3 }
179 2 if(y==2)
180 2 {
181 3 LCD_CLR(2);
182 3 LCD_SEND_COMMAND(LCD_LINE2);
183 3 for(;x<(17)&&*DATA!='\0';x++)
184 3 {
185 4 LCD_SEND_DATA(*DATA++);
186 4 }
187 3 if(*DATA!='\0') //判斷是否發送完畢
188 3 {
189 4 x=1;
190 4 y=1; //未完畢轉到第一行顯示
191 4 }
192 3 DELAY();
193 3 }
194 2 }while(*DATA!='\0');
195 1 }
196 //*************************************************
197 //函數功能:延時3秒
198 //輸入變量:無
199 //輸出變量:無
200 //調用模塊:無
201 //*************************************************
202 void DELAY(void)
203 {
204 1 TMOD=0x02;
205 1 TH0=0x06;
206 1 TL0=0x06;
207 1 TR0=1;
208 1 ET0=1;
209 1 EA=1;
210 1 while(t!=8000); //延時2秒
211 1 TR0=0;
212 1 ET0=0;
213 1 EA=0;
214 1 t=0;
215 1 }
216 //*****************************************
217 //
218 //定時器0的溢出中斷程序
219 //
220 //*****************************************
221 void timer0(void) interrupt 1 using 0
222 {
223 1 t++;
224 1
225 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 418 ----
C51 COMPILER V7.50 LCD2 07/24/2007 16:45:13 PAGE 5
CONSTANT SIZE = 1489 ----
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 + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -