51单片机温湿度控制系统 YL69湿度检测程序 显示湿度

基于51单片机SHT11温湿度传感器检测程序_百度文库
两大类热门资源免费畅读
续费一年阅读会员,立省24元!
基于51单片机SHT11温湿度传感器检测程序
地方国营太兴水泥厂殷付厂长|
总评分4.2|
用知识赚钱
阅读已结束,下载本文需要
想免费下载本文?
定制HR最喜欢的简历
下载文档到电脑,同时保存到云知识,更方便管理
还剩8页未读,继续阅读
定制HR最喜欢的简历
你可能喜欢yl-69湿度传感器能测的湿度范围是多少_百度知道
yl-69湿度传感器能测的湿度范围是多少
您的回答被采纳后将获得:
系统奖励15(财富值+成长值)+难题奖励30(财富值+成长值)
我有更好的答案
湿度值是自己定的,yl-69只是输出一个模拟量,可以经A/D转换后输出数字湿度值。比如,yl-69可以输出0-5V,那么你在程序里可以将其对应为0-100%
我目前毕设用的就是YL-69做的土壤湿度检测,感觉完全放入水中也只能到94%,貌似也不是那么精确
为您推荐:
其他类似问题
您可能关注的内容
湿度传感器的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。求基于51单片机YL69土壤湿度传感器的C语言代码,包括AD转换,谢谢。_百度知道
求基于51单片机YL69土壤湿度传感器的C语言代码,包括AD转换,谢谢。
我有更好的答案
你好!显示用什么?数码管还是液晶呢
是LCD1206液晶显示。因为液晶这部分代码我知道怎么写。所以希望有YL69的代码,因为不知道YL69是如何初始化、运作的
嗯。我之前没看到,已经私信你了。
我发不了追问了。。。。想让你加一下我Q
为您推荐:
其他类似问题
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。查看: 409|回复: 0
DHT11按键调节温湿度+YL69土壤湿度报警
DHT11按键控制+土壤湿度报警
单片机源程序如下:
#include&reg52.h&
#include &intrins.h&
typedef unsigned char uint8;
typedef unsigned int uint16;
sbit rs=P2^6;& && && &// 数据命令选择
sbit rw=P2^5;& && && &//读写选择
sbit e=P2^7;& && && & //使能
sbit k1=P3^3; //模式
sbit k2=P2^1; //加
sbit k3=P2^2; //减
sbit bee=P1^5;//蜂鸣器
sbit DO=P3^1;
sbit DHT11_DQ_OUT=P3^2;
sbit led1=P1^0;
sbit led2=P1^1;
sbit led3=P1^2;
sbit dq=P2^0;
uint8
uint8 mode=0,
char temph=28,templ=20;
char humih=80,humil=20;
uint8 temp,
uint8& && && & //设定报警标志
uint8 code num[10]=&&;
uint8 code str1[]=&Temp:&;&&//温度
uint8 code str2[]=&Humi:&;&&//湿度
uint8 code str3[]=&Error&;&&
uint8 code str4[]=&Success& & &;
uint8 code str5[]=&%RH&;
uint8 code str6[]=&TempH:&;& && && & //设定温度上限显示
uint8 code str7[]=&TempL:&;& && && & //设定温度下限显示
uint8 code str8[]=&HumiH:&;& && && &&&//设定湿度上限显示
uint8 code str9[]=&HumiL:&;& && && &&&//设定湿度下限显示
void delay(uint16 i)
{
& && &&&while(i--);
}
void delay_ms(uint16 i)
{
& && &&&while(i--)
& && && && && & delay(90);
}
void delay1(uint16 z)
{& && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && && &
& & uint16 i,j;
& & for(i=z;i&0;i--)
& && &&&for(j=110;j&0;j--);
}
void wrc(uint8 c)& && && &//写命令
{
& && &&&delay(1000);
& && &&&rs=0;
& && &&&rw=0;
& && &&&e=0;
& && &&&P0=c;
& && &&&e=1;
& && &&&delay(10);
& && &&&e=0;
}
void wrd(uint8 dat)& && && & //写数据
{
& && &&&delay(1000);
& && &&&rs=1;
& && &&&rw=0;
& && &&&e=0;
& && &&&P0=
& && &&&e=1;
& && &&&delay(10);
& && &&&e=0;
& && &&&rs=0;
}
void lcd_init()& && && &&&// LCD1602初始化
{
& && &&&delay(1000);
& && &&&wrc(0x38);
& && &&&wrc(0x38);& && && &//功能设置命令,选择8位总线,双行显示&&5*7点阵字符
& && &&&wrc(0x38);
& && &&&wrc(0x06);& && &&&//光标和显示模式设置&&光标右移&&整屏不移动
& && &&&wrc(0x0c);& && &&&//显示开关控制&&开显示&&无光标 光标不闪烁
& && &&&wrc(0x01);& && &&&//清零指令&&固定的
}
//复位DHT11
void DHT11_Rst()& && && &&&
{& && && && && &&&
& & DHT11_DQ_OUT=0;& && && &//拉低DQ
& & delay_ms(20);& && && && &//拉低至少18ms
& & DHT11_DQ_OUT=1;& && && &//DQ=1
& && &&&delay(3);& && && && & //主机拉高20~40us
}
//等待DHT11的回应
//返回1:未检测到DHT11的存在
//返回0:存在
uint8 DHT11_Check()& && && && &
{& &
& && &&&uint8 retry=0;& && && &
& & while (DHT11_DQ_OUT&&retry&100)//DHT11会拉低40~50us
& && &&&{
& && && && && & retry++;
& && && && && & _nop_();
& && &&&};& && && &
& && &&&if(retry&=100)return 1;
& && &&&else retry=0;
& & while (!DHT11_DQ_OUT&&retry&100)//DHT11拉低后会再次拉高40~50us
& && &&&{
& && && && && & retry++;
& && && && && & _nop_();
& && &&&};
& && &&&if(retry&=100)return 1;& && && && &
& && &&&return 0;
}
//DHT11初始化
//返回0:初始化成功,1:失败
uint8 DHT11_Init()
{
& && &&&DHT11_Rst();& && && &
& && &&&return DHT11_Check();& && &&&
}
//从DHT11读取一个位
//返回值:1/0
uint8 DHT11_Read_Bit(void)& && && && && && && && &&&
{
& && && &uint8 retry=0;
& && &&&while(DHT11_DQ_OUT&&retry&100)//等待变为低电平 12-14us 开始
& && &&&{
& && && && && & retry++;
& && && && && & _nop_();
& && &&&}
& && &&&retry=0;
& && &&&while((!DHT11_DQ_OUT)&&retry&100)//等待变高电平& && && &26-28us表示0,116-118us表示1
& && &&&{
& && && && && & retry++;
& && && && && & _nop_();
& && &&&}
& && &&&delay(1);//等待40us
& && &&&if(DHT11_DQ_OUT)return 1;
& && &&&else return 0;& && && && && && &
//从DHT11读取一个字节
//返回值:读到的数据
uint8 DHT11_Read_Byte(void)& &
{& && &&&
& & uint8 i,dat=0;
& && &&&for (i=0;i&8;i++)
& && &&&{
& && && && && && & dat&&=1;
& && && && &dat|=DHT11_Read_Bit();
& & }& && && && && && && && && && && && && && && && && &
//从DHT11读取一次数据
//temp:温度值(范围:0~50°)
//humi:湿度值(范围:20%~90%)
//返回值:0,正常;1,读取失败
uint8 DHT11_Read_Data(uint8 *temp,uint8 *humi)& &
{& && &&&
& && && &uint8 buf[5];
& && &&&uint8
& && &&&DHT11_Rst();
& && &&&if(DHT11_Check()==0)
& && &&&{
& && && && && & for(i=0;i&5;i++)//读取40位数据
& && && && && & {
& && && && && && && && &buf[i]=DHT11_Read_Byte();
& && && && && & }
& && && && && & if((buf[0]+buf[1]+buf[2]+buf[3])==buf[4])
& && && && && & {
& && && && && && && && &*humi=buf[0];
& && && && && && && && &*temp=buf[2];
& && && && && & }
& && && && && &
& && &&&}else return 1;
& && &&&return 0;& && && && &
}
void key_pros()&&//按键处理函数
{
& && &&&if(k1==0)
& && &&&{
& && && && && & delay(1000);
& && && && && & if(k1==0)
& && && && && & {
& && && && && && && && &mode++;
& && && && && && && && &if(mode==5)mode=0;
& && && && && && && && &wrc(0x01);
& && && && && & }
& && && && && & while(!k1);
& && &&&}
& && &&&if(mode==1)& && && && && && &//对温度上限设定
& && &&&{
& && && && && & if(k2==0)& && && && && && &//加
& && && && && & {
& && && && && && && && &delay(1000);
& && && && && && && && &if(k2==0)
& && && && && && && && &{
& && && && && && && && && && &&&temph++;
& && && && && && && && && && &&&if(temph&=80)temph=80;
& && && && && && && && &}
& && && && && && && && &while(!k2);
& && && && && & }
& && && && && & if(k3==0)& && && &&&//减
& && && && && & {
& && && && && && && && &delay(1000);
& && && && && && && && &if(k3==0)
& && && && && && && && &{
& && && && && && && && && && &&&temph--;
& && && && && && && && && && &&&if(temph&=0)temph=0;
& && && && && && && && &}
& && && && && && && && &while(!k3);
& && && && && & }
& && &&&}
& && &&&if(mode==2)& && && && && && &//对温度下限设定
& && &&&{
& && && && && & if(k2==0)& && && && && && &//加
& && && && && & {
& && && && && && && && &delay(1000);
& && && && && && && && &if(k2==0)
& && && && && && && && &{
& && && && && && && && && && &&&templ++;
& && && && && && && && && && &&&if(templ&=80)templ=80;
& && && && && && && && &}
& && && && && && && && &while(!k2);
& && && && && & }
& && && && && & if(k3==0)& && && &&&//减
& && && && && & {
& && && && && && && && &delay(1000);
& && && && && && && && &if(k3==0)
& && && && && && && && &{
& && && && && && && && && && &&&templ--;
& && && && && && && && && && &&&if(templ&=0)templ=0;
& && && && && && && && &}
& && && && && && && && &while(!k3);
& && && && && & }
& && &&&}
& && &&&if(mode==3)& && && && && && &//对湿度上限设定
& && &&&{
& && && && && & if(k2==0)& && && && && && &//加
& && && && && & {
& && && && && && && && &delay(1000);
& && && && && && && && &if(k2==0)
& && && && && && && && &{
& && && && && && && && && && &&&humih++;
& && && && && && && && && && &&&if(humih&=80)humih=80;
& && && && && && && && &}
& && && && && && && && &while(!k2);
& && && && && & }
& && && && && & if(k3==0)& && && &&&//减
& && && && && & {
& && && && && && && && &delay(1000);
& && && && && && && && &if(k3==0)
& && && && && && && && &{
& && && && && && && && && && &&&humih--;
& && && && && && && && && && &&&if(humih&=0)humih=0;
& && && && && && && && &}
& && && && && && && && &while(!k3);
& && && && && & }
& && &&&}
& && &&&if(mode==4)& && && && && && &//对湿度下限设定
& && &&&{
& && && && && & if(k2==0)& && && && && && &//加
& && && && && & {
& && && && && && && && &delay(1000);
& && && && && && && && &if(k2==0)
& && && && && && && && &{
& && && && && && && && && && &&&humil++;
& && && && && && && && && && &&&if(humil&=80)humil=80;
& && && && && && && && &}
& && && && && && && && &while(!k2);
& && && && && & }
& && && && && & if(k3==0)& && && &&&//减
& && && && && & {
& && && && && && && && &delay(1000);
& && && && && && && && &if(k3==0)
& && && && && && && && &{
& && && && && && && && && && &&&humil--;
& && && && && && && && && && &&&if(humil&=0)humil=0;
& && && && && && && && &}
& && && && && && && && &while(!k3);
& && && && && & }
& && &&&}
}
void lcd_init_display()& && && &&&//LCD初始化显示
{
& && &&&uint8
& && &&&for(i=0;i&5;i++)
& && &&&{
& && && && && & wrc(0x80+i);
& && && && && & wrd(str1[i]);& && &&&
& && &&&}
& && &&&for(i=0;i&5;i++)
& && &&&{
& && && && && & wrc(0xc0+i);
& && && && && & wrd(str2[i]);& && &&&
& && &&&}
}
void data_pros()& && &&&//数据处理函数
{
& && &&&uint8& && && && &&&
& && &&&uint8 temp_buf[2],humi_buf[2];
& && &&&uint8 temphbuf[2],templbuf[2],humihbuf[2],humilbuf[2];
& && &&&DHT11_Read_Data(&temp,&humi);
& && &&&temp_buf[0]=temp/10+0x30;& && &&&
& && &&&temp_buf[1]=temp%10+0x30;
& && &&&humi_buf[0]=humi/10+0x30;& && &&&
& && &&&humi_buf[1]=humi%10+0x30;
& && &&&
& && &&&temphbuf[0]=temph/10+0x30;
& && &&&temphbuf[1]=temph%10+0x30;
& && &&&templbuf[0]=templ/10+0x30;
& && &&&templbuf[1]=templ%10+0x30;
& && &&&humihbuf[0]=humih/10+0x30;
& && &&&humihbuf[1]=humih%10+0x30;
& && &&&humilbuf[0]=humil/10+0x30;
& && &&&humilbuf[1]=humil%10+0x30;
& && &&&if(mode==0)
& && &&&{
& && && && && & lcd_init_display();
& && && && && & wrc(0x85);
& && && && && & wrd(num[temp/10]);
& && && && && & wrd(num[temp%10]);
& && && && && & wrd(0xdf);
& && && && && & wrd('C');
& && &&&
& && && && && & for(i=0;i&2;i++)
& && && && && & {
& && && && && && && && &wrc(0Xc5+i);
& && && && && && && && &wrd(humi_buf[i]);& && && && && && &
& && && && && & }& && &&&
& && && && && & for(i=0;i&3;i++)
& && && && && & {
& && && && && && && && &wrc(0Xc7+i);
& && && && && && && && &wrd(str5[i]);& && && && && && &
& && && && && & }& && &&&
& && &&&}
& && &&&if(mode==1)& && && && && && && && &&&//温度上限显示
& && &&&{
& && && && && & wrc(0x80);
& && && && && & for(i=0;i&6;i++)
& && && && && & {
& && && && && && && && &wrd(str6[i]);& && && && && && &
& && && && && & }
& && && && && & wrd(temphbuf[0]);
& && && && && & wrd(temphbuf[1]);& && && && && && && && &
& && &&&}
& && &&&if(mode==2)& && && && && && && && &&&//温度下限显示
& && &&&{
& && && && && & wrc(0x80);
& && && && && & for(i=0;i&6;i++)
& && && && && & {
& && && && && && && && &wrd(str7[i]);& && && && && && &
& && && && && & }
& && && && && & wrd(templbuf[0]);
& && && && && & wrd(templbuf[1]);& && && && && && && && &
& && &&&}
& && &&&if(mode==3)& && && && && && && && &&&//湿度上限显示
& && &&&{
& && && && && & wrc(0x80);
& && && && && & for(i=0;i&6;i++)
& && && && && & {
& && && && && && && && &wrd(str8[i]);& && && && && && &
& && && && && & }
& && && && && & wrd(humihbuf[0]);
& && && && && & wrd(humihbuf[1]);& && && && && && && && &
& && &&&}
& && &&&if(mode==4)& && && && && && && && &&&//湿度下限显示
& && &&&{
& && && && && & wrc(0x80);
& && && && && & for(i=0;i&6;i++)
& && && && && & {
& && && && && && && && &wrd(str9[i]);& && && && && && &
& && && && && & }
& && && && && & wrd(humilbuf[0]);
& && && && && & wrd(humilbuf[1]);& && && && && && && && &
& && &&&}
}
void baojinpros()& && &&&//报警处理
{
& && &&&if(temp&=temph||humi&=humih)& && && &//检测温度或者湿度高于设定上限值 降温湿
& && &&&{
& && && && && & led1=1;& && && && && & //降温湿指示灯
& && && && && & led2=0;
& && &&&}
& && &&&if(temp&=templ||humi&=humil)& && &&&//检测温度或者湿度低于设定下限值&&升温湿
& && &&&{
& && && && && & led1=0;
& && && && && & led2=1;&&//升高温湿指示灯
& && &&&}
& && &&&if(DO==0)
& && &&&{
& && && && && & led3=1;
& && &&&}
& && &&&if(DO==1)
& && &&&{
& && && && && & led3=0;
& && &&&}
& && &&&if((temp&templ&&temp&temph)&&(humi&humil&&humi&humih)&&DO==1)
& && &&&{
& && && && && & led1=0;
& && && && && & led2=0;
& && && && && & led3=0;
& && &&&}
}
void Initial_com(void)
{
EA=1;& && &&&//开总中断
ES=1;& && &&&//允许串口中断
ET1=1;& && &&&//允许定时器T1的中断
TMOD=0x20;& &//定时器T1,在方式2中断产生波特率
PCON=0x00;& &//SMOD=0
SCON=0x50;& &// 方式1 由定时器控制
TH1=0& & //波特率设置为9600
TL1=0
……………………
…………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
(60.79 KB, 下载次数: 22)
10:37 上传
点击文件名下载附件
下载积分: 黑币 -5
Powered by

我要回帖

更多关于 湿度检测模块程序 的文章

 

随机推荐