- #include "sys.h"
- #include "delay.h"
- #include "usart.h"
- #include "time.h"
- #include "adc_dma.h"
- #include "mq2.h"
- #include "mq7.h"
- #include "dht11.h"
- #include "esp8266.h"
- #include "gizwits_product.h"
- #include "Lcd_Driver.h"
- #include "GUI.h"
- #include "led.h"
- #include "sensor.h"
- u8 temperature = 20;
- u8 humidity = 20;
- float mq2 = 20;
- float mq7 = 10;
- char str[10] ={0};
- //硬件初始化
- void Hardware_Init(void)
- {
- delay_init();
- NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
- uart_init(115200); //串口初始化为115200
- ADCx_Init(); //ADC初始化
- // TIM4_Init(6000,36000-1); //定时3s
- Led_Init();
- Sensor_Init();
- Lcd_Init();
- Lcd_Clear(BLUE);
-
- // while(DHT11_Init()) //DHT11初始化
- // {
- // Gui_DrawFont_GBK16(16,30,RED,BLUE,(u8 *)"DHT11_Init FAILED");
- // delay_ms(500);
- // }
- }
- //协议初始化
- void Gizwits_Init(void)
- {
- TIM3_Int_Init(9,7199); //1MS 系统定时
- usart3_init(9600); //WIFI 初始化 波特率必须为 9600
- memset((uint8_t*)¤tDataPoint, 0, sizeof(dataPoint_t));//设备状态结构体初始化
- userInit();
- gizwitsInit();
- }
- void userHandle(void);
- void TFT_ShowTable(void);
- int main(void)
- {
- u8 t=0;
- Hardware_Init();
- Gizwits_Init();
- TFT_ShowTable();
- while(1)
- {
- gizwitsSetMode(WIFI_AIRLINK_MODE);//Air-link模式接入
- if(t%10==0) //每100ms读取一次
- {
- // DHT11_Read_Data(&temperature,&humidity); //读取温湿度值
- mq2 = MQ2_GetPPM();
- mq7 = MQ7_GetPPM();
- }
- delay_ms(10);
- t++;
- if(t==20)
- {
- t=0;
- }
- userHandle();//用户采集
- gizwitsHandle((dataPoint_t *)¤tDataPoint);//协议处理
-
- if(SENSOR_LIGHT == 1)//手头没有独立按键了,用光敏传感器代替
- {
- printf("WIFI进入AirLink连接模式\r\n");
- gizwitsSetMode(WIFI_AIRLINK_MODE);//Air-link模式接入
- }
- }
- }
- void userHandle(void)
- {
- currentDataPoint.valueValue_Tem = temperature; //Add Sensor Data Collection
- currentDataPoint.valueValue_Hum = humidity; //Add Sensor Data Collection
- currentDataPoint.valueValue_Mq7 = mq7; //Add Sensor Data Collection
- currentDataPoint.valueValue_Mq2 = mq2; //Add Sensor Data Collection
-
-
- Gui_DrawFont_GBK24(23,4,BLUE,YELLOW,(u8 *)"AIR MONITOR");
-
- sprintf(str, "MQ2: %.2fppm", mq2);
- Gui_DrawFont_GBK16(16,30,BLUE,YELLOW, (u8 *)str);
- sprintf(str, "MQ7: %.2fppm", mq7);
- Gui_DrawFont_GBK16(16,50,BLUE,YELLOW,(u8 *)str);
- sprintf(str, "TEM: %d℃", temperature);
- Gui_DrawFont_GBK16(16,70,BLUE,YELLOW,(u8 *)str);
- sprintf(str, "HUM: %d%c", humidity, '%');
- Gui_DrawFont_GBK16(16,90,BLUE,YELLOW,(u8 *)str);
-
-
- if(currentDataPoint.valueValue_Mq2 >= currentDataPoint.valueMq2_MAX)
- {
- currentDataPoint.valueWarning_Mq2 = 1;//Add Sensor Data Collection
- }
- else
- {
- currentDataPoint.valueWarning_Mq2 = 0;//Add Sensor Data Collection
- }
-
- if(currentDataPoint.valueValue_Mq7 >= currentDataPoint.valueMq7_MAX)
- {
- currentDataPoint.valueWarning_Mq7 = 1;//Add Sensor Data Collection
- }
- else
- {
- currentDataPoint.valueWarning_Mq7 = 0;//Add Sensor Data Collection
- }
-
-
- if((currentDataPoint.valueValue_Tem >= currentDataPoint.valueTem_MAX) | (currentDataPoint.valueValue_Tem <= currentDataPoint.valueTem_MIN))
- {
- currentDataPoint.valueWarning_Tem = 1;//Add Sensor Data Collection
- }
- else
- {
- currentDataPoint.valueWarning_Tem = 0;//Add Sensor Data Collection
- }
-
- if((currentDataPoint.valueWarning_Hum >= currentDataPoint.valueHum_MAX) | (currentDataPoint.valueWarning_Hum <= currentDataPoint.valueHum_MIN))
- {
- currentDataPoint.valueWarning_Hum = 1;//Add Sensor Data Collection
- }
- else
- {
- currentDataPoint.valueWarning_Hum = 0;//Add Sensor Data Collection
- }
- }
- void TFT_ShowTable(void)
- {
- Gui_DrawFont_GBK24(23,4,BLUE,YELLOW,(u8 *)"AIR MONITOR");
- DisplayButtonUp(15,28,113,46); //x1,y1,x2,y2
- DisplayButtonUp(15,48,113,66); //x1,y1,x2,y2
- DisplayButtonUp(15,68,113,86); //x1,y1,x2,y2
- DisplayButtonUp(15,88,113,106); //x1,y1,x2,y2
- }
复制代码
原理图: 无
仿真: 无
代码:
环境监测.7z
(264.33 KB, 下载次数: 60)
|