89.基于51单片机的智能窗户控制【DHT11,ADC0832,步进电机,LCD1602】(仿真)
89.基于51单片机的智能窗户控制【DHT11,ADC0832,步进电机,LCD1602】(仿真)
1、电机模块主要负责为智 能窗的开合提供驱动控制。
2、按键模块向系统输入信号并手动控制开关窗口。
3、采用雨滴检测模块、烟雾检测模块和湿度检测模块对相关指标进行检测。系统处 理器收到信号后能够对开关窗口进行智能分析和判断。
4、报警检测模块用于检 测盗窃,可以发出警报声并关闭窗户。
5、烟雾过高是开窗
6、检测到人体要关窗
资料包括:
原理图:
仿真图:
程序运行图:
#include "ADC0832.h"
#include "intrins.h"
//读取AD值
unsigned int ADC0832(unsigned char channel) //AD转换,返回结果
{
unsigned char i = 0;
unsigned char j;
unsigned int dat = 0;
unsigned char ndat = 0;
if (channel == 0) channel = 2;//通道1
if (channel == 1) channel = 3;//通道2
ADDI = 1;//输入引脚拉高
_nop_();//延时1us
_nop_();//延时1us
ADCS = 0;//片选
_nop_();//延时1us
_nop_();//延时1us
ADCLK = 1;//拉高时钟
_nop_();//延时1us
_nop_();//延时1us
ADCLK = 0;//拉低时钟
_nop_();//延时1us
_nop_();//延时1us
ADCLK = 1;//拉高时钟
ADDI = channel & 0x1;
_nop_();//延时1us
_nop_();//延时1us
ADCLK = 0;//拉低时钟
_nop_();//延时1us
_nop_();//延时1us
ADCLK = 1;//拉高时钟
ADDI = (channel >> 1) & 0x1;
_nop_();//延时1us
_nop_();//延时1us
ADCLK = 0;//拉低时钟
ADDI = 1;//输出1
_nop_();//延时1us
_nop_();//延时1us
dat = 0; //存储清零
ADDI =1;
for (i = 0; i < 8; i++) //循环8次
{
dat |= ADDI;//读取引脚
ADCLK = 1; //拉高时钟
_nop_();//延时1us
_nop_();//延时1us
ADCLK = 0;//拉低时钟
_nop_();//延时1us
_nop_();//延时1us
dat <<= 1;//左移
if (i == 7) dat |= ADDI;//读取引脚
}
for (i = 0; i < 8; i++)//循环8次
{
j = 0;
j = j | ADDI; //读取引脚
ADCLK = 1; //拉高时钟
_nop_();//延时1us
_nop_();//延时1us
ADCLK = 0; //拉低时钟
_nop_();//延时1us
_nop_();//延时1us
j = j << 7; //左移7位
ndat = ndat | j; //合并数据
if (i < 7) ndat >>= 1;//去掉符号
}
ADCS = 1; //清除片选
ADCLK = 0;//拉低时钟
ADDI=1;
dat <<= 8;//数据移位
dat |= ndat;//合并数据
return(ndat);
}