|
|
C51 COMPILER V9.56.0.0 MAIN 05/01/2022 12:19:19 PAGE 1 |
|
|
|
|
|
|
|
|
C51 COMPILER V9.56.0.0, COMPILATION OF MODULE MAIN |
|
|
OBJECT MODULE PLACED IN main.OBJ |
|
|
COMPILER INVOKED BY: D:\Keil_v5\C51\BIN\C51.EXE main.c OPTIMIZE(8,SPEED) BROWSE DEBUG OBJECTEXTEND TABS(2) |
|
|
|
|
|
line level source |
|
|
|
|
|
1 #include<reg51.h> |
|
|
2 #include"lcd.h" |
|
|
3 #include"ds1302.h" |
|
|
4 #include"i2c.h" |
|
|
5 #include "DS18B20.h" |
|
|
6 |
|
|
7 #include <stdio.h> |
|
|
8 #include <string.h> |
|
|
9 |
|
|
10 |
|
|
11 #define uchar unsigned char |
|
|
12 #define uint unsigned int |
|
|
13 |
|
|
14 sbit LED0=P2^5; |
|
|
15 sbit LED1=P2^6; |
|
|
16 sbit LED2=P2^1; |
|
|
17 |
|
|
18 sbit LED3=P2^4; |
|
|
19 |
|
|
20 sbit LED4=P2^3; |
|
|
21 |
|
|
22 sbit key1 = P1^2; |
|
|
23 sbit key2 = P1^3; |
|
|
24 sbit key3 = P2^2; |
|
|
25 sbit key4 = P2^7; |
|
|
26 |
|
|
27 |
|
|
28 sbit IN = P3^7; |
|
|
29 sbit OUT = P3^6; |
|
|
30 |
|
|
31 sbit SCL1=P1^1; |
|
|
32 sbit SDA1=P1^0; |
|
|
33 |
|
|
34 int cut = 0; |
|
|
35 |
|
|
36 struct Time{ |
|
|
37 int hour; |
|
|
38 int min; |
|
|
39 int sec; |
|
|
40 }; |
|
|
41 |
|
|
42 struct UserInfo{ |
|
|
43 int num; |
|
|
44 int model; |
|
|
45 int set; |
|
|
46 int start; |
|
|
47 float Light; |
|
|
48 int temp; |
|
|
49 struct Time time[2]; |
|
|
50 }; |
|
|
51 |
|
|
52 struct UserInfo userInfo; |
|
|
53 |
|
|
54 void LcdDisplay(); |
|
|
55 void LcdDisplay1(); |
|
|
C51 COMPILER V9.56.0.0 MAIN 05/01/2022 12:19:19 PAGE 2 |
|
|
|
|
|
56 void Delay10ms(void); |
|
|
57 |
|
|
58 #define SlaveAddress 0x46 //¶¨ÒåÆ÷¼þÔÚIIC×ÜÏßÖеĴӵØÖ·,¸ù¾ÝALT ADDRESSµ |
|
|
-ØÖ·Òý½Å²»Í¬ÐÞ¸Ä |
|
|
59 //ALT ADDRESSÒý½Å½ÓµØʱµØַΪ0x46£¬½ÓµçԴʱµØÖ |
|
|
-·Îª0xB8 |
|
|
60 typedef unsigned char BYTE; |
|
|
61 typedef unsigned short WORD; |
|
|
62 |
|
|
63 BYTE BUF[8]; //½ÓÊÕÊý¾Ý»º´æÇø |
|
|
64 int dis_data; //±äÁ¿ |
|
|
65 |
|
|
66 void delay_nms(unsigned int k); |
|
|
67 void InitLcd(); |
|
|
68 void Init_BH1750(void); |
|
|
69 |
|
|
70 void WriteDataLCM(uchar dataW); |
|
|
71 void WriteCommandLCM(uchar CMD,uchar Attribc); |
|
|
72 void DisplayOneChar(uchar X,uchar Y,uchar DData); |
|
|
73 void conversion(uint temp_data); |
|
|
74 |
|
|
75 void Single_Write_BH1750(uchar REG_Address); //µ¥¸öдÈëÊý¾Ý |
|
|
76 uchar Single_Read_BH1750(uchar REG_Address); //µ¥¸ö¶ÁÈ¡ÄÚ²¿¼Ä´æÆ÷Êý¾Ý |
|
|
77 void Multiple_Read_BH1750(); //Á¬ÐøµÄ¶ÁÈ¡ÄÚ²¿¼Ä´æÆ÷Êý |
|
|
-¾Ý |
|
|
78 //------------------------------------ |
|
|
79 void Delay5us(); |
|
|
80 void Delay5ms(); |
|
|
81 void BH1750_Start(); //ÆðʼÐźŠ|
|
|
82 void BH1750_Stop(); //Í£Ö¹ÐźŠ|
|
|
83 void BH1750_SendACK(bit ack); //Ó¦´ðACK |
|
|
84 bit BH1750_RecvACK(); //¶Áack |
|
|
85 void BH1750_SendByte(BYTE dat); //IICµ¥¸ö×Ö½Úд |
|
|
86 BYTE BH1750_RecvByte(); //IICµ¥¸ö×Ö½Ú¶Á |
|
|
87 |
|
|
88 |
|
|
89 //ºÁÃëÑÓʱ************************** |
|
|
90 void delay_nms(unsigned int k) |
|
|
91 { |
|
|
92 1 unsigned int i,j; |
|
|
93 1 for(i=0;i<k;i++) |
|
|
94 1 { |
|
|
95 2 for(j=0;j<121;j++) |
|
|
96 2 {;}} |
|
|
97 1 } |
|
|
98 |
|
|
99 void Delay5us() |
|
|
100 { |
|
|
101 1 _nop_();_nop_();_nop_();_nop_(); |
|
|
102 1 _nop_();_nop_();_nop_();_nop_(); |
|
|
103 1 _nop_();_nop_();_nop_();_nop_(); |
|
|
104 1 _nop_();_nop_();_nop_();_nop_(); |
|
|
105 1 } |
|
|
106 |
|
|
107 void Delay5ms() |
|
|
108 { |
|
|
109 1 WORD n = 560; |
|
|
110 1 |
|
|
111 1 while (n--); |
|
|
112 1 } |
|
|
113 |
|
|
114 /************************************** |
|
|
C51 COMPILER V9.56.0.0 MAIN 05/01/2022 12:19:19 PAGE 3 |
|
|
|
|
|
115 ÆðʼÐźŠ|
|
|
116 **************************************/ |
|
|
117 void BH1750_Start() |
|
|
118 { |
|
|
119 1 SDA1 = 1; //À¸ßÊý¾ÝÏß |
|
|
120 1 SCL1 = 1; //À¸ßʱÖÓÏß |
|
|
121 1 Delay5us(); //ÑÓʱ |
|
|
122 1 SDA1 = 0; //²úÉúϽµÑØ |
|
|
123 1 Delay5us(); //ÑÓʱ |
|
|
124 1 SCL1 = 0; //ÀµÍʱÖÓÏß |
|
|
125 1 } |
|
|
126 |
|
|
127 /************************************** |
|
|
128 Í£Ö¹ÐźŠ|
|
|
129 **************************************/ |
|
|
130 void BH1750_Stop() |
|
|
131 { |
|
|
132 1 SDA1 = 0; //ÀµÍÊý¾ÝÏß |
|
|
133 1 SCL1 = 1; //À¸ßʱÖÓÏß |
|
|
134 1 Delay5us(); //ÑÓʱ |
|
|
135 1 SDA1 = 1; //²úÉúÉÏÉýÑØ |
|
|
136 1 Delay5us(); //ÑÓʱ |
|
|
137 1 } |
|
|
138 |
|
|
139 /************************************** |
|
|
140 ·¢ËÍÓ¦´ðÐźŠ|
|
|
141 Èë¿Ú²ÎÊý:ack (0:ACK 1:NAK) |
|
|
142 **************************************/ |
|
|
143 void BH1750_SendACK(bit ack) |
|
|
144 { |
|
|
145 1 SDA1 = ack; //дӦ´ðÐźŠ|
|
|
146 1 SCL1 = 1; //À¸ßʱÖÓÏß |
|
|
147 1 Delay5us(); //ÑÓʱ |
|
|
148 1 SCL1 = 0; //ÀµÍʱÖÓÏß |
|
|
149 1 Delay5us(); //ÑÓʱ |
|
|
150 1 } |
|
|
151 |
|
|
152 /************************************** |
|
|
153 ½ÓÊÕÓ¦´ðÐźŠ|
|
|
154 **************************************/ |
|
|
155 bit BH1750_RecvACK() |
|
|
156 { |
|
|
157 1 SCL1 = 1; //À¸ßʱÖÓÏß |
|
|
158 1 Delay5us(); //ÑÓʱ |
|
|
159 1 CY = SDA1; //¶ÁÓ¦´ðÐźŠ|
|
|
160 1 SCL1 = 0; //ÀµÍʱÖÓÏß |
|
|
161 1 Delay5us(); //ÑÓʱ |
|
|
162 1 |
|
|
163 1 return CY; |
|
|
164 1 } |
|
|
165 |
|
|
166 /************************************** |
|
|
167 ÏòIIC×ÜÏß·¢ËÍÒ»¸ö×Ö½ÚÊý¾Ý |
|
|
168 **************************************/ |
|
|
169 void BH1750_SendByte(BYTE dat) |
|
|
170 { |
|
|
171 1 BYTE i; |
|
|
172 1 |
|
|
173 1 for (i=0; i<8; i++) //8λ¼ÆÊýÆ÷ |
|
|
174 1 { |
|
|
175 2 dat <<= 1; //ÒƳöÊý¾ÝµÄ×î¸ßλ |
|
|
176 2 SDA1 = CY; //ËÍÊý¾Ý¿Ú |
|
|
C51 COMPILER V9.56.0.0 MAIN 05/01/2022 12:19:19 PAGE 4 |
|
|
|
|
|
177 2 SCL1 = 1; //À¸ßʱÖÓÏß |
|
|
178 2 Delay5us(); //ÑÓʱ |
|
|
179 2 SCL1 = 0; //ÀµÍʱÖÓÏß |
|
|
180 2 Delay5us(); //ÑÓʱ |
|
|
181 2 } |
|
|
182 1 BH1750_RecvACK(); |
|
|
183 1 } |
|
|
184 |
|
|
185 /************************************** |
|
|
186 ´ÓIIC×ÜÏß½ÓÊÕÒ»¸ö×Ö½ÚÊý¾Ý |
|
|
187 **************************************/ |
|
|
188 BYTE BH1750_RecvByte() |
|
|
189 { |
|
|
190 1 BYTE i; |
|
|
191 1 BYTE dat = 0; |
|
|
192 1 |
|
|
193 1 SDA1 = 1; //ʹÄÜÄÚ²¿ÉÏÀ,×¼±¸¶ÁÈ¡Êý¾Ý, |
|
|
194 1 for (i=0; i<8; i++) //8λ¼ÆÊýÆ÷ |
|
|
195 1 { |
|
|
196 2 dat <<= 1; |
|
|
197 2 SCL1 = 1; //À¸ßʱÖÓÏß |
|
|
198 2 Delay5us(); //ÑÓʱ |
|
|
199 2 dat |= SDA1; //¶ÁÊý¾Ý |
|
|
200 2 SCL1 = 0; //ÀµÍʱÖÓÏß |
|
|
201 2 Delay5us(); //ÑÓʱ |
|
|
202 2 } |
|
|
203 1 return dat; |
|
|
204 1 } |
|
|
205 |
|
|
206 //********************************* |
|
|
207 |
|
|
208 void Single_Write_BH1750(uchar REG_Address) |
|
|
209 { |
|
|
210 1 BH1750_Start(); //ÆðʼÐźŠ|
|
|
211 1 BH1750_SendByte(SlaveAddress); //·¢ËÍÉ豸µØÖ·+дÐźŠ|
|
|
212 1 BH1750_SendByte(REG_Address); //ÄÚ²¿¼Ä´æÆ÷µØÖ·£¬ |
|
|
213 1 // BH1750_SendByte(REG_data); //ÄÚ²¿¼Ä´æÆ÷Êý¾Ý£¬ |
|
|
214 1 BH1750_Stop(); //·¢ËÍÍ£Ö¹ÐźŠ|
|
|
215 1 } |
|
|
216 |
|
|
217 //********µ¥×Ö½Ú¶ÁÈ¡***************************************** |
|
|
218 /* |
|
|
219 uchar Single_Read_BH1750(uchar REG_Address) |
|
|
220 { uchar REG_data; |
|
|
221 BH1750_Start(); //ÆðʼÐźŠ|
|
|
222 BH1750_SendByte(SlaveAddress); //·¢ËÍÉ豸µØÖ·+дÐźŠ|
|
|
223 BH1750_SendByte(REG_Address); //·¢ËÍ´æ´¢µ¥ÔªµØÖ·£¬´Ó0¿ªÊ¼ |
|
|
224 BH1750_Start(); //ÆðʼÐźŠ|
|
|
225 BH1750_SendByte(SlaveAddress+1); //·¢ËÍÉ豸µØÖ·+¶ÁÐźŠ|
|
|
226 REG_data=BH1750_RecvByte(); //¶Á³ö¼Ä´æÆ÷Êý¾Ý |
|
|
227 BH1750_SendACK(1); |
|
|
228 BH1750_Stop(); //Í£Ö¹ÐźŠ|
|
|
229 return REG_data; |
|
|
230 } |
|
|
231 */ |
|
|
232 //********************************************************* |
|
|
233 // |
|
|
234 //Á¬Ðø¶Á³öBH1750ÄÚ²¿Êý¾Ý |
|
|
235 // |
|
|
236 //********************************************************* |
|
|
237 void Multiple_read_BH1750(void) |
|
|
238 |
|
|
C51 COMPILER V9.56.0.0 MAIN 05/01/2022 12:19:19 PAGE 5 |
|
|
|
|
|
239 { uchar i; |
|
|
240 1 BH1750_Start(); //ÆðʼÐźŠ|
|
|
241 1 BH1750_SendByte(SlaveAddress+1); //·¢ËÍÉ豸µØÖ·+¶ÁÐźŠ|
|
|
242 1 |
|
|
243 1 for (i=0; i<3; i++) //Á¬Ðø¶ÁÈ¡2¸öµØÖ·Êý¾Ý£¬´æ´¢ÖÐBUF |
|
|
244 1 { |
|
|
245 2 BUF[i] = BH1750_RecvByte(); //BUF[0]´æ´¢0x32µØÖ·ÖеÄÊý¾Ý |
|
|
246 2 if (i == 3) |
|
|
247 2 { |
|
|
248 3 |
|
|
249 3 BH1750_SendACK(1); //×îºóÒ»¸öÊý¾ÝÐèÒª»ØNOACK |
|
|
250 3 } |
|
|
251 2 else |
|
|
252 2 { |
|
|
253 3 BH1750_SendACK(0); //»ØÓ¦ACK |
|
|
254 3 } |
|
|
255 2 } |
|
|
256 1 |
|
|
257 1 BH1750_Stop(); //Í£Ö¹ÐźŠ|
|
|
258 1 Delay5ms(); |
|
|
259 1 } |
|
|
260 |
|
|
261 |
|
|
262 //³õʼ»¯BH1750£¬¸ù¾ÝÐèÒªÇë²Î¿¼pdf½øÐÐÐÞ¸Ä**** |
|
|
263 void Init_BH1750() |
|
|
264 { |
|
|
265 1 Single_Write_BH1750(0x01); |
|
|
266 1 |
|
|
267 1 } |
|
|
268 |
|
|
269 |
|
|
270 void Uart_Init() |
|
|
271 { |
|
|
272 1 TMOD = 0x20 | 0x01; |
|
|
273 1 SCON = 0x50; |
|
|
274 1 TH1 = 0xFD; |
|
|
275 1 TL1 = TH1; |
|
|
276 1 PCON = 0x00; |
|
|
277 1 EA = 1; |
|
|
278 1 ES = 1; |
|
|
279 1 TR1 = 1; |
|
|
280 1 } |
|
|
281 |
|
|
282 void us_delay(uchar t) |
|
|
283 { |
|
|
284 1 while(t--); |
|
|
285 1 } |
|
|
286 |
|
|
287 void Send_Uart(uchar value) |
|
|
288 { |
|
|
289 1 ES=0; |
|
|
290 1 TI=0; |
|
|
291 1 SBUF=value; |
|
|
292 1 while(TI==0); |
|
|
293 1 TI=0; |
|
|
294 1 ES=1; |
|
|
295 1 } |
|
|
296 |
|
|
297 void Bluetooth_Set(uchar *puf) |
|
|
298 { |
|
|
299 1 while(*puf!='\0') |
|
|
300 1 { |
|
|
C51 COMPILER V9.56.0.0 MAIN 05/01/2022 12:19:19 PAGE 6 |
|
|
|
|
|
301 2 Send_Uart(*puf); |
|
|
302 2 us_delay(5); |
|
|
303 2 puf++; |
|
|
304 2 } |
|
|
305 1 } |
|
|
306 |
|
|
307 void Detection() |
|
|
308 { |
|
|
309 1 int i = 0; |
|
|
310 1 Single_Write_BH1750(0x01); |
|
|
311 1 Single_Write_BH1750(0x10); |
|
|
312 1 delay_nms(180); |
|
|
313 1 Multiple_Read_BH1750(); |
|
|
314 1 dis_data=BUF[0]; |
|
|
315 1 dis_data=(dis_data<<8)+BUF[1]; |
|
|
316 1 userInfo.Light = (float)dis_data/1.2; |
|
|
317 1 |
|
|
318 1 userInfo.temp = Temper_change(); |
|
|
319 1 userInfo.temp /= 100; |
|
|
320 1 if(key1==0) |
|
|
321 1 { |
|
|
322 2 Delay10ms(); |
|
|
323 2 if(key1==0){ |
|
|
324 3 if(userInfo.set == 0){ |
|
|
325 4 if(userInfo.model == 0) userInfo.model = 1; |
|
|
326 4 else userInfo.model = 0; |
|
|
327 4 } |
|
|
328 3 } |
|
|
329 2 while((i<50)&&(key1==0)){ |
|
|
330 3 Delay10ms(); |
|
|
331 3 i++; |
|
|
332 3 } |
|
|
333 2 i=0; |
|
|
334 2 } |
|
|
335 1 |
|
|
336 1 if(key2==0) |
|
|
337 1 { |
|
|
338 2 Delay10ms(); |
|
|
339 2 if(key2==0){ |
|
|
340 3 if(userInfo.model){ |
|
|
341 4 if(userInfo.start == 0) userInfo.start = 1; |
|
|
342 4 else userInfo.start = 0; |
|
|
343 4 }else{ |
|
|
344 4 if(userInfo.set == 0) userInfo.set = 1; |
|
|
345 4 else userInfo.set = 0; |
|
|
346 4 cut = 0; |
|
|
347 4 } |
|
|
348 3 LcdWriteCom(0x01); //清屏 |
|
|
349 3 } |
|
|
350 2 while((i<50)&&(key2==0)){ |
|
|
351 3 Delay10ms(); |
|
|
352 3 i++; |
|
|
353 3 } |
|
|
354 2 i=0; |
|
|
355 2 } |
|
|
356 1 |
|
|
357 1 if(IN==0) |
|
|
358 1 { |
|
|
359 2 Delay10ms(); |
|
|
360 2 if(IN==0){ |
|
|
361 3 userInfo.num++; |
|
|
362 3 if(userInfo.num > 99) userInfo.num = 99; |
|
|
C51 COMPILER V9.56.0.0 MAIN 05/01/2022 12:19:19 PAGE 7 |
|
|
|
|
|
363 3 } |
|
|
364 2 while((i<50)&&(IN==0)){ |
|
|
365 3 Delay10ms(); |
|
|
366 3 i++; |
|
|
367 3 } |
|
|
368 2 i=0; |
|
|
369 2 } |
|
|
370 1 |
|
|
371 1 if(OUT==0) //<EFBFBD><EFBFBD>ⰴ<EFBFBD><EFBFBD>K1<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD> |
|
|
372 1 { |
|
|
373 2 Delay10ms(); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> |
|
|
374 2 if(OUT==0){ |
|
|
375 3 userInfo.num--; |
|
|
376 3 if(userInfo.num < 0) userInfo.num = 0; |
|
|
377 3 } |
|
|
378 2 while((i<50)&&(OUT==0)){ |
|
|
379 3 Delay10ms(); |
|
|
380 3 i++; |
|
|
381 3 } |
|
|
382 2 i=0; |
|
|
383 2 } |
|
|
384 1 |
|
|
385 1 if(key3==0) //<EFBFBD><EFBFBD>ⰴ<EFBFBD><EFBFBD>K1<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD> |
|
|
386 1 { |
|
|
387 2 Delay10ms(); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> |
|
|
388 2 if(key3==0){ |
|
|
389 3 cut++; |
|
|
390 3 if(cut >= 4) cut = 0; |
|
|
391 3 } |
|
|
392 2 while((i<50)&&(key3==0)){ |
|
|
393 3 Delay10ms(); |
|
|
394 3 i++; |
|
|
395 3 } |
|
|
396 2 i=0; |
|
|
397 2 } |
|
|
398 1 |
|
|
399 1 if(key4==0) //<EFBFBD><EFBFBD>ⰴ<EFBFBD><EFBFBD>K1<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD> |
|
|
400 1 { |
|
|
401 2 Delay10ms(); //<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> |
|
|
402 2 if(key4==0){ |
|
|
403 3 if(cut == 0){ |
|
|
404 4 userInfo.time[0].hour++; |
|
|
405 4 if(userInfo.time[0].hour >= 24) userInfo.time[0].hour = 0; |
|
|
406 4 }else if(cut == 1){ |
|
|
407 4 userInfo.time[0].min++; |
|
|
408 4 if(userInfo.time[0].min >= 59) userInfo.time[0].min = 0; |
|
|
409 4 }else if(cut == 2){ |
|
|
410 4 userInfo.time[1].hour++; |
|
|
411 4 if(userInfo.time[1].hour >= 24) userInfo.time[1].hour = 0; |
|
|
412 4 }else if(cut == 3){ |
|
|
413 4 userInfo.time[1].min++; |
|
|
414 4 if(userInfo.time[1].min >= 59) userInfo.time[1].min = 0; |
|
|
415 4 } |
|
|
416 3 while((i<50)&&(key4==0)){ |
|
|
417 4 Delay10ms(); |
|
|
418 4 i++; |
|
|
419 4 } |
|
|
420 3 i=0; |
|
|
421 3 } |
|
|
422 2 } |
|
|
423 1 } |
|
|
424 |
|
|
C51 COMPILER V9.56.0.0 MAIN 05/01/2022 12:19:19 PAGE 8 |
|
|
|
|
|
425 |
|
|
426 int getTimeResult() |
|
|
427 { |
|
|
428 1 int result = 1; |
|
|
429 1 struct Time Nowtime; |
|
|
430 1 |
|
|
431 1 Nowtime.hour = TIME[2]/16 * 10 + (TIME[2]&0x0f); |
|
|
432 1 Nowtime.min = TIME[1]/16 * 10 + (TIME[1]&0x0f); |
|
|
433 1 |
|
|
434 1 if(Nowtime.hour < userInfo.time[0].hour || Nowtime.hour > userInfo.time[1].hour) return 0; |
|
|
435 1 if(Nowtime.hour == userInfo.time[0].hour && Nowtime.min < userInfo.time[0].min) return 0; |
|
|
436 1 if(Nowtime.hour == userInfo.time[1].hour && Nowtime.min > userInfo.time[1].min) return 0; |
|
|
437 1 |
|
|
438 1 return result; |
|
|
439 1 } |
|
|
440 |
|
|
441 |
|
|
442 void Dispose() |
|
|
443 { |
|
|
444 1 |
|
|
445 1 if(userInfo.model == 0){ |
|
|
446 2 if(getTimeResult() && userInfo.Light < 100){ |
|
|
447 3 if(userInfo.num < 10 && userInfo.num > 0) LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 1; |
|
|
448 3 else if(userInfo.num >= 10 && userInfo.num < 20) LED0 = 0, LED1 = 0, LED2 = 1 ,LED3 = 1; |
|
|
449 3 else if(userInfo.num >= 20 && userInfo.num < 30) LED0 = 0, LED1 = 1, LED2 = 1 ,LED3 = 1; |
|
|
450 3 else if(userInfo.num >= 30) LED0 = 1, LED1 = 1, LED2 = 1 ,LED3 = 1; |
|
|
451 3 else LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 0; |
|
|
452 3 }else{ |
|
|
453 3 LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 0; |
|
|
454 3 } |
|
|
455 2 }else{ |
|
|
456 2 if(userInfo.start){ |
|
|
457 3 LED0 = 1, LED1 = 1, LED2 = 1 ,LED3 = 1; |
|
|
458 3 }else{ |
|
|
459 3 LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 0; |
|
|
460 3 } |
|
|
461 2 } |
|
|
462 1 LED4 = userInfo.model; |
|
|
463 1 } |
|
|
464 |
|
|
465 void main() |
|
|
466 { |
|
|
467 1 int i = 0; |
|
|
468 1 uchar str[10]; |
|
|
469 1 Ds1302Init(); |
|
|
470 1 Uart_Init(); |
|
|
471 1 LcdInit(); |
|
|
472 1 |
|
|
473 1 userInfo.time[0].hour = 18; |
|
|
474 1 userInfo.time[0].min = 0; |
|
|
475 1 userInfo.time[0].sec = 0; |
|
|
476 1 |
|
|
477 1 userInfo.time[1].hour = 23; |
|
|
478 1 userInfo.time[1].min = 30; |
|
|
479 1 userInfo.time[1].sec = 0; |
|
|
480 1 |
|
|
481 1 while(1) |
|
|
482 1 { |
|
|
483 2 Ds1302ReadTime(); |
|
|
484 2 LcdDisplay(); |
|
|
485 2 Detection(); |
|
|
486 2 Dispose(); |
|
|
C51 COMPILER V9.56.0.0 MAIN 05/01/2022 12:19:19 PAGE 9 |
|
|
|
|
|
487 2 sprintf(str, "%d\r\n", userInfo.temp); |
|
|
488 2 Bluetooth_Set(str); |
|
|
489 2 } |
|
|
490 1 } |
|
|
491 |
|
|
492 void LcdDisplay() |
|
|
493 { |
|
|
494 1 uint temp_data; |
|
|
495 1 if(userInfo.set == 0){ |
|
|
496 2 // TODO 显示时间 |
|
|
497 2 LcdWriteCom(0x80); |
|
|
498 2 LcdWriteData('0'+TIME[4]/16); //月 |
|
|
499 2 LcdWriteData('0'+(TIME[4]&0x0f)); |
|
|
500 2 LcdWriteData('-'); |
|
|
501 2 LcdWriteData('0'+TIME[3]/16); //日 |
|
|
502 2 LcdWriteData('0'+(TIME[3]&0x0f)); |
|
|
503 2 LcdWriteData(' '); |
|
|
504 2 |
|
|
505 2 LcdWriteData('0'+TIME[2]/16); //时 |
|
|
506 2 LcdWriteData('0'+(TIME[2]&0x0f)); |
|
|
507 2 LcdWriteData(':'); |
|
|
508 2 LcdWriteData('0'+TIME[1]/16); //分 |
|
|
509 2 LcdWriteData('0'+(TIME[1]&0x0f)); |
|
|
510 2 LcdWriteData(':'); |
|
|
511 2 LcdWriteData('0'+TIME[0]/16); //秒 |
|
|
512 2 LcdWriteData('0'+(TIME[0]&0x0f)); |
|
|
513 2 |
|
|
514 2 LcdWriteData(' '); |
|
|
515 2 LcdWriteData('0'+(TIME[5]&0x0f)); |
|
|
516 2 |
|
|
517 2 LcdWriteCom(0x80 + 0x40); |
|
|
518 2 temp_data = userInfo.Light; |
|
|
519 2 temp_data=temp_data%10000; |
|
|
520 2 LcdWriteData(temp_data/1000+0x30); |
|
|
521 2 temp_data=temp_data%1000; |
|
|
522 2 LcdWriteData(temp_data/100+0x30); |
|
|
523 2 temp_data=temp_data%100; |
|
|
524 2 LcdWriteData(temp_data/10+0x30); |
|
|
525 2 temp_data=temp_data%10; |
|
|
526 2 LcdWriteData(temp_data+0x30); |
|
|
527 2 LcdWriteData('L'); |
|
|
528 2 LcdWriteData('x'); |
|
|
529 2 LcdWriteData(' '); |
|
|
530 2 LcdWriteData(userInfo.temp / 10 + 0x30); |
|
|
531 2 LcdWriteData(userInfo.temp % 10 + 0x30); |
|
|
532 2 LcdWriteData('C'); |
|
|
533 2 |
|
|
534 2 LcdWriteData(' '); |
|
|
535 2 LcdWriteData(userInfo.num / 10 % 10 + 0x30); |
|
|
536 2 LcdWriteData(userInfo.num % 10 + 0x30); |
|
|
537 2 }else{ |
|
|
538 2 LcdWriteCom(0x80); |
|
|
539 2 LcdWriteData('0'+ userInfo.time[0].hour/10); //时 |
|
|
540 2 LcdWriteData('0'+ userInfo.time[0].hour% 10); |
|
|
541 2 LcdWriteData(':'); |
|
|
542 2 LcdWriteData('0'+userInfo.time[0].min/10); //分 |
|
|
543 2 LcdWriteData('0'+ userInfo.time[0].min % 10); |
|
|
544 2 LcdWriteData(':'); |
|
|
545 2 LcdWriteData('0'+userInfo.time[0].sec / 10); //秒 |
|
|
546 2 LcdWriteData('0'+userInfo.time[0].sec % 10); |
|
|
547 2 LcdWriteData(' '); |
|
|
548 2 |
|
|
C51 COMPILER V9.56.0.0 MAIN 05/01/2022 12:19:19 PAGE 10 |
|
|
|
|
|
549 2 LcdWriteData('0'+cut); |
|
|
550 2 |
|
|
551 2 LcdWriteCom(0x80 + 0x40); |
|
|
552 2 LcdWriteData('0'+ userInfo.time[1].hour/10); //时 |
|
|
553 2 LcdWriteData('0'+ userInfo.time[1].hour% 10); |
|
|
554 2 LcdWriteData(':'); |
|
|
555 2 LcdWriteData('0'+userInfo.time[1].min/10); //分 |
|
|
556 2 LcdWriteData('0'+ userInfo.time[1].min % 10); |
|
|
557 2 LcdWriteData(':'); |
|
|
558 2 LcdWriteData('0'+userInfo.time[1].sec / 10); //秒 |
|
|
559 2 LcdWriteData('0'+userInfo.time[1].sec % 10); |
|
|
560 2 } |
|
|
561 1 } |
|
|
562 |
|
|
563 |
|
|
564 void Delay10ms(void) //<EFBFBD><EFBFBD><EFBFBD> 0us |
|
|
565 { |
|
|
566 1 unsigned char a,b,c; |
|
|
567 1 for(c=1;c>0;c--) |
|
|
568 1 for(b=38;b>0;b--) |
|
|
569 1 for(a=130;a>0;a--); |
|
|
570 1 } |
|
|
|
|
|
|
|
|
MODULE INFORMATION: STATIC OVERLAYABLE |
|
|
CODE SIZE = 2027 ---- |
|
|
CONSTANT SIZE = 5 ---- |
|
|
XDATA SIZE = ---- ---- |
|
|
PDATA SIZE = ---- ---- |
|
|
DATA SIZE = 38 22 |
|
|
IDATA SIZE = ---- ---- |
|
|
BIT SIZE = ---- 1 |
|
|
END OF MODULE INFORMATION. |
|
|
|
|
|
|
|
|
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
|
|
|
|