Page 1 of 1

Interfacing DHT11 with PIC

PostPosted: Tue Feb 14, 2012 5:32 pm
by shahrul
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.
CODE: SELECT_ALL_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;
}

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.
CODE: SELECT_ALL_CODE
sum=temp[0]+temp[1]+temp[2]+temp[3]+temp[4];
sum=sum&0xFF;

But, the value sum not equal to the fifth byte read from DHT11. Anyone know how the above function?

Re: Interfacing DHT11 with PIC

PostPosted: Wed Feb 15, 2012 6:23 pm
by shahrul
After I troubleshoot with oscilloscope, it's done now. DHT11 Lesson.