您的位置 首页 资料

51单片机+DHT11温控程序-可设置温度值

基于51单片机的温湿度测量控制程序,使用DHT11数字传感器,用1602液晶屏显示,按键定义如下:sbitkey_1=P0^1;确定按键sbitkey_2=P0

根据51单片机的温湿度丈量操控程序,运用DHT11数字传感器,用1602液晶屏显现,按键界说如下:

sbit key_1=P0^1; //确认按键
sbit key_2=P0^2; //按键加
sbit key_3=P0^3; //按键减
本程序中用到的头文件 12c5a.h下载:http://www.51hei.com/f/12c5a.rar
#include “12c5a.H”
#include “intrins.h”

unsigned char code num[]={“0123456789”};//显现字符存储
unsigned char code start_char[]={“Loading….”};
unsigned char code t_char[]={“NOW TEMP IS”};
unsigned char *pnum=num;
unsigned int bbb,ccc,temp,temp_high,temp_low;

#define ADC_POWER 0x80 //ADC power control bit
#define ADC_FLAG 0x10 //ADC completeflag
#define ADC_START 0x08 //ADC start control bit
#define ADC_SPEEDLL 0x00 //540 clocks
#define ADC_SPEEDL 0x20 //360 clocks
#define ADC_SPEEDH 0x40 //180 clocks
#define ADC_SPEEDHH 0x60 //90 clocks

sbit RS=P3^4; //数据指令挑选端
sbit RW=P3^5; //读写操控端
sbit E=P3^6; //使能信号操控端
//sbit key_0=P0^0; //设置按键
sbit key_1=P0^1; //确认按键
sbit key_2=P0^2; //按键加
sbit key_3=P0^3; //按键减
sbit P04=P0^4;
sbit P05=P0^5;
sbit P06=P0^6;

void key_temphigh();
void key_templow();
void key_scan();
void delay_1602(unsigned int a);
void init_1602(void);
void WR_data_1602(unsigned char adata,unsigned char i);
void process(unsigned int shuju);

void Delay(unsigned char n)
{
int x;
while (n–)
{
x = 500;
while (x–);
}
}

void init_ADC(void)
{
P1ASF=0xFF;
ADC_RES = 0;
ADC_RESL = 0;
ADC_CONTR = 0x88;
Delay(2);
}

unsigned int GetResult(void)
{
unsigned char m,n;
unsigned int aaa;
init_ADC();
while (!(ADC_CONTR & ADC_FLAG)); //Wait completeflag
ADC_CONTR =0x80; //Close ADC
m=ADC_RES;
n=ADC_RESL;
aaa=m*4+n;
return aaa;
}
void start_init(void)
{
unsigned char i;
WR_data_1602(0x80,0); //显现在榜首行
for(i=0;i<11;i++)
WR_data_1602(start_char[i],1);
delay_1602(20);
init_ADC();
temp=GetResult()*5.0;
WR_data_1602(0x80,0); //显现在榜首行
for(i=0;i<11;i++)
WR_data_1602(t_char[i],1);
}

void delay_1602(unsigned int a) //延时
{
unsigned int i,j,k;
for(i=0;ifor(j=0;j<106;j++)
for(k=0;k<100;k++);
}

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/ziliao/317444.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部