pic16f877-dht11-ReadingData

by Marwen Maghrebi
// Read data from sensor
unsigned char Read_Data(unsigned char* dht_data) {
    *dht_data = 0;
    
    for(char i = 0; i < 8; i++) {
        TMR1H = 0;              // Reset Timer1
        TMR1L = 0;
        
        while(!DHT11_PIN)       // Wait for rising edge
            if(TMR1L > 100)     // Timeout if low time > 100s
                return 1;
        
        TMR1H = 0;              // Reset Timer1
        TMR1L = 0;
        
        while(DHT11_PIN)        // Wait for falling edge
            if(TMR1L > 100)     // Timeout if high time > 100s
                return 1;
        
        if(TMR1L > 50)          // If high time > 50s = bit is 1
            *dht_data |= (1 << (7 - i));
    }
    
    return 0;                   // Return 0 (data read OK)
}
Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
-
00:00
00:00
Update Required Flash plugin
-
00:00
00:00