实现功能:
1、对温度、湿度进行采集2、可以警报提示、修改温度、湿度上下限值3、lcd显示相关信息
原理图:
部分程序:
#include
#define uint unsigned int
#define uchar unsigned char
#include
typedef bit bool ;
sbit io = p1^1 ;//(口线定义)
sbit bee=p1^0;
sbit rs = p2^5 ;
sbit rw = p2^6 ;
sbit ep = p2^7 ;
bit flag_300ms ;
sbit k1=p1^2;
sbit k2=p1^3;
sbit k3=p1^4;
uchar yemian=0;//(定义变量)
uchar flat=1;
uchar data_byte;
uchar rh,rl,th,tl;
uchar wendu,shidu;//报警的温度和湿度
#include eeprom52.h
/ 延时程序 /
void delay(uchar ms)
{ // 延时子程序
uchar i ;
while(ms--)
{
for(i = 0 ; i<250;i++) ;
}
}
void delay1()//延时10us
{
uchar i;
i--;
i--;
i--;
i--;
i--;
i--;
}
void longdelay(uchar s) //长延时
{
while(s--)
{
delay(20) ;
}
}
/ 把数据保存到单片机内部eeprom中 /
void write_eeprom()
{
sectorerase(0x2000);
byte_write(0x2000, wendu);
byte_write(0x2001, shidu);
byte_write(0x2060, a_a);
}
/* 把数据从单片机内部eeprom中读出来 /
void read_eeprom()
{
wendu = byte_read(0x2000);
shidu = byte_read(0x2001);
a_a = byte_read(0x2060);
}
/ 开机自检eeprom初始化 ***/
void init_eeprom()
{
read_eeprom(); //先读
if(a_a != 2) //新的单片机初始单片机内问eeprom
{
wendu = 30;
shidu = 80;
a_a = 2;
write_eeprom();
}
}
if( th
{
bee=1; //停止报警
}
}
/ lcd模块 ******************/
bool lcd_bz()//测试lcd忙碌状态
rs = 0 ;
rw = 0 ;
ep = 0 ;
p0 = cmd ;
ep = 1 ;
ep = 0 ;
}
void write_addr(uchar addr)//写地址
{
write_cmd(addr|0x80) ;
}
void write_byte(uchar dat)//写字节
{
while(lcd_bz()) ;
rs = 1 ;
rw = 0 ;
ep = 0 ;
p0 = dat ;
ep = 1 ;
ep = 0 ;
}
void lcd_init()// 初始化
{
write_cmd(0x38) ;
delay(1);
write_cmd(0x08) ;
delay(1);
write_cmd(0x01) ;
delay(1);
write_cmd(0x06) ;
delay(1);
write_cmd(0x0c) ;
delay(1);
}
data_byte<<=1;
data_byte|=temp;
}
return data_byte;
}
void receive()//接收数据
{
uchar t_h,t_l,r_h,r_l,check,num_check;
uchar count;
start();//开始信号
io=1;
if(!io)//读取dht11响应信号
{
while((io)&&count++);
r_h=receive_byte();
r_l=receive_byte();
t_h=receive_byte();
t_l=receive_byte();
check=receive_byte();
io=0;//拉低延时50us
delay1();delay1();delay1();delay1();delay1();
io=1;
num_check=r_h+r_l+t_h+t_l;
if(num_check=check)
{
rh=r_h;
rl=r_l;
th=t_h;
tl=t_l;
check=num_check;
}
}
}
科技感满满!LED全息屏为你的展示空间增色添彩
德明利拟参股设立合资公司并向其出售触控业务资产
印板安装型电流传感器,Current Sensor
技术分享 | i.MX8M Plus开发板支持ov5640
有关高速PCB布局设计的避坑指南
基于51单片机的温度湿度采集系统设计
物联网技术有助于政府监管数据所有权
一种有源箝位Flyback软开关电路设计
60W吉他音箱 (60W Guitar Amplifier)
AEC-Q101的认证对象和测试项目
用于医疗成像系统的数据转换器是什么样子的
低成本电路将时钟转换为低失真正弦波
海康威视建筑工程安全质量物联网系统的特点和应用方案
AP6067锂电池充电IC_输入4.8V-20V 输出4.2/8.4V
WeLink助力中建西南院成功举办数字赋能培训
领存自主可控高端存储产品亮相
微波传声技术
观测者-3成首次利用太阳能主动探测台风中心的无人艇
基于HA13118的18瓦音频放大器电路
高通正式推出了全球首个Qualcomm QTM527毫米波天线模组