1
基于PIC18系列(PIC18F4520)单片机+DHT11的温湿度采集系统的设计与制作(Proteus仿真部分)
Proteus仿真连线图
//main.c
/*
* This Code is written to Developed to Extract Temperature and Humidity
* Data from the DHT11 Sensor using the one-wire Communication protocol.
* And Displays the Extracted Data on a 20x4 LCD Display.
* The Project uses an external XTAL of 4MHZ.
*
* Website: https://space.bilibili.com/314404732
//doubixiaohanhan
*/
#include "prototyper.h"
#pragma config OSC = HS
#pragma config LVP = OFF
#pragma config WDT = OFF
void main (void)
{
unsigned char RH_Integral;
unsigned char RH_Decimal;
unsigned char Temp_Integral;
unsigned char Temp_Decimal;
unsigned char Checksum;
unsigned char DataValid;
Port_Init ();
//doubixiaohanhan
LCD_Init ();
LCD_Stuff ();
while (1)
{
DHT11_Start ();
if (DHT11_Response ())
{
RH_Integral = DHT11_Read ();
RH_Decimal = DHT11_Read ();
Temp_Integral = DHT11_Read ();
Temp_Decimal = DHT11_Read ();
Checksum = DHT11_Read ();
DataValid = Check_Parity (Checksum, RH_Integral, RH_Decimal, Temp_Integral, Temp_Decimal);
if (DataValid)
{
DisplayTemp (Temp_Integral, Temp_Decimal);
DisplayHumidity (RH_Integral, RH_Decimal);
Delay10KTCYx (120); // A minimum Sample Period of 1.2 seconds @4MHZ
}
else
{
Parity_Error ();
}
} //doubixiaohanhan
else
{
Sensor_Unresponsive ();
}
}
}