找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1601|回复: 1
打印 上一主题 下一主题
收起左侧

发表一个汽车车内环境自动调控的stm32工程代码

[复制链接]
跳转到指定楼层
楼主
ID:311897 发表于 2018-5-15 21:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
包含车内环境采集量的采集和相应的调节动作
希望能帮到在做环境自动调节项目的小伙伴

单片机源程序如下:
  1. #include "delay.h"
  2. #include "sys.h"
  3. #include "oled.h"
  4. #include "htc101.h"
  5. #include "dht11.h"
  6. #include "display.h"
  7. #include "PWM.h"
  8. #include "motor.h"
  9. #include "tim.h"
  10. #include "allcontrol.h"
  11. #include "ventilationsystem.h"

  12. u8 nowtemperature;                                                                                                             
  13. u8 nowhumidity;
  14. u8 Ctrol_flag=0;                                                                                                                                                //控制标志位


  15. int main(void)
  16. {       
  17.                 delay_init();                                                //延时函数初始化          
  18.                 OLED_Init();                                                      //初始化OLED  
  19.                 OLED_Clear();                                   //清屏函数
  20.                
  21.           NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
  22.           uart_init(19200);                                                                                                                                 //串口初始化为19200                               

  23.                 DHT11_Init();                                                                                                                                                //温湿度初始化
  24.          
  25.                 Ventilation_GPIO_Init();                                                                                                //风扇初始化
  26.          
  27.           MOTOR_GPIO_Config();                                                                                                                //电机端口初始化
  28.           TIM3_PWM_Init(999,0);                                                                                                                //PWM波初始化
  29.          
  30.                 START_display();                                                                                                                                //人机交互界面1         
  31.           short_wait();
  32.                 OLED_Clear();                         
  33.           Display_5();                                                                                                                                                //人机交互界面2
  34.          
  35.                 while(1)                                                                                                                                        
  36.                         {       

  37.                                                                                                                                                                                                                                 //第一部分:采集数据,人机交互
  38.                                 DHT11_Read_Data(&nowtemperature,&nowhumidity);  //读取温湿度值
  39.                                        
  40.                                 Display_0();                                                                                                                                                //人机交互界面3
  41.                                 OLED_ShowNum(0+40,4,nowtemperature,2,16);                                 //显示温度                             
  42.                                 OLED_ShowNum(0+40,6,nowhumidity,2,16);                                         //显示湿度       
  43.                                 OLED_ShowNum(0+40,2,CO2_Data,4,16);                                                         //显示当前CO2值
  44.                                 delay_ms(500);                                                                                                                                        //防止显示闪屏
  45.                                 short_wait();
  46.                                
  47.                                
  48.                                                                                                                                                                                                                                 //第二部分:分析数据,自动控制
  49.                        
  50.                                 if(CO2_Data<4500&&nowtemperature<26&&nowhumidity>12)
  51.                                         {
  52.                                                 Ctrol_flag=0;
  53.                                         }

  54.                                 if(CO2_Data<6000&CO2_Data>4500&&nowtemperature<26&&nowhumidity>12)
  55.                                         {
  56.                                                 Ctrol_flag=1;
  57.                                         }

  58.                                 if(CO2_Data>6000&&nowtemperature<26&&nowhumidity>12)
  59.                                         {
  60.                                                 Ctrol_flag=2;
  61.                                         }

  62.                                 if(CO2_Data<6000&nowtemperature>26|nowhumidity<12)
  63.                                         {
  64.                                                 Ctrol_flag=3;
  65.                                         }
  66.                                        
  67.                          if(CO2_Data>6000&&nowtemperature>26|nowhumidity<12)
  68.                                         {
  69.                                                 Ctrol_flag=4;
  70.                                         }

  71.                                        
  72.                         if(Ctrol_flag==0)
  73.                           {
  74.                                         motoroutput1(0);
  75.                                         motoroutput2(0);
  76.                                         motoroutput3(0);
  77.                                         Ventilation_Close();
  78.                           }
  79.                        
  80.                         if(Ctrol_flag==1)                                               
  81.                                 {
  82.                                                 Ctrol_flag=0;
  83.                                                 delay_ms(500);
  84.                                                 motoroutput1(500);       
  85.                                                 OLED_Clear();  
  86.                                                 Display_1();                                                                                                                                                //人机交互界面4
  87.                                                 mid_wait();
  88.                                                 motoroutput1(0);
  89.                                                 Ventilation_Close();
  90.                                                 short_wait();
  91.                                                 long_wait();
  92.                                                 mid_wait();
  93.                                                 mid_wait();
  94.                                           short_wait();
  95.                                                 short_wait();
  96.                                                
  97.                                 }
  98.                                
  99.                         if(Ctrol_flag==2)                                                  
  100.                                 {
  101.                                                 Ctrol_flag=0;
  102.                                                 delay_ms(500);
  103.                                                 OLED_Clear();
  104.                                                 Display_2();                                                                                                                                                //人机交互界面5
  105.                                                 motoroutput2(200);
  106.                                                 motoroutput1(0);
  107.                                                 mid_wait();
  108.                                                 motoroutput2(0);
  109.                                                 Ventilation_Close();
  110.                                                 short_wait();
  111.                                                 big_long_wait();
  112.                                                 short_wait();
  113.                                                 short_wait();
  114.                                 }
  115.                                
  116.                         if(Ctrol_flag==3)                                                 
  117.                                 {
  118.                                                 Ctrol_flag=0;
  119.                                                 delay_ms(500);
  120.                                                 OLED_Clear();
  121.                                                 Display_3();                                                                                                                                                 //人机交互界面6                       
  122.                                                 motoroutput1_1(200);                                                                                                                  //车窗反转
  123.                                                 motoroutput2_2(200);
  124.                                                 motoroutput3(200);
  125.                                                 mid_wait();
  126.                                                 motoroutput1_1(0);                                                                                                                 
  127.                                                 motoroutput2_2(0);
  128.                                                 Ventilation_Close();
  129.                                                 short_wait();
  130.                                                 big_long_wait();
  131.                                 }
  132.                                
  133.                         if(Ctrol_flag==4)                                                 
  134.                                 {
  135.                                                 Ctrol_flag=0;
  136.                                                 delay_ms(500);
  137.                                                 OLED_Clear();
  138.                                                 Display_4();                                                                                                                                                //人机交互界面7
  139.                                                 motoroutput1_1(200);                                                                                                                 //车窗反转
  140.                                                 motoroutput2_2(200);
  141.                                           mid_wait();
  142.                                                 motoroutput1_1(0);                                                                                                                 
  143.                                                 motoroutput2_2(0);
  144.                                                 motoroutput3(200);
  145.                                                 Ventilation_Open();
  146.                                                 short_wait();
  147.                                                 short_wait();
  148.                                                 big_long_wait();
  149.                                                 big_long_wait();
  150.                                 }
  151.                                        
  152. //                                motoroutput1(500);                                                                                                                                //用于检测电机是否正常工作
  153. //                                motoroutput2(500);
  154. //                                motoroutput3(500);
  155.                 }          
  156. }
复制代码

所有资料51hei提供下载:
汽车舒适度调节.rar (305.4 KB, 下载次数: 15)


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:1 发表于 2018-5-16 00:20 | 只看该作者
能介绍一下电路以及大致的工作原理讲解吗?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表