|
|
@ -27,13 +27,18 @@ struct UserInfo{ |
|
|
|
int num; |
|
|
|
int num; |
|
|
|
float light; |
|
|
|
float light; |
|
|
|
int light_threshold; |
|
|
|
int light_threshold; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int num_th1; |
|
|
|
|
|
|
|
int num_th2; |
|
|
|
|
|
|
|
int num_th3; |
|
|
|
|
|
|
|
|
|
|
|
int warn; |
|
|
|
int warn; |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
struct UserInfo userInfo; |
|
|
|
struct UserInfo userInfo; |
|
|
|
struct timing nowTime; |
|
|
|
struct timing nowTime; |
|
|
|
|
|
|
|
|
|
|
|
u8 Settime[6]={0x22,0x04,0x27,0x19,0x17,0x20}; // 设置时间 22年 03月 27日 22:34:00
|
|
|
|
u8 Settime[6]={0x22,0x04,0x27,0x19,0x17,0x00}; // 设置时间 22年 03月 27日 22:34:00
|
|
|
|
|
|
|
|
|
|
|
|
int setModel = 0; |
|
|
|
int setModel = 0; |
|
|
|
int change = 0; |
|
|
|
int change = 0; |
|
|
@ -54,6 +59,10 @@ void UserInfo_Init() |
|
|
|
userInfo.light_threshold = AT24CXX_ReadOneByte(3) * 255 + AT24CXX_ReadOneByte(4); |
|
|
|
userInfo.light_threshold = AT24CXX_ReadOneByte(3) * 255 + AT24CXX_ReadOneByte(4); |
|
|
|
userInfo.num = AT24CXX_ReadOneByte(5); |
|
|
|
userInfo.num = AT24CXX_ReadOneByte(5); |
|
|
|
userInfo.warn = 1;
|
|
|
|
userInfo.warn = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
userInfo.num_th1 = AT24CXX_ReadOneByte(6); |
|
|
|
|
|
|
|
userInfo.num_th2 = AT24CXX_ReadOneByte(7); |
|
|
|
|
|
|
|
userInfo.num_th3 = AT24CXX_ReadOneByte(8); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -90,7 +99,7 @@ void Sys_Init(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
delay_init();
|
|
|
|
delay_init();
|
|
|
|
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); |
|
|
|
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); |
|
|
|
uart_init(115200);
|
|
|
|
//uart_init(115200);
|
|
|
|
LED_Init();
|
|
|
|
LED_Init();
|
|
|
|
DS18B20_Init(); |
|
|
|
DS18B20_Init(); |
|
|
|
AT24CXX_Init(); //IIC初始化
|
|
|
|
AT24CXX_Init(); //IIC初始化
|
|
|
@ -104,7 +113,6 @@ void Sys_Init(void) |
|
|
|
bh_data_send(BHPowOn); |
|
|
|
bh_data_send(BHPowOn); |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* @description: 显示 |
|
|
|
* @description: 显示 |
|
|
|
* @param {*} |
|
|
|
* @param {*} |
|
|
@ -113,10 +121,10 @@ void Sys_Init(void) |
|
|
|
void DisplayTask(void) |
|
|
|
void DisplayTask(void) |
|
|
|
{ |
|
|
|
{ |
|
|
|
char str[60]; |
|
|
|
char str[60]; |
|
|
|
if(userInfo.model == 0) sprintf(str,"%2d-%2d %2d:%2d:%2d %0.1fLx,%dLx %d num:%d", nowTime.mon, nowTime.day, nowTime.hour, nowTime.min, \
|
|
|
|
if(userInfo.model == 0) sprintf(str,"%2d-%2d %2d:%2d:%2d %0.1fLx,%dLx %d %2d,%2d,%2d num:%2d ", nowTime.mon, nowTime.day, nowTime.hour, nowTime.min, \
|
|
|
|
nowTime.sec, userInfo.light, userInfo.light_threshold, userInfo.warn, userInfo.num); |
|
|
|
nowTime.sec, userInfo.light, userInfo.light_threshold, userInfo.warn, userInfo.num_th1,userInfo.num_th2,userInfo.num_th3 , userInfo.num); |
|
|
|
else sprintf(str,"%3dLx %2d:%2d:%2d %d", userInfo.light_threshold,userInfo.SetTimer.hour, userInfo.SetTimer.min, \
|
|
|
|
else sprintf(str,"%3dLx %2d:%2d:%2d %2d,%2d,%2d %d ", userInfo.light_threshold,userInfo.SetTimer.hour, userInfo.SetTimer.min, \
|
|
|
|
userInfo.SetTimer.sec, change); |
|
|
|
userInfo.SetTimer.sec, userInfo.num_th1,userInfo.num_th2,userInfo.num_th3, change); |
|
|
|
|
|
|
|
|
|
|
|
OLED_ShowString(0, 0, str, 16); |
|
|
|
OLED_ShowString(0, 0, str, 16); |
|
|
|
}; |
|
|
|
}; |
|
|
@ -143,7 +151,7 @@ void ChangeValue(int Value){ |
|
|
|
case 0: |
|
|
|
case 0: |
|
|
|
if(userInfo.light_threshold < 1000){ |
|
|
|
if(userInfo.light_threshold < 1000){ |
|
|
|
userInfo.light_threshold = userInfo.light_threshold * 10 + Value; |
|
|
|
userInfo.light_threshold = userInfo.light_threshold * 10 + Value; |
|
|
|
if(userInfo.light_threshold > 390) userInfo.light_threshold = 390; |
|
|
|
if(userInfo.light_threshold > 1000) userInfo.light_threshold = 1000; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 1: |
|
|
|
case 1: |
|
|
@ -164,6 +172,24 @@ void ChangeValue(int Value){ |
|
|
|
if(userInfo.SetTimer.sec > 59) userInfo.SetTimer.sec = 59; |
|
|
|
if(userInfo.SetTimer.sec > 59) userInfo.SetTimer.sec = 59; |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
case 4: |
|
|
|
|
|
|
|
if(userInfo.num_th1 < 10){ |
|
|
|
|
|
|
|
userInfo.num_th1 = userInfo.num_th1 * 10 + Value; |
|
|
|
|
|
|
|
if(userInfo.num_th1 > 99) userInfo.num_th1 = 99; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 5: |
|
|
|
|
|
|
|
if(userInfo.num_th2 < 10){ |
|
|
|
|
|
|
|
userInfo.num_th2 = userInfo.num_th2 * 10 + Value; |
|
|
|
|
|
|
|
if(userInfo.num_th2 > 99) userInfo.num_th2 = 99; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 6: |
|
|
|
|
|
|
|
if(userInfo.num_th3 < 10){ |
|
|
|
|
|
|
|
userInfo.num_th3 = userInfo.num_th3 * 10 + Value; |
|
|
|
|
|
|
|
if(userInfo.num_th3 > 99) userInfo.num_th3 = 99; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -188,6 +214,15 @@ void DeleteValue() |
|
|
|
case 3: |
|
|
|
case 3: |
|
|
|
userInfo.SetTimer.sec /= 10; |
|
|
|
userInfo.SetTimer.sec /= 10; |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
case 4: |
|
|
|
|
|
|
|
userInfo.num_th1 /= 10; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 5: |
|
|
|
|
|
|
|
userInfo.num_th2 /= 10; |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case 6: |
|
|
|
|
|
|
|
userInfo.num_th3 /= 10; |
|
|
|
|
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -197,18 +232,21 @@ void DeleteValue() |
|
|
|
* @return {*} |
|
|
|
* @return {*} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void keyHandling(){ |
|
|
|
void keyHandling(){ |
|
|
|
|
|
|
|
static int flag = 0; |
|
|
|
int key = 16; |
|
|
|
int key = 16; |
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
key = Key_Scan(); |
|
|
|
key = Key_Scan(); |
|
|
|
switch (key) |
|
|
|
switch (key) |
|
|
|
{ |
|
|
|
{ |
|
|
|
case 12: |
|
|
|
case 12: |
|
|
|
userInfo.model++; |
|
|
|
userInfo.model++; |
|
|
|
if(userInfo.model >= 2) userInfo.model = 0; |
|
|
|
if(userInfo.model >= 2) userInfo.model = 0; |
|
|
|
|
|
|
|
change = 0; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 13: |
|
|
|
case 13: |
|
|
|
if(userInfo.model == 0) break; |
|
|
|
if(userInfo.model == 0) break; |
|
|
|
change++; |
|
|
|
change++; |
|
|
|
if(change >= 4) change = 0; |
|
|
|
if(change >= 7) change = 0; |
|
|
|
break; |
|
|
|
break; |
|
|
|
case 14: |
|
|
|
case 14: |
|
|
|
if(userInfo.warn == 0) userInfo.warn = 1; |
|
|
|
if(userInfo.warn == 0) userInfo.warn = 1; |
|
|
@ -226,14 +264,43 @@ void keyHandling(){ |
|
|
|
OLED_Clear(); |
|
|
|
OLED_Clear(); |
|
|
|
Warning(); |
|
|
|
Warning(); |
|
|
|
} |
|
|
|
} |
|
|
|
key = KEY_Scan(0); |
|
|
|
|
|
|
|
if(key == IN_PRES){ |
|
|
|
if(IN == 0){ |
|
|
|
|
|
|
|
delay_ms(10); |
|
|
|
|
|
|
|
if(IN == 0){ |
|
|
|
|
|
|
|
if(flag == 3) flag = 4; |
|
|
|
|
|
|
|
else if(flag == 0) flag = 1; |
|
|
|
|
|
|
|
else flag = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
while((i<50)&&(IN==0)){ |
|
|
|
|
|
|
|
delay_ms(10); |
|
|
|
|
|
|
|
i++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
i=0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(OUT == 0){ |
|
|
|
|
|
|
|
delay_ms(10); |
|
|
|
|
|
|
|
if(OUT == 0){ |
|
|
|
|
|
|
|
if(flag == 1) flag = 2; |
|
|
|
|
|
|
|
else if(flag == 0) flag = 3; |
|
|
|
|
|
|
|
else flag = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
while((i<50)&&(OUT==0)){ |
|
|
|
|
|
|
|
delay_ms(10); |
|
|
|
|
|
|
|
i++; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
i=0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(flag == 2){ |
|
|
|
userInfo.num++; |
|
|
|
userInfo.num++; |
|
|
|
if(userInfo.num >= 99) userInfo.num = 99; |
|
|
|
if(userInfo.num >= 99) userInfo.num = 99; |
|
|
|
}
|
|
|
|
flag = 0; |
|
|
|
else if(key == OUT_PRES){ |
|
|
|
}else if(flag == 4){ |
|
|
|
userInfo.num--; |
|
|
|
userInfo.num--; |
|
|
|
if(userInfo.num < 0) userInfo.num = 0; |
|
|
|
if(userInfo.num < 0) userInfo.num = 0; |
|
|
|
|
|
|
|
flag = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -246,6 +313,7 @@ void keyHandling(){ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
void TaskProcessing() |
|
|
|
void TaskProcessing() |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
static int flag = 0,min = 0, sec = 0; |
|
|
|
int x=0, pwm; //bh1750模块获取到的数据
|
|
|
|
int x=0, pwm; //bh1750模块获取到的数据
|
|
|
|
bh_data_send(BHReset); |
|
|
|
bh_data_send(BHReset); |
|
|
|
bh_data_send(BHModeH1);
|
|
|
|
bh_data_send(BHModeH1);
|
|
|
@ -255,19 +323,43 @@ void TaskProcessing() |
|
|
|
|
|
|
|
|
|
|
|
keyHandling(); |
|
|
|
keyHandling(); |
|
|
|
|
|
|
|
|
|
|
|
PWMA = userInfo.light_threshold * 1.3; |
|
|
|
if(userInfo.warn == 0) flag = 0; |
|
|
|
|
|
|
|
|
|
|
|
// 超过时间报警
|
|
|
|
// 超过时间报警
|
|
|
|
if(getTimerResult()){ |
|
|
|
if(getTimerResult() && userInfo.warn){ |
|
|
|
|
|
|
|
if(flag == 0) { |
|
|
|
|
|
|
|
min = userInfo.SetTimer.min + 1; |
|
|
|
|
|
|
|
sec = userInfo.SetTimer.sec; |
|
|
|
|
|
|
|
if(min >= 60){ |
|
|
|
|
|
|
|
min = min - 60; |
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
flag = 1; |
|
|
|
|
|
|
|
}else{ |
|
|
|
|
|
|
|
if(min == nowTime.min && sec == nowTime.sec){ |
|
|
|
|
|
|
|
userInfo.warn = 0; |
|
|
|
|
|
|
|
flag = 0; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if(userInfo.warn) Warning(); |
|
|
|
if(userInfo.warn) Warning(); |
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LED0 = 0; |
|
|
|
|
|
|
|
LED1 = 0; |
|
|
|
|
|
|
|
LED2 = 0; |
|
|
|
|
|
|
|
if(userInfo.num >= userInfo.num_th1) LED0 = 1; |
|
|
|
|
|
|
|
if(userInfo.num >= userInfo.num_th2) LED1 = 1; |
|
|
|
|
|
|
|
if(userInfo.num >= userInfo.num_th3) LED2 = 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(userInfo.light > userInfo.light_threshold) LED0 = 0,LED1 = 0,LED2 = 0; |
|
|
|
|
|
|
|
|
|
|
|
AT24CXX_WriteOneByte(0, userInfo.SetTimer.hour); |
|
|
|
AT24CXX_WriteOneByte(0, userInfo.SetTimer.hour); |
|
|
|
AT24CXX_WriteOneByte(1, userInfo.SetTimer.min); |
|
|
|
AT24CXX_WriteOneByte(1, userInfo.SetTimer.min); |
|
|
|
AT24CXX_WriteOneByte(2, userInfo.SetTimer.sec); |
|
|
|
AT24CXX_WriteOneByte(2, userInfo.SetTimer.sec); |
|
|
|
AT24CXX_WriteOneByte(3, userInfo.light_threshold >> 8); |
|
|
|
AT24CXX_WriteOneByte(3, userInfo.light_threshold >> 8); |
|
|
|
AT24CXX_WriteOneByte(4, userInfo.light_threshold & 0x00FF); |
|
|
|
AT24CXX_WriteOneByte(4, userInfo.light_threshold & 0x00FF); |
|
|
|
AT24CXX_WriteOneByte(5, userInfo.num); |
|
|
|
AT24CXX_WriteOneByte(5, userInfo.num); |
|
|
|
|
|
|
|
AT24CXX_WriteOneByte(6, userInfo.num_th1); |
|
|
|
|
|
|
|
AT24CXX_WriteOneByte(7, userInfo.num_th2); |
|
|
|
|
|
|
|
AT24CXX_WriteOneByte(8, userInfo.num_th3); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|