engshahrul
Banned
Hi, I'm trying interfacing DHT11 with PIC. I'm using Hi-Tech compiler.
From information all over datasheet and internet, after sending start signal, DHT11 will reply 5 byte data. The last one is check sum.
This is my DHT11 start signal and DHT11 read byte. I give start signal and read 5 byte. Another 1, I calculate the sum of 5 byte.
But, the value sum not equal to the fifth byte read from DHT11. Anyone know how the above function?
From information all over datasheet and internet, after sending start signal, DHT11 will reply 5 byte data. The last one is check sum.
Code:
void dht11_start(void)
{
DataDir=0; // set pin as output
Data=0; // give low
__delay_ms(20);
Data=1; //give high
__delay_us(30);
DataDir=1; //set pin as input
while(Data==0) continue;
while(Data==1) continue;
}
char dht11_byte(void)
{int i;
char value=0;
for(i=0;i<8;i++){
while(Data==0) continue;
__delay_us(40);
if(Data==1){
value=value|(1<<(7-i));
while(Data==1) continue;}
}
return value;
}
Code:
sum=temp[0]+temp[1]+temp[2]+temp[3]+temp[4];
sum=sum&0xFF;
Last edited: