资料编号:140
一:功能介绍
1、采用stm32单片机+LCD1602显示屏+独立按键+DHT11传感器+ds1302时钟+光敏传感器+蜂鸣器+LED灯,制作一个基于stm32单片机智能晾衣杆控制系统Proteus仿真;
2、通过光敏传感器采集当前的光照强度,显示到LCD1602显示屏上面;
3、通过DHT11传感器采集温湿度,并且显示到LCD1602显示屏上面;
4、通过DS1302时钟记录当前的时间,显示到LCD1602屏幕上面;
5、通过按键设置光照强度和湿度阈值,显示到LCD1602屏幕上面;
6、如果湿度大于设置阈值,蜂鸣器进行提醒可能下雨;当湿度小于等于阈值并且光照强度大于阈值,也就是晴天光照强度高的情况下,自动打开晾衣杆(LED指示灯模拟),反之关闭晾衣杆;
二:仿真演示视频+程序简要讲解:(程序有中文注释,新手容易看懂)
140-基于stm32单片机智能晾衣杆控制系统Proteus仿真+源程序
三:设计软件介绍
本设计使用C语言编程设计,程序代码采用keil5编写,程序有中文注释,新手容易看懂,仿真采用Proteus软件进行仿真,演示视频使用的是Proteus8.9版本;资料包里有相关软件包,可自行下载安装。
四:程序打开方法
特别注意:下载资料包以后一定要先解压!!!(建议解压到桌面上,文件路径太深会导致程序打开异常),解压后再用keil5打开。
程序部分展示,有中文注释,新手容易看懂
//毫秒级的延时
void delay_ms(u16 time)
{
u16 i=0;
while(time--)
{
i=800; //自己定义
while(i--) ;
}
}
/*****************DHT11********************/
extern void DHT11_receive( int *h, int *t);
/*****************引脚配置********************/
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB| RCC_APB2Periph_GPIOC| RCC_APB2Periph_GPIOC,ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1,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(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 |GPIO_Pin_9|GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//LED
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//DHT11
GPIO_InitStructure.GPIO_Pin = 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_0| GPIO_Pin_1| GPIO_Pin_2| GPIO_Pin_3| GPIO_Pin_4| GPIO_Pin_5;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//配置 PA0 ADC采集模式
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//LED
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14|GPIO_Pin_6;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
/* ADC配置 */
void ADC_Set(void)
{
ADC_InitTypeDef ADC_InitStructure;//ADC结构体变量//注意在一个语句快内变量的声明要放在可执行语句的前面,否则出错,因此要放在ADC1_GPIO_Config();前面
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;//ADC1和ADC2工作在独立模式
ADC_InitStructure.ADC_ScanConvMode = DISABLE; //使能扫描
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;//ADC转换工作在连续模式
ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;//由软件控制转换,不使用外部触发
ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;//转换数据右对齐
ADC_InitStructure.ADC_NbrOfChannel = 1;//转换通道为1
ADC_Init(ADC1, &ADC_InitStructure); //初始化ADC
ADC_RegularChannelConfig(ADC1, ADC_Channel_0, 1, ADC_SampleTime_28Cycles5);
ADC_Cmd(ADC1, ENABLE);//使能ADC1
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
}
int wendu,shidu,guangqiang; //保存温度 湿度 光强
int gz=70,sd=80;// 湿度设定 光强设定
u8 time_data[8];//保存时间的数组
int nian=12,yue=34,ri=56;//保存年 月 日
int shi=12,fen=34,miao=56;//保存
//这里对按键进行扫描
void anjiansaomiao(void)
{
static u8_t k1,k2,k3,k4;
static u8_t K1Flag=0,K2Flag=0,K3Flag=0,K4Flag=0;
//按键扫描,获取按键状态
k1 = GPIO_ReadInputDataBit(GPIOB , GPIO_Pin_0);
k2 = GPIO_ReadInputDataBit(GPIOB , GPIO_Pin_1);
k3 = GPIO_ReadInputDataBit(GPIOB , GPIO_Pin_2);
k4 = GPIO_ReadInputDataBit(GPIOB , GPIO_Pin_3);
//光照设定值+
//表明按下
if(k1 == 0)
{
K1Flag = 1;
}
else
{
//释放后进行响应
if(K1Flag )
{
K1Flag = 0;
gz++;
if(gz>99) gz=99;
}
}
//光照设定值-
//表明按下
if(k2 == 0)
{
K2Flag = 1;
}
else
{
//释放后进行响应
if(K2Flag )
{
K2Flag = 0;
gz--;
if(gz<0) gz=0;
}
}
//湿度设定值+
//表明按下
if(k3 == 0)
{
K3Flag = 1;
}
else
{
//释放后进行响应
if(K3Flag )
{
K3Flag = 0;
sd++;
if(sd>99) sd=99;
}
}
//湿度设定值-
//表明按下
if(k4 == 0)
{
K4Flag = 1;
}
else
{
//释放后进行响应
if(K4Flag)
{
K4Flag = 0;
sd--;
if(sd<0) sd=1;
}
}
}
//中断优先级配置
void NVICConfig(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQn; //中断源:[15:10],位于“stm32f10x.h”中
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //抢占优先级:1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //子优先级:1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //使能中断通道
NVIC_Init(&NVIC_InitStructure);
}
void Display(void)
{
char xxx=0,yyy=0;
//T1 温度
WrByte1602(0,0,'T'); //.
WrByte1602(0,1,'='); //.
WrByte1602(0,2,AsciiCode[wendu%100/10]);
WrByte1602(0,3,AsciiCode[wendu%10]);
WrByte1602(0,4,' ');
//T2 湿度
WrByte1602(0,5,'H'); //.
WrByte1602(0,6,'='); //.
WrByte1602(0,7,AsciiCode[shidu%100/10]);
WrByte1602(0,8,AsciiCode[shidu%10]);
WrByte1602(0,9,' ');
//T3 光强
WrByte1602(0,10,'G'); //.
WrByte1602(0,11,'='); //.
WrByte1602(0,12,AsciiCode[guangqiang%1000/100]);
WrByte1602(0,13,AsciiCode[guangqiang%100/10]);
WrByte1602(0,14,AsciiCode[guangqiang%10]);
WrByte1602(0,15,' ');
五:仿真文件(采用Proteus打开)
六:资料清单展示(文件中包含的相关资料)