|
包含車內(nèi)環(huán)境采集量的采集和相應(yīng)的調(diào)節(jié)動(dòng)作
希望能幫到在做環(huán)境自動(dòng)調(diào)節(jié)項(xiàng)目的小伙伴
單片機(jī)源程序如下:
- #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; //控制標(biāo)志位
- int main(void)
- {
- delay_init(); //延時(shí)函數(shù)初始化
- OLED_Init(); //初始化OLED
- OLED_Clear(); //清屏函數(shù)
-
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //設(shè)置NVIC中斷分組2:2位搶占優(yōu)先級(jí),2位響應(yīng)優(yōu)先級(jí)
- uart_init(19200); //串口初始化為19200
- DHT11_Init(); //溫濕度初始化
-
- Ventilation_GPIO_Init(); //風(fēng)扇初始化
-
- MOTOR_GPIO_Config(); //電機(jī)端口初始化
- TIM3_PWM_Init(999,0); //PWM波初始化
-
- START_display(); //人機(jī)交互界面1
- short_wait();
- OLED_Clear();
- Display_5(); //人機(jī)交互界面2
-
- while(1)
- {
- //第一部分:采集數(shù)據(jù),人機(jī)交互
- DHT11_Read_Data(&nowtemperature,&nowhumidity); //讀取溫濕度值
-
- Display_0(); //人機(jī)交互界面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); //顯示當(dāng)前CO2值
- delay_ms(500); //防止顯示閃屏
- short_wait();
-
-
- //第二部分:分析數(shù)據(jù),自動(dòng)控制
-
- 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(); //人機(jī)交互界面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(); //人機(jī)交互界面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(); //人機(jī)交互界面6
- motoroutput1_1(200); //車窗反轉(zhuǎn)
- 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(); //人機(jī)交互界面7
- motoroutput1_1(200); //車窗反轉(zhuǎn)
- 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); //用于檢測(cè)電機(jī)是否正常工作
- // motoroutput2(500);
- // motoroutput3(500);
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
汽車舒適度調(diào)節(jié).rar
(305.4 KB, 下載次數(shù): 16)
2018-5-16 00:19 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
|
評(píng)分
-
查看全部評(píng)分
|