?? main.lst
字號:
C51 COMPILER V8.01 MAIN 10/03/2008 08:28:26 PAGE 1
C51 COMPILER V8.01, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE main.c BROWSE DEBUG OBJECTEXTEND
line level source
1 #include "data.h"
2
3 /*---全局數據定義區---*/
4 unsigned char str[25]; //存儲需要在顯示屏顯示的字符
5 unsigned char PageFlage; //顯示的當前頁號
6 unsigned char up; //上鍵按下次數
7 unsigned char down; //下鍵按下次數
8 unsigned char left; //左鍵按下次數
9 unsigned char right; //右鍵按下次數
10
11 typedef struct time //時間結構體
12 {
13 uchar sec; //秒
14 uchar min; //分
15 uchar hour; //小時
16 uchar day; //日期
17 uchar month; //月
18 uchar year; //年
19 uchar week; //星期
20 };
21
22 uchar xdata sec1 _at_ 0x4000;
23 uchar xdata min1 _at_ 0x4001;
24 uchar xdata hour1 _at_ 0x4002;
25 uchar xdata day1 _at_ 0x4003;
26 uchar xdata month1 _at_ 0x4004;
27 uchar xdata year1 _at_ 0x4005;
28 uchar xdata week1 _at_ 0x4006;
29
30 uchar xdata sec2 _at_ 0x4007;
31 uchar xdata min2 _at_ 0x4008;
32 uchar xdata hour2 _at_ 0x4009;
33 uchar xdata day2 _at_ 0x400a;
34 uchar xdata month2 _at_ 0x400b;
35 uchar xdata year2 _at_ 0x400c;
36 uchar xdata week2 _at_ 0x400d;
37
38 uchar xdata cal[8][7] _at_ 0x4020; //日歷表存儲
39
40 /*---全局數據定義區---*/
41
42 /*---外部函數引用區---*/
43 //---顯示器函數區
44 extern char InitLcd(); //液晶顯示器初始化函數
45 extern void cls(); //液晶顯示器清屏函數
46 //液晶顯示器顯示函數
47 extern uchar dprintf(uchar x,uchar y,char *string,uchar mod);
48 //液晶顯示器坐標設置函數
49 extern void SetPos(uchar row, uchar col);
50 extern void WriteCom(uchar cmd); //液晶顯示器命令寫函數
51 extern void WriteData(uchar Data); //液晶顯示器寫數據函數
52
53 //---鍵盤處理函數區
54 extern uchar KeyScan(); //按鍵掃描函數
55 extern uchar KeyProcess(uchar KeyNum); //按鍵處理函數
C51 COMPILER V8.01 MAIN 10/03/2008 08:28:26 PAGE 2
56
57 //---DS1302處理函數區
58 //1302寫數據函數
59 extern uchar Write1302(uchar Addr,uchar Data);
60 extern uchar Read1302(uchar Addr); //1302讀數據函數
61
62 //---DS18B20處理函數區
63 extern void Init_DS18B20(); //DS18B20復位函數
64 extern unsigned char ReadOneChar(); //DS18B20字節讀函數
65 extern void WriteOneChar(uchar dat); //DS18B20字節寫函數
66 extern void delay_18B20(unsigned int i);//DS18B20延時函數
67 //extern uchar BcdToHex(uchar time,uchar Data);
68 /*---外部函數引用區---*/
69
70 /*---內部函數區---*/
71 void BcdToChar(struct time times); //BCD碼轉字符函數
72 void MainPage(); //主頁顯示函數
73 int GetTemperature(); //讀取溫度函數
74 /*---內部函數區---*/
75
76
77 void BcdToChar(struct time times)
78 {
79 1 uchar str1[5],i;
80 1
81 1 for(i=0;i<25;i++)
82 1 str[i]=0;
83 1 for(i=0;i<5;i++)
84 1 str1[i]=0;
85 1
86 1 strcat(str,"20");
87 1 str1[0] = times.year >> 4 | 0x30;
88 1 strcat(str,str1);
89 1 str1[0] = times.year & 0x0f | 0x30;
90 1 strcat(str,str1);
91 1
92 1 strcat(str,".");
93 1
94 1 str1[0] = times.month >> 4 | 0x30;
95 1 strcat(str,str1);
96 1 str1[0] = times.month & 0x0f | 0x30;
97 1 strcat(str,str1);
98 1
99 1 strcat(str,".");
100 1
101 1 str1[0] = times.day >> 4 | 0x30;
102 1 strcat(str,str1);
103 1 str1[0] = times.day & 0x0f | 0x30;
104 1 strcat(str,str1);
105 1
106 1 strcat(str," w:");
107 1
108 1 str1[0] = times.week & 0x0f | 0x30;
109 1 strcat(str,str1);
110 1
111 1 strcat(str," ");
112 1
113 1 str1[0] = times.hour >> 4 | 0x30;
114 1 strcat(str,str1);
115 1 str1[0] = times.hour & 0x0f | 0x30;
116 1 strcat(str,str1);
117 1
C51 COMPILER V8.01 MAIN 10/03/2008 08:28:26 PAGE 3
118 1 strcat(str,":");
119 1
120 1 str1[0] = times.min >> 4 | 0x30;
121 1 strcat(str,str1);
122 1 str1[0] = times.min & 0x0f | 0x30;
123 1 strcat(str,str1);
124 1 }
125
126 int GetTemperature() //讀取18B20溫度函數
127 {
128 1 uchar a=0;
129 1 uchar b=0;
130 1 uchar c=0;
131 1 uchar temp,temp1,temp2;
132 1 short cou[3],i;
133 1
134 1 uchar str1[3];
135 1
136 1 Init_DS18B20();
137 1 WriteOneChar(0xCC); // 跳過讀序號列號的操作
138 1 WriteOneChar(0x44); // 啟動溫度轉換
139 1
140 1 delay_18B20(200); // this message is wery important
141 1
142 1 Init_DS18B20();
143 1 WriteOneChar(0xCC); //跳過讀序號列號的操作
144 1 WriteOneChar(0xBE); //讀取溫度寄存器等(共可讀9個寄存器) 前兩個就是溫度
145 1
146 1 delay_18B20(200);
147 1
148 1 a=ReadOneChar(); //讀取溫度值低位
149 1 b=ReadOneChar(); //讀取溫度值高位
150 1 temp1=b<<4;
151 1 temp1+=(a&0xf0)>>4;
152 1 temp2=a&0x0f;
153 1
154 1 temp=((b*256+a)>>4); //當前采集溫度值除16得實際溫度值
155 1 if((temp & 0x80) == 0x80)
156 1 {
157 2 temp1 = 1;
158 2 temp = abs((char)temp);
159 2 }
160 1 else
161 1 temp1 = 0;
162 1
163 1 cou[0] = 0;
164 1 cou[1] = 0;
165 1 cou[2] = 0;
166 1
167 1 while(temp >= 100)
168 1 {
169 2 temp = temp - 100;
170 2 cou[0]++;
171 2 }
172 1
173 1 while(temp >= 10)
174 1 {
175 2 temp = temp - 10;
176 2 cou[1]++;
177 2 }
178 1
179 1 cou[2] = temp;
C51 COMPILER V8.01 MAIN 10/03/2008 08:28:26 PAGE 4
180 1
181 1 for(i=0;i<25;i++)
182 1 str[i]=0;
183 1
184 1 if(temp1 == 1)
185 1 strcat(str,"溫度: -");
186 1 else
187 1 strcat(str,"溫度: +");
188 1
189 1 cou[0] = cou[0] | 0x30;
190 1 str1[0] = cou[0];
191 1 cou[1] = cou[1] | 0x30;
192 1 str1[1] = cou[1];
193 1 cou[2] = cou[2] | 0x30;
194 1 str1[2] = cou[2];
195 1 strcat(str,str1);
196 1
197 1 return temp;
198 1 }
199
200 void MainPage()
201 {
202 1 struct time times;
203 1 int value;
204 1
205 1 PageFlage = 1;
206 1 left = 3;
207 1 right = 1;
208 1 times.min = Read1302(MIN|0x01);
209 1 times.hour = Read1302(HOUR|0x01);
210 1 times.day = Read1302(DAY|0x01);
211 1 times.month = Read1302(MONTH|0x01);
212 1 times.year = Read1302(YEAR|0x01);
213 1 times.week = Read1302(WEEK|0x01);
214 1 times.week = times.week - 1;
215 1
216 1 BcdToChar(times); //溫度數值轉換為字符
217 1
218 1 SetPos(0,0);
219 1 dprintf(0,0,str,1); //顯示時間
220 1
221 1 value = GetTemperature(); //讀取溫度
222 1
223 1 if(value == 0x7fff)
224 1 dprintf(0,16,"溫度: ",1);
225 1 else
226 1 dprintf(0,16,str,1);
227 1
228 1 dprintf(0,48,"遙控",0);
229 1 dprintf(32,48," ",1);
230 1 dprintf(40,48,"日歷",1);
231 1 dprintf(72,48," ",1);
232 1 dprintf(80,48,"計算器",1);
233 1 dprintf(0,80,"受控車狀態: 待命",1);
234 1 dprintf(0,112,"確定",1);
235 1 dprintf(127,112,"返回",1);
236 1 }
237
238 main()
239 {
240 1 int key;
241 1 int value;
C51 COMPILER V8.01 MAIN 10/03/2008 08:28:26 PAGE 5
242 1 struct time times;
243 1
244 1 InitLcd();
245 1
246 1 dat = 0;
247 1 clk = 0;
248 1 PageFlage = 1;
249 1
250 1 MainPage();
251 1
252 1 while(1)
253 1 {
254 2 if(PageFlage == 1)
255 2 {
256 3 times.min = Read1302(MIN|0x01);
257 3 times.hour = Read1302(HOUR|0x01);
258 3 times.day = Read1302(DAY|0x01);
259 3 times.month = Read1302(MONTH|0x01);
260 3 times.year = Read1302(YEAR|0x01);
261 3 times.week = Read1302(WEEK|0x01);
262 3 times.week = times.week - 1;
263 3
264 3 day1 = day2 = times.day;
265 3 month1 = month2 = times.month;
266 3 year1 = year2 = times.year;
267 3 week1 = week2 = times.week;
268 3
269 3 BcdToChar(times); //溫度數值轉換為字符
270 3
271 3 SetPos(0,0);
272 3 dprintf(0,0,str,1); //顯示時間
273 3
274 3 value = GetTemperature(); //讀取溫度
275 3
276 3 if(value == 0x7fff)
277 3 dprintf(0,16,"溫度: ",1);
278 3 else
279 3 dprintf(0,16,str,1);
280 3 }
281 2
282 2 key = KeyScan();
283 2 KeyProcess(key);
284 2 }
285 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1133 ----
CONSTANT SIZE = 80 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 30 42
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 + -