Temperature & Humidity Sensor

 void init_dht11(void)
  {
    DDRD|=(1<<DDD2);       //DD2 for read data
    PORTD|=(1<<PORTD2);    //Output high
    PORTD&=~(1<<PORTD2);   //Ouput Low for 18ms
    _delay_ms(18);
    PORTD|=(1<<PORTD2);    //Output high for relise bus
    DDRD&=~(1<<DDD2);      //Input sate declear for interrupt triger
    while(PIND&(1<<PIND2));//Wait for pull the data line low
    while(!(PIND&(1<<PIND2)));//wait 80us low
    while(PIND&(1<<PIND2)); //wait 80us high
    while(!(PIND&(1<<PIND2)));//wait 50us low
    sei();
    //SREG|=(1<<I);	       //Global interrupt enable
    GICR |=(1<<INT0);	   //External Interrupt Request 0 Enable
    MCUCR|=(1<<ISC00);	   //any edge of INT0 generates an interrupt request
 }
 uint8_t start_flag=1,millisecond;
/**** Interrupt service routine ********************/
ISR(INT0_vect)
{ 
 if(start_flag){
		pulse=TCNT0;
		TCCR0=0; // Timer stop
		if(pulse<30) sample[count]=0;
        else if(pulse>50 && pulse<75) sample[count]=1;
        count++;
        start_flag=0;
    }else{ // start timer with flag clear
    TCCR0|=(1<<CS01);                       //prescaler 8
    TCNT0=0;                                //intialize timer value
   start_flag=1;
  }
if(count>40) 
	{
		count=0;
		start_flag=1;
	}
}
/************************************************************************************************
*************************************************************************************************
This program will read the temperature and humidity data and display in LCD
             The value sould be update in every 5s
 
*************************************************************************************************
		Subeer Kumar Sarkar
		Electrical & Electronic Engineer
************************************************************************************************
************************************************************************************************
***********************************************************************************************/
#include<avr/io.h>
#include<util/delay.h>
#include<avr/interrupt.h>
#include"dht11.h"
#include"lcd.h"
char str[40],deg=223,hum=37;
int main(void)
{
LCD_INIT();         //LCD intilize
LCD_write_string(1,1,"Temp and Humidity");
timer2_250ms();
init_dht11();
_delay_ms(1000);
while(1)
{
 for(uint8_t i=0;i<8;i++)
 {
   humidity|=(sample[i]<<(7-i));
   temperature|=(sample[16+i]<<(7-i));
 }
 sprintf(str,"HR:%02d%c T:%02d%cC  ",humidity,hum,temperature,deg);
 LCD_write_string(1,2,str);
 temperature=0;humidity=0;
 _delay_ms(1000); //delay for LCD update
}
return 0;
}

Here timer2 is initialized at 250ms to call sensor at every 5s. So the data will be update in every 5s. One interesting thing that we use %02d to display only 2digit of temperature and humidity data.