/****************************************************************************************************************
*************************
*Author:JYW
*Time:2019_04_24
*Describe:LetAllLinesOfCodeSpeak
*****************************************************/
/*************************************
*Auther:JYW
*Time:2019_04_24
*Describe:代码练习DHT11等驱动练习
*********************************/
#define BV(x) 1<<x
void COM()
{//首先读入的是高位
unsigned char i = 0;
for(i= 0; i<8;i++)
{
uchartemp = 0;
ucharFLAG = 2;
while((!DATA_PIN)&&ucharFLAG++);
Delay_us(30);
if(DATA_PIN) uchartemp = 1;
ucharFLAG = 2;
while((DATA_PIN)&&ucharFLAG++);
if(DATA_PIN) break;//这一行代码在自己写的时候忘记了
ucharDATA <<=1;
ucharDATA |=uchartemp;
}
}
void DHT11()
{
P0DIR = BV(7);//输出
DATA_PIN = 0;
Delay_ms(19);
DATA_PIN = 1;
P0DIR = ~(DV(7));//输入
Delay_us(40);
if(!DATA_PIN)
{
ucharFLAG = 2;
while((!DATA_PIN)&&ucharFLAG++);
ucharFLAG = 2;
while((DATA_PIN)&&ucharFLAG++);
COM();
HumBuf_H = ucharDATA;
COM();
HumBuf_L = ucharDATA;
COM();
TempBuf_H = ucharDATA;
COM();
TempBuf_L = ucharDATA;
COM();
CheckBufData = ucharDATA;
if(CheckBufData = HumBuf_H + HumBuf_L + TempBuf_H + TempBuf_L)
{
Hum_H = HumBuf_H;
Hum_L = HumBuf_L;
Temp_H = TempBuf_H;
Temp_L = TempBuf_L;
CheckData = CheckBufData;
}
wendu_shi = Temp_H/10;
wendu_ge = Temp_H%10;
shidu_shi = Hum_H /10;
shidu_ge = Hum_H %10;
}
else
{
wendu_shi = 0;
wendu_ge = 0;
shidu_shi = 0;
shidu_ge = 0;
}
P0DIR = BV(7);//输出
}