Interfacing DHT11 sensor with PIC16F877A – CCS C compiler

This topic shows how to interface PIC16F877A microcontroller with DHT11 digital relative humidity and temperature sensor using CCS PIC C compiler.
The following topic shows how the DHT11 sensor works and how to simulate it with PIC16F877A using Proteus software.
Interfacing PIC16F877A with DHT11 (RHT01) sensor Proteus simulation

To see how the DHT11 works just read the previous topic and the sensor datasheet.
Interfacing PIC16F877A with DHT11 sensor circuit:
Interfacing PIC16F877A with DHT11 sensor circuit
The circuit is simple, there is the microcontroller PIC16F877A, DHT11 sensor and 1602 LCD to display humidity and temperature results.
The DHT11 sensor has 4 pins:
VCC : Positive power supply (+5V)
DATA : Sensor data input and output
NC : Not connected terminal
GND : Ground (0V)
A pull-up resistor must be added between the DHT11 data pin and VCC (+5V) pin as shown in the circuit schematic (4.7K ~ 10K).
Interfacing PIC16F877A with DHT11 humidity and temperature sensor C code:
The interfacing code was tested with CCS PIC C compiler version 5.051.
If you want to understand the code please read the DHT11 datasheet.
Variables Time_out and k are used to test reading time to avoid wrong data reception and microcontroller hanging.
 

PIC16F877A with DHT11 relative humidity and temperature sensor video:
The following video shows the project circuit connected in a breadboard.