You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
2.2 KiB
121 lines
2.2 KiB
#include "led.h" |
|
#include "delay.h" |
|
#include "sys.h" |
|
#include "usart.h" |
|
#include "wifi.h" |
|
#include "dht11.h" |
|
#include "lcd1602.h" |
|
#include "adc.h" |
|
#include "timer.h" |
|
#include "string.h" |
|
#include "ds18b20.h" |
|
#include <stdio.h> |
|
#include <stdlib.h> |
|
#include <string.h> |
|
#include "motor.h" |
|
|
|
u8 humi_value,temp_value,temp_pig; |
|
u16 smog_value,beam_value; |
|
int UpperThreshold = 30; |
|
int LowerThreshold = -10; |
|
|
|
u8 temp_threshold = 10, humi_threshold = 10; |
|
u8 cleanFlag = 0x00, feedFlag = 0x00; |
|
|
|
// 用户数据的结构体 |
|
struct UserInfo{ |
|
u8 humi_value; |
|
u8 temp_value; |
|
u8 temp_pig; |
|
u8 temp_threshold; |
|
u8 humi_threshold; |
|
u8 cleanFlag; |
|
u8 feedFlag; |
|
}; |
|
|
|
void Data_Deal(void) |
|
{ |
|
DHT11_Read_Data(&temp_value,&humi_value); |
|
} |
|
|
|
void Receive_data(void) |
|
{ |
|
// 接受到数据 |
|
if(USART_RX_STA & 0x8000){ |
|
|
|
|
|
USART_RX_STA = 0x00; |
|
} |
|
} |
|
|
|
void Sys_Init(void) |
|
{ |
|
delay_init(); |
|
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); |
|
uart_init(115200); |
|
USART3_init(115200); |
|
//LED_Init(); |
|
Relay_Beep_Init(); |
|
DHT11_Init(); |
|
DS18B20_Init(); |
|
motor_Init(); |
|
} |
|
|
|
int getSum(u8 *data, int length){ |
|
int sum = 0, i = 0; |
|
for(i = 0; i < length; i++){ |
|
sum += data[i]; |
|
} |
|
return sum; |
|
} |
|
|
|
u8 deserialization(struct UserInfo *usr, u8* data, int length){ |
|
if(length != 13) return -1; |
|
if(data[length - 1] != 0x0D || data[0] != 0xFD) return -1; |
|
if(getSum(data, length - 3) != (data[length - 3] * 256 + data[length - 2])) return -1; |
|
usr->temp_value = data[3]; |
|
usr->humi_value = data[4]; |
|
usr->temp_pig = data[5]; |
|
usr->temp_threshold = data[6]; |
|
usr->humi_threshold = data[7]; |
|
usr->cleanFlag = data[8]; |
|
usr->feedFlag = data[9]; |
|
return 0; |
|
} |
|
|
|
u8 serialize(struct UserInfo *usr, u8* data, int length){ |
|
int sum = 0; |
|
if(length != 13) return -1; |
|
data[0] = 0xFD; |
|
data[1] = 0x00; |
|
data[2] = 0x01; |
|
data[3] = usr->temp_value; |
|
data[4] = usr->humi_value; |
|
data[5] = usr->temp_pig; |
|
data[6] = usr->temp_threshold; |
|
data[7] = usr->humi_threshold; |
|
data[8] = usr->cleanFlag; |
|
data[9] = usr->feedFlag; |
|
sum = getSum(data, 10); |
|
data[10] = sum >> 8; |
|
data[11] = sum & 0x00FF; |
|
data[12] = 0x0D; |
|
return 0; |
|
} |
|
|
|
int main(void) |
|
{ |
|
Sys_Init(); |
|
delay_ms(1000); |
|
Data_Deal(); |
|
while(1) |
|
{ |
|
PWM_init(); |
|
//LED_GREEN = ~LED_GREEN; |
|
Data_Deal(); |
|
Receive_data(); |
|
delay_ms(200); |
|
} |
|
} |
|
|
|
|
|
|