一:功能介绍
1、采用stm32单片机+LCD1602+DHT11温湿度传感器+烟雾传感器+光敏电阻+按键+电机+LED灯,制作一个单片机车内环境智能车窗控制系统;
2、通过按键设置手动和自动模式,手动情况下:可以通过按键打开和关闭车窗,通过LED指示灯来显示当前车窗状态;
3、自动情况下:光照强度大于一定值,自动打开车窗,或者当烟雾浓度大于一定值,自动打开车窗;
4、LCD1602显示采集的温湿度、光照强度、烟雾浓度;
二:仿真演示视频+程序简要讲解:(程序有中文注释,新手容易看懂)
114-基于stm32单片机车内环境智能车窗控制系统Proteus仿真+程序源码+讲解视频
三:设计软件介绍
本设计使用C语言编程设计,程序代码采用keil5编写,程序有中文注释,新手容易看懂,仿真采用Proteus软件进行仿真,演示视频使用的是Proteus8.9版本;资料包里有相关软件包,可自行下载安装。
四:程序打开方法
特别注意:下载资料包以后一定要先解压!!!(建议解压到桌面上,文件路径太深会导致程序打开异常),解压后再用keil5打开。
程序部分展示,有中文注释,新手容易看懂
/*****************引脚配置********************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
//LCD1602 管脚
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8| GPIO_Pin_9| GPIO_Pin_10| GPIO_Pin_11| GPIO_Pin_12| GPIO_Pin_13| GPIO_Pin_14| GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 |GPIO_Pin_6|GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//DHT11
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
void IO_out( void )
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOC ,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0| GPIO_Pin_1| GPIO_Pin_2| GPIO_Pin_3;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10|GPIO_Pin_9;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
void anjian()
{
static u8_t k1,k2,k3;
//按键扫描,获取按键状态
k3 = GPIO_ReadInputDataBit(GPIOC , GPIO_Pin_2);
k2 = GPIO_ReadInputDataBit(GPIOC , GPIO_Pin_1);
k1 = GPIO_ReadInputDataBit(GPIOC , GPIO_Pin_0);
if(k3==1)//手动模式下
{
if(k1 == 1)
{
PCout(9)=PCout(10)=0;
}
if(k2 == 1)
{
PCout(9)=PCout(10)=1;
}
}
if(k3==0)//自动模式下
{
if(temp2>50||temp1>80) PCout(9)=PCout(10)=0;//烟雾浓度大于50或者光照强度>80暴晒情况下 自动开窗
else PCout(9)=PCout(10)=1;
}
}
int main(void)
{
GPIO_Configuration();//初始化
ADC1_GPIO_Config();
ADC_Config();
Init1602();
IO_out();
delay_ms(500);
while(1)
{
anjian();
WrByte1602(0,1,' '); //字符显示
WrByte1602(0,2,'G');
WrByte1602(0,3,'Z');
WrByte1602(0,4,'=');
WrByte1602(1,1,' ');
WrByte1602(1,2,'Y');
WrByte1602(1,3,'W');
WrByte1602(1,4,'=');
WrByte1602(0,9,' ');
WrByte1602(0,10,'W');
WrByte1602(0,11,'D');
WrByte1602(0,12,'=');
WrByte1602(1,9,' ');
WrByte1602(1,10,'S');
WrByte1602(1,11,'D');
WrByte1602(1,12,'=');
//读取温湿度
DHT11_receive(&shidu,&wendu);
ADC_num1=Get_ADC(ADC_Channel_0);//读取光照强度
temp1=ADC_num1*100/4096;
ADC_num2=Get_ADC(ADC_Channel_1);//读取烟雾浓度
temp2=ADC_num2*100/4096;
anjian();//按键多次检测 防止漏检测
WrByte1602(0,5,AsciiCode[temp1%1000/100]);//显示光照强度
WrByte1602(0,6,AsciiCode[temp1%100/10]);
WrByte1602(0,7,AsciiCode[temp1%10]);
WrByte1602(1,5,AsciiCode[temp2%1000/100]); //显示烟雾浓度
WrByte1602(1,6,AsciiCode[temp2%100/10]);
WrByte1602(1,7,AsciiCode[temp2%10]);
anjian();//按键多次检测 防止漏检测
WrByte1602(0,13,AsciiCode[wendu%1000/100]); //显示温度
WrByte1602(0,14,AsciiCode[wendu%100/10]);
WrByte1602(0,15,AsciiCode[wendu%10]);
WrByte1602(1,13,AsciiCode[shidu%1000/100]); //显示湿度
WrByte1602(1,14,AsciiCode[shidu%100/10]);
WrByte1602(1,15,AsciiCode[shidu%10]);
anjian();//按键多次检测 防止漏检测
}
五:仿真文件(采用Proteus打开)
六:资料清单展示(文件中包含的相关资料)