529
// Send start signal to the sensor void Start_Signal(void) { DHT11_PIN_DIR = 0; // Configure as output DHT11_PIN = 0; // Pull data line low __delay_ms(25); // Wait 25ms DHT11_PIN = 1; // Release data line __delay_us(30); // Wait 30us DHT11_PIN_DIR = 1; // Configure as input } // Check sensor response unsigned char Check_Response(void) { TMR1H = 0; // Reset Timer1 TMR1L = 0; TMR1ON = 1; // Enable Timer1 module while(!DHT11_PIN && TMR1L < 100); // Wait for DHT11_PIN to go high (80s low time) if(TMR1L > 99) // If response time > 99s return 0; // Return 0 (response error) TMR1H = 0; // Reset Timer1 TMR1L = 0; while(DHT11_PIN && TMR1L < 100); // Wait for DHT11_PIN to go low (80s high time) if(TMR1L > 99) // If response time > 99s return 0; // Return 0 (response error) return 1; // Return 1 (response OK) }