|
|
|
|
C51 COMPILER V9.56.0.0 MAIN 05/05/2022 19:42:13 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/05/2022 19:42:13 PAGE 2
|
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
57 void LcdDisplay();
|
|
|
|
|
58 void LcdDisplay1();
|
|
|
|
|
59 void Delay10ms(void);
|
|
|
|
|
60
|
|
|
|
|
61 #define SlaveAddress 0x46 //定义器件在IIC总线中的从地址,根据ALT ADDRESS地址引脚不<EFBFBD>
|
|
|
|
|
-<EFBFBD><EFBFBD>修改
|
|
|
|
|
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--);
|
|
|
|
|
115 1 }
|
|
|
|
|
116
|
|
|
|
|
C51 COMPILER V9.56.0.0 MAIN 05/05/2022 19:42:13 PAGE 3
|
|
|
|
|
|
|
|
|
|
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 SDA = ack; //写应答信号
|
|
|
|
|
149 1 SCL = 1; //拉高时钟线
|
|
|
|
|
150 1 Delay5us(); //延时
|
|
|
|
|
151 1 SCL = 0; //拉低时钟线
|
|
|
|
|
152 1 Delay5us(); //延时
|
|
|
|
|
153 1 }
|
|
|
|
|
154
|
|
|
|
|
155 /**************************************
|
|
|
|
|
156 接收应答信号
|
|
|
|
|
157 **************************************/
|
|
|
|
|
158 bit BH1750_RecvACK()
|
|
|
|
|
159 {
|
|
|
|
|
160 1 SCL = 1; //拉高时钟线
|
|
|
|
|
161 1 Delay5us(); //延时
|
|
|
|
|
162 1 CY = SDA; //读应答信号
|
|
|
|
|
163 1 SCL = 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位计数器
|
|
|
|
|
177 1 {
|
|
|
|
|
178 2 dat <<= 1; //移出数据的最高位
|
|
|
|
|
C51 COMPILER V9.56.0.0 MAIN 05/05/2022 19:42:13 PAGE 4
|
|
|
|
|
|
|
|
|
|
179 2 SDA = CY; //送数据口
|
|
|
|
|
180 2 SCL = 1; //拉高时钟线
|
|
|
|
|
181 2 Delay5us(); //延时
|
|
|
|
|
182 2 SCL = 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 SDA = 1; //使能内部上拉,准备读取数据,
|
|
|
|
|
197 1 for (i=0; i<8; i++) //8位计数器
|
|
|
|
|
198 1 {
|
|
|
|
|
199 2 dat <<= 1;
|
|
|
|
|
200 2 SCL = 1; //拉高时钟线
|
|
|
|
|
201 2 Delay5us(); //延时
|
|
|
|
|
202 2 dat |= SDA; //读数据
|
|
|
|
|
203 2 SCL = 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 //*********************************************************
|
|
|
|
|
223 //
|
|
|
|
|
224 //连续读出BH1750内部数据
|
|
|
|
|
225 //
|
|
|
|
|
226 //*********************************************************
|
|
|
|
|
227 void Multiple_read_BH1750(void)
|
|
|
|
|
228
|
|
|
|
|
229 { uchar i;
|
|
|
|
|
230 1 BH1750_Start(); //起始信号
|
|
|
|
|
231 1 BH1750_SendByte(SlaveAddress+1); //发送设备地址+读信号
|
|
|
|
|
232 1
|
|
|
|
|
233 1 for (i=0; i<3; i++) //连续读取2个地址数据,存储中BUF
|
|
|
|
|
234 1 {
|
|
|
|
|
235 2 BUF[i] = BH1750_RecvByte(); //BUF[0]存储0x32地址中的数据
|
|
|
|
|
236 2 if (i == 3)
|
|
|
|
|
237 2 {
|
|
|
|
|
238 3
|
|
|
|
|
239 3 BH1750_SendACK(1); //最后一个数据需要回NOACK
|
|
|
|
|
240 3 }
|
|
|
|
|
C51 COMPILER V9.56.0.0 MAIN 05/05/2022 19:42:13 PAGE 5
|
|
|
|
|
|
|
|
|
|
241 2 else
|
|
|
|
|
242 2 {
|
|
|
|
|
243 3 BH1750_SendACK(0); //回应ACK
|
|
|
|
|
244 3 }
|
|
|
|
|
245 2 }
|
|
|
|
|
246 1
|
|
|
|
|
247 1 BH1750_Stop(); //停止信号
|
|
|
|
|
248 1 Delay5ms();
|
|
|
|
|
249 1 }
|
|
|
|
|
250
|
|
|
|
|
251
|
|
|
|
|
252 //初始化BH1750
|
|
|
|
|
253 void Init_BH1750()
|
|
|
|
|
254 {
|
|
|
|
|
255 1 Single_Write_BH1750(0x01);
|
|
|
|
|
256 1
|
|
|
|
|
257 1 }
|
|
|
|
|
258
|
|
|
|
|
259 // 串口初始化
|
|
|
|
|
260 void Uart_Init()
|
|
|
|
|
261 {
|
|
|
|
|
262 1 TMOD = 0x20 | 0x01;
|
|
|
|
|
263 1 SCON = 0x50;
|
|
|
|
|
264 1 TH1 = 0xFD;
|
|
|
|
|
265 1 TL1 = TH1;
|
|
|
|
|
266 1 PCON = 0x00;
|
|
|
|
|
267 1 EA = 1;
|
|
|
|
|
268 1 ES = 1;
|
|
|
|
|
269 1 TR1 = 1;
|
|
|
|
|
270 1 }
|
|
|
|
|
271
|
|
|
|
|
272 void us_delay(uchar t)
|
|
|
|
|
273 {
|
|
|
|
|
274 1 while(t--);
|
|
|
|
|
275 1 }
|
|
|
|
|
276
|
|
|
|
|
277 void Send_Uart(uchar value)
|
|
|
|
|
278 {
|
|
|
|
|
279 1 ES=0;
|
|
|
|
|
280 1 TI=0;
|
|
|
|
|
281 1 SBUF=value;
|
|
|
|
|
282 1 while(TI==0);
|
|
|
|
|
283 1 TI=0;
|
|
|
|
|
284 1 ES=1;
|
|
|
|
|
285 1 }
|
|
|
|
|
286
|
|
|
|
|
287 void Bluetooth_Set(uchar *puf)
|
|
|
|
|
288 {
|
|
|
|
|
289 1 while(*puf!='\0')
|
|
|
|
|
290 1 {
|
|
|
|
|
291 2 Send_Uart(*puf);
|
|
|
|
|
292 2 us_delay(5);
|
|
|
|
|
293 2 puf++;
|
|
|
|
|
294 2 }
|
|
|
|
|
295 1 }
|
|
|
|
|
296
|
|
|
|
|
297
|
|
|
|
|
298 // 获取数据
|
|
|
|
|
299 void Detection()
|
|
|
|
|
300 {
|
|
|
|
|
301 1 static int num = 0;
|
|
|
|
|
302 1 int i = 0;
|
|
|
|
|
C51 COMPILER V9.56.0.0 MAIN 05/05/2022 19:42:13 PAGE 6
|
|
|
|
|
|
|
|
|
|
303 1 Single_Write_BH1750(0x01);
|
|
|
|
|
304 1 Single_Write_BH1750(0x10);
|
|
|
|
|
305 1 delay_nms(180);
|
|
|
|
|
306 1 Multiple_Read_BH1750();
|
|
|
|
|
307 1 dis_data=BUF[0];
|
|
|
|
|
308 1 dis_data=(dis_data<<8)+BUF[1];
|
|
|
|
|
309 1 userInfo.Light = (float)dis_data/1.2; // 获取光照值
|
|
|
|
|
310 1
|
|
|
|
|
311 1 userInfo.temp = Temper_change();
|
|
|
|
|
312 1 userInfo.temp /= 100; // 获取温度,去除小数部分
|
|
|
|
|
313 1
|
|
|
|
|
314 1 // 按键一
|
|
|
|
|
315 1 if(key1==0)
|
|
|
|
|
316 1 {
|
|
|
|
|
317 2 Delay10ms();
|
|
|
|
|
318 2 if(key1==0){
|
|
|
|
|
319 3 if(userInfo.set == 0){
|
|
|
|
|
320 4 if(userInfo.model == 0) userInfo.model = 1;
|
|
|
|
|
321 4 else userInfo.model = 0;
|
|
|
|
|
322 4 if(userInfo.model == 1) LED4 = 1, LED5 = 0;
|
|
|
|
|
323 4 else LED4 = 0, LED5 = 1;
|
|
|
|
|
324 4 }
|
|
|
|
|
325 3 }
|
|
|
|
|
326 2 while((i<50)&&(key1==0)){
|
|
|
|
|
327 3 Delay10ms();
|
|
|
|
|
328 3 i++;
|
|
|
|
|
329 3 }
|
|
|
|
|
330 2 i=0;
|
|
|
|
|
331 2 }
|
|
|
|
|
332 1
|
|
|
|
|
333 1 // 按键二
|
|
|
|
|
334 1 if(key2==0)
|
|
|
|
|
335 1 {
|
|
|
|
|
336 2 Delay10ms();
|
|
|
|
|
337 2 if(key2==0){
|
|
|
|
|
338 3 if(userInfo.model){
|
|
|
|
|
339 4 led_num++;
|
|
|
|
|
340 4 if(led_num >= 5) led_num = 0;
|
|
|
|
|
341 4 }else{
|
|
|
|
|
342 4 if(userInfo.set == 0) userInfo.set = 1;
|
|
|
|
|
343 4 else userInfo.set = 0;
|
|
|
|
|
344 4 cut = 0;
|
|
|
|
|
345 4 }
|
|
|
|
|
346 3 LcdWriteCom(0x01); //清屏
|
|
|
|
|
347 3 }
|
|
|
|
|
348 2 while((i<50)&&(key2==0)){
|
|
|
|
|
349 3 Delay10ms();
|
|
|
|
|
350 3 i++;
|
|
|
|
|
351 3 }
|
|
|
|
|
352 2 i=0;
|
|
|
|
|
353 2 }
|
|
|
|
|
354 1
|
|
|
|
|
355 1 if(IN==0) // 光电门 进
|
|
|
|
|
356 1 {
|
|
|
|
|
357 2 Delay10ms();
|
|
|
|
|
358 2 if(IN==0){ // 去抖
|
|
|
|
|
359 3 userInfo.num++;
|
|
|
|
|
360 3 if(userInfo.num > 99) userInfo.num = 99;
|
|
|
|
|
361 3 }
|
|
|
|
|
362 2 while((i<50)&&(IN==0)){
|
|
|
|
|
363 3 Delay10ms();
|
|
|
|
|
364 3 i++;
|
|
|
|
|
C51 COMPILER V9.56.0.0 MAIN 05/05/2022 19:42:13 PAGE 7
|
|
|
|
|
|
|
|
|
|
365 3 }
|
|
|
|
|
366 2 i=0;
|
|
|
|
|
367 2 }
|
|
|
|
|
368 1
|
|
|
|
|
369 1
|
|
|
|
|
370 1 if(OUT==0) // 光电门 出
|
|
|
|
|
371 1 {
|
|
|
|
|
372 2 Delay10ms();
|
|
|
|
|
373 2 if(OUT==0){ // 去抖
|
|
|
|
|
374 3 userInfo.num--;
|
|
|
|
|
375 3 if(userInfo.num < 0) userInfo.num = 0;
|
|
|
|
|
376 3 }
|
|
|
|
|
377 2 while((i<50)&&(OUT==0)){
|
|
|
|
|
378 3 Delay10ms();
|
|
|
|
|
379 3 i++;
|
|
|
|
|
380 3 }
|
|
|
|
|
381 2 i=0;
|
|
|
|
|
382 2 }
|
|
|
|
|
383 1
|
|
|
|
|
384 1
|
|
|
|
|
385 1 if(key3==0) // 按键3
|
|
|
|
|
386 1 {
|
|
|
|
|
387 2 Delay10ms();
|
|
|
|
|
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 // 按键四
|
|
|
|
|
400 1 if(key4==0)
|
|
|
|
|
401 1 {
|
|
|
|
|
402 2 Delay10ms();
|
|
|
|
|
403 2 if(key4==0){
|
|
|
|
|
404 3 // 根据cut的值,修改不同的对象
|
|
|
|
|
405 3 if(cut == 0){
|
|
|
|
|
406 4 userInfo.time[0].hour++;
|
|
|
|
|
407 4 if(userInfo.time[0].hour >= 24) userInfo.time[0].hour = 0;
|
|
|
|
|
408 4 }else if(cut == 1){
|
|
|
|
|
409 4 userInfo.time[0].min++;
|
|
|
|
|
410 4 if(userInfo.time[0].min >= 59) userInfo.time[0].min = 0;
|
|
|
|
|
411 4 }else if(cut == 2){
|
|
|
|
|
412 4 userInfo.time[1].hour++;
|
|
|
|
|
413 4 if(userInfo.time[1].hour >= 24) userInfo.time[1].hour = 0;
|
|
|
|
|
414 4 }else if(cut == 3){
|
|
|
|
|
415 4 userInfo.time[1].min++;
|
|
|
|
|
416 4 if(userInfo.time[1].min >= 59) userInfo.time[1].min = 0;
|
|
|
|
|
417 4 }
|
|
|
|
|
418 3 while((i<50)&&(key4==0)){
|
|
|
|
|
419 4 Delay10ms();
|
|
|
|
|
420 4 i++;
|
|
|
|
|
421 4 }
|
|
|
|
|
422 3 i=0;
|
|
|
|
|
423 3 }
|
|
|
|
|
424 2 }
|
|
|
|
|
425 1 }
|
|
|
|
|
*** WARNING C280 IN LINE 301 OF main.c: 'num': unreferenced local variable
|
|
|
|
|
C51 COMPILER V9.56.0.0 MAIN 05/05/2022 19:42:13 PAGE 8
|
|
|
|
|
|
|
|
|
|
426
|
|
|
|
|
427
|
|
|
|
|
428 // 获取时间是否达到 返回1为定时时间到
|
|
|
|
|
429 int getTimeResult()
|
|
|
|
|
430 {
|
|
|
|
|
431 1 int result = 1;
|
|
|
|
|
432 1 struct Time Nowtime;
|
|
|
|
|
433 1
|
|
|
|
|
434 1 Nowtime.hour = TIME[2]/16 * 10 + (TIME[2]&0x0f);
|
|
|
|
|
435 1 Nowtime.min = TIME[1]/16 * 10 + (TIME[1]&0x0f);
|
|
|
|
|
436 1
|
|
|
|
|
437 1 if(Nowtime.hour < userInfo.time[0].hour || Nowtime.hour > userInfo.time[1].hour) return 0;
|
|
|
|
|
438 1 if(Nowtime.hour == userInfo.time[0].hour && Nowtime.min < userInfo.time[0].min) return 0;
|
|
|
|
|
439 1 if(Nowtime.hour == userInfo.time[1].hour && Nowtime.min > userInfo.time[1].min) return 0;
|
|
|
|
|
440 1
|
|
|
|
|
441 1 return result;
|
|
|
|
|
442 1 }
|
|
|
|
|
443
|
|
|
|
|
444
|
|
|
|
|
445 // 点灯
|
|
|
|
|
446 void Dispose()
|
|
|
|
|
447 {
|
|
|
|
|
448 1
|
|
|
|
|
449 1 if(userInfo.model == 0){
|
|
|
|
|
450 2 if(getTimeResult() && userInfo.Light < 100){
|
|
|
|
|
451 3 if(userInfo.num < 10 && userInfo.num > 0) LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 1;
|
|
|
|
|
452 3 else if(userInfo.num >= 10 && userInfo.num < 20) LED0 = 0, LED1 = 0, LED2 = 1 ,LED3 = 1;
|
|
|
|
|
453 3 else if(userInfo.num >= 20 && userInfo.num < 30) LED0 = 0, LED1 = 1, LED2 = 1 ,LED3 = 1;
|
|
|
|
|
454 3 else if(userInfo.num >= 30) LED0 = 1, LED1 = 1, LED2 = 1 ,LED3 = 1;
|
|
|
|
|
455 3 else LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 0;
|
|
|
|
|
456 3 }else{
|
|
|
|
|
457 3 LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 0;
|
|
|
|
|
458 3 }
|
|
|
|
|
459 2 }else{
|
|
|
|
|
460 2 if(led_num){
|
|
|
|
|
461 3 if(led_num == 1) LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 1;
|
|
|
|
|
462 3 else if(led_num == 2) LED0 = 0, LED1 = 0, LED2 = 1 ,LED3 = 1;
|
|
|
|
|
463 3 else if(led_num == 3) LED0 = 0, LED1 = 1, LED2 = 1 ,LED3 = 1;
|
|
|
|
|
464 3 else if(led_num == 4) LED0 = 1, LED1 = 1, LED2 = 1 ,LED3 = 1;
|
|
|
|
|
465 3 }else{
|
|
|
|
|
466 3 LED0 = 0, LED1 = 0, LED2 = 0 ,LED3 = 0;
|
|
|
|
|
467 3 }
|
|
|
|
|
468 2 }
|
|
|
|
|
469 1 LED4 = userInfo.model;
|
|
|
|
|
470 1 }
|
|
|
|
|
471
|
|
|
|
|
472 // main
|
|
|
|
|
473 void main()
|
|
|
|
|
474 {
|
|
|
|
|
475 1 int i = 0;
|
|
|
|
|
476 1 uchar str[10];
|
|
|
|
|
477 1 Ds1302Init(); // 时钟初始化
|
|
|
|
|
478 1 Uart_Init();
|
|
|
|
|
479 1 LcdInit(); // lcd初始化
|
|
|
|
|
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;
|
|
|
|
|
486 1 userInfo.time[1].min = 30;
|
|
|
|
|
487 1 userInfo.time[1].sec = 0;
|
|
|
|
|
C51 COMPILER V9.56.0.0 MAIN 05/05/2022 19:42:13 PAGE 9
|
|
|
|
|
|
|
|
|
|
488 1
|
|
|
|
|
489 1 while(1)
|
|
|
|
|
490 1 {
|
|
|
|
|
491 2 Ds1302ReadTime(); // 读取时间
|
|
|
|
|
492 2 LcdDisplay();
|
|
|
|
|
493 2 Detection();
|
|
|
|
|
494 2 Dispose();
|
|
|
|
|
495 2 }
|
|
|
|
|
496 1 }
|
|
|
|
|
*** WARNING C280 IN LINE 476 OF main.c: 'str': unreferenced local variable
|
|
|
|
|
497
|
|
|
|
|
498 // 显示
|
|
|
|
|
499 void LcdDisplay()
|
|
|
|
|
500 {
|
|
|
|
|
501 1 uint temp_data;
|
|
|
|
|
502 1 if(userInfo.set == 0){
|
|
|
|
|
503 2 // TODO 显示时间
|
|
|
|
|
504 2 LcdWriteCom(0x80);
|
|
|
|
|
505 2 LcdWriteData('0'+TIME[4]/16); //月
|
|
|
|
|
506 2 LcdWriteData('0'+(TIME[4]&0x0f));
|
|
|
|
|
507 2 LcdWriteData('-');
|
|
|
|
|
508 2 LcdWriteData('0'+TIME[3]/16); //日
|
|
|
|
|
509 2 LcdWriteData('0'+(TIME[3]&0x0f));
|
|
|
|
|
510 2 LcdWriteData(' ');
|
|
|
|
|
511 2
|
|
|
|
|
512 2 LcdWriteData('0'+TIME[2]/16); //时
|
|
|
|
|
513 2 LcdWriteData('0'+(TIME[2]&0x0f));
|
|
|
|
|
514 2 LcdWriteData(':');
|
|
|
|
|
515 2 LcdWriteData('0'+TIME[1]/16); //分
|
|
|
|
|
516 2 LcdWriteData('0'+(TIME[1]&0x0f));
|
|
|
|
|
517 2 LcdWriteData(':');
|
|
|
|
|
518 2 LcdWriteData('0'+TIME[0]/16); //秒
|
|
|
|
|
519 2 LcdWriteData('0'+(TIME[0]&0x0f));
|
|
|
|
|
520 2
|
|
|
|
|
521 2 LcdWriteData(' ');
|
|
|
|
|
522 2 LcdWriteData('0'+(TIME[5]&0x0f));
|
|
|
|
|
523 2
|
|
|
|
|
524 2 LcdWriteCom(0x80 + 0x40);
|
|
|
|
|
525 2 temp_data = userInfo.Light;
|
|
|
|
|
526 2 temp_data=temp_data%10000;
|
|
|
|
|
527 2 LcdWriteData(temp_data/1000+0x30);
|
|
|
|
|
528 2 temp_data=temp_data%1000;
|
|
|
|
|
529 2 LcdWriteData(temp_data/100+0x30);
|
|
|
|
|
530 2 temp_data=temp_data%100;
|
|
|
|
|
531 2 LcdWriteData(temp_data/10+0x30);
|
|
|
|
|
532 2 temp_data=temp_data%10;
|
|
|
|
|
533 2 LcdWriteData(temp_data+0x30);
|
|
|
|
|
534 2 LcdWriteData('L');
|
|
|
|
|
535 2 LcdWriteData('x');
|
|
|
|
|
536 2 LcdWriteData(' ');
|
|
|
|
|
537 2 LcdWriteData(userInfo.temp / 10 + 0x30);
|
|
|
|
|
538 2 LcdWriteData(userInfo.temp % 10 + 0x30);
|
|
|
|
|
539 2 LcdWriteData('C');
|
|
|
|
|
540 2
|
|
|
|
|
541 2 LcdWriteData(' ');
|
|
|
|
|
542 2 LcdWriteData(userInfo.num / 10 % 10 + 0x30);
|
|
|
|
|
543 2 LcdWriteData(userInfo.num % 10 + 0x30);
|
|
|
|
|
544 2 }else{
|
|
|
|
|
545 2 LcdWriteCom(0x80);
|
|
|
|
|
546 2 LcdWriteData('0'+ userInfo.time[0].hour/10); //时
|
|
|
|
|
547 2 LcdWriteData('0'+ userInfo.time[0].hour% 10);
|
|
|
|
|
548 2 LcdWriteData(':');
|
|
|
|
|
C51 COMPILER V9.56.0.0 MAIN 05/05/2022 19:42:13 PAGE 10
|
|
|
|
|
|
|
|
|
|
549 2 LcdWriteData('0'+userInfo.time[0].min/10); //分
|
|
|
|
|
550 2 LcdWriteData('0'+ userInfo.time[0].min % 10);
|
|
|
|
|
551 2 LcdWriteData(':');
|
|
|
|
|
552 2 LcdWriteData('0'+userInfo.time[0].sec / 10); //秒
|
|
|
|
|
553 2 LcdWriteData('0'+userInfo.time[0].sec % 10);
|
|
|
|
|
554 2 LcdWriteData(' ');
|
|
|
|
|
555 2
|
|
|
|
|
556 2 LcdWriteData('0'+cut);
|
|
|
|
|
557 2
|
|
|
|
|
558 2 LcdWriteCom(0x80 + 0x40);
|
|
|
|
|
559 2 LcdWriteData('0'+ userInfo.time[1].hour/10); //时
|
|
|
|
|
560 2 LcdWriteData('0'+ userInfo.time[1].hour% 10);
|
|
|
|
|
561 2 LcdWriteData(':');
|
|
|
|
|
562 2 LcdWriteData('0'+userInfo.time[1].min/10); //分
|
|
|
|
|
563 2 LcdWriteData('0'+ userInfo.time[1].min % 10);
|
|
|
|
|
564 2 LcdWriteData(':');
|
|
|
|
|
565 2 LcdWriteData('0'+userInfo.time[1].sec / 10); //秒
|
|
|
|
|
566 2 LcdWriteData('0'+userInfo.time[1].sec % 10);
|
|
|
|
|
567 2 }
|
|
|
|
|
568 1 }
|
|
|
|
|
569
|
|
|
|
|
570
|
|
|
|
|
571 void Delay10ms(void) //<EFBFBD><EFBFBD><EFBFBD> 0us
|
|
|
|
|
572 {
|
|
|
|
|
573 1 unsigned char a,b,c;
|
|
|
|
|
574 1 for(c=1;c>0;c--)
|
|
|
|
|
575 1 for(b=38;b>0;b--)
|
|
|
|
|
576 1 for(a=130;a>0;a--);
|
|
|
|
|
577 1 }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
MODULE INFORMATION: STATIC OVERLAYABLE
|
|
|
|
|
CODE SIZE = 2049 ----
|
|
|
|
|
CONSTANT SIZE = ---- ----
|
|
|
|
|
XDATA SIZE = ---- ----
|
|
|
|
|
PDATA SIZE = ---- ----
|
|
|
|
|
DATA SIZE = 42 22
|
|
|
|
|
IDATA SIZE = ---- ----
|
|
|
|
|
BIT SIZE = ---- 1
|
|
|
|
|
END OF MODULE INFORMATION.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
C51 COMPILATION COMPLETE. 2 WARNING(S), 0 ERROR(S)
|