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