本設計:
基于STM32智能窗簾設計(含源程序+proteus仿真)
仿真:proteus8.11
程序編譯器:keil 5
編程語言:C語言
編號C0007
【騰訊文檔】C0007 網(wǎng)盤鏈接
資料下載鏈接
功能說明:
有手動,自動兩種模式:
1.自動模式:滑動變阻器模擬光照傳感器,通過stm32檢測與閾值比較
低于閾值開窗簾,高于閾值關閉窗簾;
2.手動模式:按鍵控制窗簾關閉打開。
仿真圖(提供源文件):
源程序(提供源文件):
#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"};
//函數(shù)聲明
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]);
}
資料清單如下:
閱讀全文