标题: 温度湿度代码 [打印本页]
作者: jwwww 时间: 2017-12-5 10:04
标题: 温度湿度代码
//主程序清单:
#include<reg52.h>
#include<stdio.h>
#include<intrins.h>
typedef unsigned charuint8;
typedef unsignedint uint16;
typedef unsigned charuchar;
typedef unsigned intuint;
void main()
{
uchar i;
RXBUF tmp;
EA=1;
EX0=1;
EX1=1;
IT0=1;
IT1=1;
while(1)
{
receive(&tmp);
for(i=0;i<100;i++)
{ BCDDisplay(tmp.HZ,tmp.WZ);
if(tmp.HZ>=25) DENG2=0;
else DENG2=1;
if(tmp.WZ>=30) DENG1=0;
else DENG1=1;
}
}
//温湿度显示子程序清单:
void start(void)
{ DHT11_IO=1;
Delay1();
DHT11_IO=0;
Delay2(20);//>18ms
DHT11_IO=1;
Delay1();//20-40us
Delay1();
Delay1();
Delay1();
Delay1();
}
ucharreceive_byte(void)
{ uchar i,temp,count;
for(i=0;i<8;i++)
{
count=2;
while((!DHT11_IO)&&count++)
//等待50us低电平结束
temp=0;
Delay1();Delay1();Delay1();Delay1();
if(DHT11_IO==1)temp=1;
count=2;
while((DHT11_IO)&&count++);
if(count==1)break;
data_byte<<=1;
data_byte|=temp;
}
return data_byte;
}
void receive(RXBUF*tmp)
{
uchar check,num_check;
uchar count;
start();//开始信号
DHT11_IO=1;
if(!DHT11_IO)//读取DHT11响应信号
{
count=2;
while((!DHT11_IO)&&count++);
//DHT11高电平80us是否结束
count=2;
while((DHT11_IO)&&count++);
tmp -> HZ = receive_byte();
tmp -> HX = receive_byte();
tmp -> WZ = receive_byte();
tmp -> WX = receive_byte();
check = receive_byte();
DHT11_IO=0;//拉低延时50us
DHT11_IO=1;
num_check = tmp -> HZ + tmp -> HX + tmp -> WZ + tmp-> WX;
if(num_check = check)
{ check =num_check;
}
}
}
//外部中断0的子程序清单:
void int0() interrupt0
{
while(WASI==0)
{
uint i;
for(i=0;i<250;i++)
{
BEEP= 0;
DENG4=0;
mDelay(50);
BEEP=1;
DENG4=1;
mDelay(50);
F_Rotation();
}
break;
}
while(WASI==0)
{
BEEP=0;
DENG4=0;
mDelay(150);
DENG4=1;
BEEP=1;
mDelay(150);
}
while(WASI==1)
{
B_Rotation();
break;
}
}
void BCDDisplay(ucharH,uchar W)
{
BCD_PORT = BCD[W / 100];
BCD1 = 0;
mDelay(10);
BCD1 = 1;
}
}
欢迎光临 (http://www.51hei.com/bbs/) |
Powered by Discuz! X3.1 |