# 基于STM32智能窗帘设计(含源程序+proteus仿真)
仿真:proteus8.11
程序编译器:keil 5
编程语言:C语言
编号C0007
资料下载链接
讲解视频
基于STM32的简易智能窗帘控制系统仿真设计
功能说明:
实现功能:
有手动,自动两种模式
自动模式下,滑动变阻器模拟光照传感器,通过stm32检测与阈值比较
低于阈值开窗帘,高于阈值关闭窗帘
手动模式下,按键控制窗帘关闭打开
仿真图(提供源文件):
新版本:
旧版:
源程序(提供源文件):
#include "delay.h"
#include "sys.h"
#include "adc.h"
#include "1602.h"
#include "motor.h"
#include "bsp_dht11.h"
#define LED1 PAout(13)
#define LED2 PAout(14)
#define MOTOR PCout(0)
unsigned char dis_vol1[] = {"LUX: % auto"};
unsigned char dis_vol2[] = {" auto"};
unsigned char dis_vol3[] = {"manual"};
//函数声明
void display1(void);
void display2(void);
u16 LUX, HZ;
int main(void)
{
unsigned int i;
u16 ADCValue1, ADCValue2;
float voltage1, voltage2;
u8 Mflag = 2;
u8 OPENflag = 0; //起初代表窗帘关
u8 AUTOflag = 0; //起初代表自动
delay_init();
Adc_Init();
GPIO_InitStructReadtempCmd();
MotoR_GPIO();
lcd_system_reset();
LED1 = 1;
LED2 = 0;
MOTOR = 1;
while(1)
{
ADCValue1 = Get_Adc_Average(ADC_Channel_0, 10);
voltage1 = ((float)ADCValue1 / 4096) * 3.3; //计算电压
LUX = (10000 * voltage1) / 33;
display1();
if(PCin(12) == 0) //自动
{
AUTOflag = 0;
for(i = 0; i <6; i++)
lcd_char_write(i, 1, dis_vol2[i]);
}
if(PCin(13) == 0) //手动
{
AUTOflag = 1;
for(i = 0; i < 6; i++)
lcd_char_write(i, 1, dis_vol3[i]);
}
if(PCin(10) == 0 && OPENflag == 0 && AUTOflag == 1)
{
LED1 = 0;
LED2 = 1;
MOTOR = 0; //开窗帘
Mflag = 2;
OPENflag = 1; //已经开好
}
if(PCin(11) == 0 && OPENflag == 1 && AUTOflag == 1)
{
LED1 = 1;
LED2 = 0;
MOTOR = 1; //关闭窗帘
Mflag = 2;
OPENflag = 0; //已经关好
}
if(LUX > 400) //40% 阈值
{
display1();
Mflag = 1; //光照足够,关闭窗帘
}
else
{
display1();
Mflag = 0; //光照不足,需要启动窗帘
}
if(Mflag == 1 && OPENflag == 1 && AUTOflag == 0)
{
LED1 = 1;
LED2 = 0;
MOTOR = 1; //关闭窗帘
Mflag = 2;
OPENflag = 0; //已经关好
}
else if(Mflag == 0 && OPENflag == 0 && AUTOflag == 0)
{
LED1 = 0;
LED2 = 1;
MOTOR = 0; //开窗帘
Mflag = 2;
OPENflag = 1; //已经开好
}
}
}
void display1()
{
unsigned int i, j;
dis_vol1[5] = LUX / 100 + 0x30;
dis_vol1[6] = LUX % 100 / 10 + 0x30;
dis_vol1[7] = '.';
dis_vol1[8] = LUX % 10 + 0x30;
for(i = 0; i < 12; i++)
lcd_char_write(i, 0, dis_vol1[i]);
// for(j=0;j<15;j++)
// lcd_char_write(j,1,dis_vol2[j]);
}
资料清单如下:
下载方式看视频或文章开头