?? lcd_1602.lst
字號:
C51 COMPILER V7.07 LCD_1602 05/14/2009 21:13:16 PAGE 1
C51 COMPILER V7.07, COMPILATION OF MODULE LCD_1602
OBJECT MODULE PLACED IN LCD_1602.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE LCD_1602.C BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /* DS12C887時鐘C語言編程 作者:賴楚君 時間:從2009-5-12至2009-
2
3 程序流程說明
4
5 一、LCD_1602驅動程序
6 1、1ms延時函數
7 2、讀LCD函數
8 3、檢測忙碌標志位函數
9 4、寫LCD函數
10 5、字符顯示定位函數
11 6、輸出并顯示字符函數
12 7、初始化LCD函數
13
14 二、DS12C887驅動程序
15 1、地址替換函數
16 2、讀DS12C887函數
17 3、寫DS12C887函數
18 4、初始化DS12C887函數
19 */
20 #include<reg51.h>
21 #include<intrins.h>
22 #define uchar unsigned char
23 #define uint unsigned int
24
25 /* 一、LCD_1602驅動程序
26 端口引腳定義 */
27 sfr LCD1602_DATA_PORT = 0x80;//P0口
28 sbit RS = P2^5;//命令/數據選擇端(H/L)
29 sbit RW = P2^6;//讀/寫選擇端(H/L)
30 sbit EN = P2^7;//下降沿觸發
31
32
33 /*1ms延時函數*/
34 void Delay_ms(uint i)
35 {
36 1 uint j;
37 1 for(;i>0;i--)
38 1 for(j=125;j>0;j++);
39 1 }
40
41 /*讀LCD函數*/
42 uchar Read_LCD(bit Style)
43 {
44 1 uchar Port;
45 1 RS = Style;
46 1 RW = 1;//讀時高電平有效
47 1 EN = 1;
48 1 Port = LCD1602_DATA_PORT;
49 1 EN = 0;
50 1 RS = ~Style;
51 1 RW = 0;
52 1 return Port;
53 1 }
54
55 /*檢測忙碌標志位函數*/
C51 COMPILER V7.07 LCD_1602 05/14/2009 21:13:16 PAGE 2
56 void Check_BusyFlag()
57 {
58 1 uint Retry;
59 1 for(Retry=1000;Retry>0;Retry--)
60 1 {
61 2 if(Read_LCD(0)&0x80==0) break;//BusyFlag=0表示不忙碌
62 2 }
63 1 }
64
65 /*寫LCD函數*/
66 #define LCD_Command 0 //寫指令宏定義
67 #define LCD_Data 1 //寫數據宏定義
68 void Write_LCD(bit Style,uchar Data )
69 {
70 1 Check_BusyFlag();//寫LCD前要先檢測忙碌標志位,而讀LCD前不用檢測該位
71 1 RS = Style;
72 1 RW = 0;//寫時低電平有效
73 1 EN = 1;
74 1 LCD1602_DATA_PORT = Data;
75 1 EN = 0;
76 1 RS = ~Style;
77 1 RW = 1;
78 1 }
79
80
81
82 /*字符顯示定位函數*/
83 void Goto_XY(uchar X,uchar Y)
84 {
85 1 if(Y==0) Write_LCD(LCD_Command,0x80|X);//第一行顯示
86 1 if(Y==1) Write_LCD(LCD_Command,0xC0|X);//第二行顯示
87 1 }
88
89 /*輸出并顯示字符函數*/
90 void Output_String(uchar *Str)
91 {
92 1 while(*Str!='\0')//不為空字符串時輸出
93 1 {
94 2 Write_LCD(LCD_Data,*Str);
95 2 Str++;
96 2 //Delay_ms(1);//加延時可以實現打字效果
97 2 }
98 1 }
99
100 /*初始化LCD函數*/
101 void Init_LCD()
102 {
103 1
104 1 Write_LCD(LCD_Command,0x38);//寫指令0x38h(16x2顯示,5x7點陣,8位數據接口)
105 1 Write_LCD(LCD_Command,0x38);
106 1 Write_LCD(LCD_Command,0x08);//關閉顯示
107 1 Write_LCD(LCD_Command,0x01);//清屏
108 1 Write_LCD(LCD_Command,0x0C);//開啟顯示且顯示光標
109 1 }
110
111 /* 二、DS12C887驅動程序
112 端口引腳定義(因特爾模式)
113 sfr DS12C887_DATA_PORT = 0x90;//P1口
114 sbit ALE = P2^4;//AS Pin
115 sbit RD_ = P2^3;//DS Pin
116 sbit WR_ = P2^2;//R/W pin
117 sbit CS = P2^1;//CS Pin
C51 COMPILER V7.07 LCD_1602 05/14/2009 21:13:16 PAGE 3
118
119 地址替換函數
120 因為DS12C887的基地址為7F00H
121 uint Replay_Address(uchar Address)
122 {
123 uint Replay;
124 Replay = 0x7F00 + Address;
125 return Replay;
126 }
127
128 讀DS12C887函數
129 uchar Read_DS12C887(uint Address)
130 {
131 uchar Port;
132 ALE = 1;
133 RD_ = 1;
134 WR_ = 1;
135 CS = 0;
136 DS12C887_DATA_PORT = Address;//讀取地址
137
138 ALE = 0;
139 RD_ = 0;
140 Port = DS12C887_DATA_PORT;//讀取數據
141 RD_ = 1;
142 CS = 1;
143 ALE = 1;
144 return Port;
145 }
146
147 寫DS12C887函數
148 void Write_DS12C887(uint Address,uchar Data)
149 {
150 ALE = 1;
151 RD_ = 1;
152 WR_ = 1;
153 CS = 0;
154 DS12C887_DATA_PORT = Address;
155
156 ALE = 0;
157 WR_ = 0;
158 DS12C887_DATA_PORT = Data;
159 WR_ = 1;
160 CS = 1;
161 ALE = 1;
162 }
163
164 初始化DS12C887函數
165 void Init_DS12C887()
166 {
167 Write_DS12C887(Replay_Address(0x0A),0x20);//對寄存器A進行設置:打開振蕩器并使RTC計時;SWQ禁止
168 Write_DS12C887(Replay_Address(0x0B),0x06);//對寄存器B進行設置:時鐘、日歷格式為二進制;24小時模式
169 //Write_DS12C887(Replay_Address(0x0C),0x06);//對寄存器C進行設置:
170 if(Read_DS12C887(Replay_Address(0x0D)) == 0)//讀寄存器D-bit7,如為0則DS12C887內部鋰電池電能耗盡,并在LCD_1
-602顯示"Warning:Battery Few"
171 {
172 Init_LCD();
173 Goto_XY(4,0);
174 Output_String("Warning:");
175 Goto_XY(2,1);
176 Output_String("Battery Few");
177 while(1);
178 }
C51 COMPILER V7.07 LCD_1602 05/14/2009 21:13:16 PAGE 4
179 }
180
181 時間處理函數
182
183 DS12C887時間地址宏定義
184 #define Second 0x00//秒
185 #define Second_Alarm 0x01//秒鬧鐘
186 #define Minute 0x02//分
187 #define Minute_Alarm 0x03//分鬧鐘
188 #define Hour 0x04//時
189 #define Hour_Alarm 0x05//時鬧鐘
190 #define Week 0x06//星期
191 #define Data 0x07//日
192 #define Month 0x08//月
193 #define Year 0x09//年
194 #define Century 0x32//世紀
195
196 void Time_Process()*/
197
198 /*DS12C887+LCD_1602時鐘主函數*/
199 void main()
200 {
201 1 Init_LCD();
202 1 Goto_XY(0,0);
203 1 Output_String("2009-05-14");
204 1 Goto_XY(0,1);
205 1 Output_String("09:05:20");
206 1 while(1);
207 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 213 ----
CONSTANT SIZE = 20 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 1
IDATA SIZE = ---- ----
BIT SIZE = ---- 2
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -