115 lines
2.5 KiB
C
115 lines
2.5 KiB
C
#include <ioCC2530.h>
|
|
#include "OnBoard.h"
|
|
//#include"DHT11.h"
|
|
|
|
typedef unsigned char uchar;
|
|
typedef unsigned int uint;
|
|
|
|
void Delay_us(void);
|
|
void Delay_10us(void);
|
|
void Delay_ms(uint Time);
|
|
void COM(void);
|
|
void DHT11(void);
|
|
|
|
uchar ucharFLAG,uchartemp;
|
|
uchar shidu_shi,shidu_ge, wendu_shi, wendu_ge=4;
|
|
uchar ucharT_data_H,ucharT_data_L,ucharRH_data_H, ucharRH_data_L,ucharcheckdata;
|
|
uchar ucharT_data_H_temp,ucharT_data_L_temp,ucharRH_data_H_temp, ucharRH_data_L_temp,ucharcheckdata_temp;
|
|
uchar ucharcomdata;
|
|
uchar ucharFLAG;
|
|
|
|
void Delay_us(void)
|
|
{
|
|
MicroWait(1);
|
|
}
|
|
|
|
void Delay_10us(void)
|
|
{
|
|
MicroWait(12);
|
|
}
|
|
|
|
#define DATA_PIN P0_7
|
|
|
|
void Delay_ms(uint Time)
|
|
{
|
|
unsigned char i;
|
|
while(Time--)
|
|
{
|
|
for(i=0;i<100;i++)
|
|
Delay_10us();
|
|
}
|
|
}
|
|
|
|
void COM(void)
|
|
{
|
|
uchar i;
|
|
for(i=0;i<8;i++)
|
|
{
|
|
ucharFLAG=2;
|
|
while((!DATA_PIN)&&ucharFLAG++);
|
|
Delay_10us();
|
|
Delay_10us();
|
|
Delay_10us();
|
|
uchartemp=0;
|
|
if(DATA_PIN)uchartemp=1;
|
|
ucharFLAG=2;
|
|
while((DATA_PIN)&&ucharFLAG++);
|
|
if(ucharFLAG==1)break;
|
|
ucharcomdata<<=1;
|
|
ucharcomdata|=uchartemp;
|
|
}
|
|
}
|
|
|
|
void DHT11(void) //¶ÁÈ¡Êý¾Ý
|
|
{
|
|
DATA_PIN=0;
|
|
Delay_ms(19); //>18MS
|
|
DATA_PIN=1;
|
|
P0DIR &= ~0x80;
|
|
Delay_10us();
|
|
Delay_10us();
|
|
Delay_10us();
|
|
if(!DATA_PIN)
|
|
{
|
|
ucharFLAG=2;
|
|
while((!DATA_PIN)&&ucharFLAG++);
|
|
ucharFLAG=2;
|
|
while((DATA_PIN)&&ucharFLAG++);
|
|
COM();
|
|
ucharRH_data_H_temp=ucharcomdata;
|
|
COM();
|
|
ucharRH_data_L_temp=ucharcomdata;
|
|
COM();
|
|
ucharT_data_H_temp=ucharcomdata;
|
|
COM();
|
|
ucharT_data_L_temp=ucharcomdata;
|
|
COM();
|
|
ucharcheckdata_temp=ucharcomdata;
|
|
DATA_PIN=1;
|
|
uchartemp=(ucharT_data_H_temp+ucharT_data_L_temp+ucharRH_data_H_temp+ucharRH_data_L_temp);
|
|
if(uchartemp==ucharcheckdata_temp)
|
|
{
|
|
ucharRH_data_H=ucharRH_data_H_temp;
|
|
ucharRH_data_L=ucharRH_data_L_temp;
|
|
ucharT_data_H=ucharT_data_H_temp;
|
|
ucharT_data_L=ucharT_data_L_temp;
|
|
ucharcheckdata=ucharcheckdata_temp;
|
|
}
|
|
wendu_shi=ucharT_data_H/10;
|
|
wendu_ge=ucharT_data_H%10;
|
|
|
|
shidu_shi=ucharRH_data_H/10;
|
|
shidu_ge=ucharRH_data_H%10;
|
|
}
|
|
else
|
|
{
|
|
wendu_shi=0;
|
|
wendu_ge=0;
|
|
|
|
shidu_shi=0;
|
|
shidu_ge=0;
|
|
}
|
|
|
|
P0DIR |= 0x80;
|
|
}
|