標(biāo)題: 溫度濕度代碼 [打印本頁]
作者: jwwww 時間: 2017-12-5 10:04
標(biāo)題: 溫度濕度代碼
//主程序清單:
#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低電平結(jié)束
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響應(yīng)信號
{
count=2;
while((!DHT11_IO)&&count++);
//DHT11高電平80us是否結(jié)束
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.torrancerestoration.com/bbs/) |
Powered by Discuz! X3.1 |