包含车内环境采集量的采集和相应的调节动作
希望能帮到在做环境自动调节项目的小伙伴
单片机源程序如下:
- #include "delay.h"
- #include "sys.h"
- #include "oled.h"
- #include "htc101.h"
- #include "dht11.h"
- #include "display.h"
- #include "PWM.h"
- #include "motor.h"
- #include "tim.h"
- #include "allcontrol.h"
- #include "ventilationsystem.h"
- u8 nowtemperature;
- u8 nowhumidity;
- u8 Ctrol_flag=0; //控制标志位
- int main(void)
- {
- delay_init(); //延时函数初始化
- OLED_Init(); //初始化OLED
- OLED_Clear(); //清屏函数
-
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
- uart_init(19200); //串口初始化为19200
- DHT11_Init(); //温湿度初始化
-
- Ventilation_GPIO_Init(); //风扇初始化
-
- MOTOR_GPIO_Config(); //电机端口初始化
- TIM3_PWM_Init(999,0); //PWM波初始化
-
- START_display(); //人机交互界面1
- short_wait();
- OLED_Clear();
- Display_5(); //人机交互界面2
-
- while(1)
- {
- //第一部分:采集数据,人机交互
- DHT11_Read_Data(&nowtemperature,&nowhumidity); //读取温湿度值
-
- Display_0(); //人机交互界面3
- OLED_ShowNum(0+40,4,nowtemperature,2,16); //显示温度
- OLED_ShowNum(0+40,6,nowhumidity,2,16); //显示湿度
- OLED_ShowNum(0+40,2,CO2_Data,4,16); //显示当前CO2值
- delay_ms(500); //防止显示闪屏
- short_wait();
-
-
- //第二部分:分析数据,自动控制
-
- if(CO2_Data<4500&&nowtemperature<26&&nowhumidity>12)
- {
- Ctrol_flag=0;
- }
- if(CO2_Data<6000&CO2_Data>4500&&nowtemperature<26&&nowhumidity>12)
- {
- Ctrol_flag=1;
- }
- if(CO2_Data>6000&&nowtemperature<26&&nowhumidity>12)
- {
- Ctrol_flag=2;
- }
- if(CO2_Data<6000&nowtemperature>26|nowhumidity<12)
- {
- Ctrol_flag=3;
- }
-
- if(CO2_Data>6000&&nowtemperature>26|nowhumidity<12)
- {
- Ctrol_flag=4;
- }
-
- if(Ctrol_flag==0)
- {
- motoroutput1(0);
- motoroutput2(0);
- motoroutput3(0);
- Ventilation_Close();
- }
-
- if(Ctrol_flag==1)
- {
- Ctrol_flag=0;
- delay_ms(500);
- motoroutput1(500);
- OLED_Clear();
- Display_1(); //人机交互界面4
- mid_wait();
- motoroutput1(0);
- Ventilation_Close();
- short_wait();
- long_wait();
- mid_wait();
- mid_wait();
- short_wait();
- short_wait();
-
- }
-
- if(Ctrol_flag==2)
- {
- Ctrol_flag=0;
- delay_ms(500);
- OLED_Clear();
- Display_2(); //人机交互界面5
- motoroutput2(200);
- motoroutput1(0);
- mid_wait();
- motoroutput2(0);
- Ventilation_Close();
- short_wait();
- big_long_wait();
- short_wait();
- short_wait();
- }
-
- if(Ctrol_flag==3)
- {
- Ctrol_flag=0;
- delay_ms(500);
- OLED_Clear();
- Display_3(); //人机交互界面6
- motoroutput1_1(200); //车窗反转
- motoroutput2_2(200);
- motoroutput3(200);
- mid_wait();
- motoroutput1_1(0);
- motoroutput2_2(0);
- Ventilation_Close();
- short_wait();
- big_long_wait();
- }
-
- if(Ctrol_flag==4)
- {
- Ctrol_flag=0;
- delay_ms(500);
- OLED_Clear();
- Display_4(); //人机交互界面7
- motoroutput1_1(200); //车窗反转
- motoroutput2_2(200);
- mid_wait();
- motoroutput1_1(0);
- motoroutput2_2(0);
- motoroutput3(200);
- Ventilation_Open();
- short_wait();
- short_wait();
- big_long_wait();
- big_long_wait();
- }
-
- // motoroutput1(500); //用于检测电机是否正常工作
- // motoroutput2(500);
- // motoroutput3(500);
- }
- }
复制代码
所有资料51hei提供下载:
汽车舒适度调节.rar
(305.4 KB, 下载次数: 16)
|