女人自慰AV免费观看内涵网,日韩国产剧情在线观看网址,神马电影网特片网,最新一级电影欧美,在线观看亚洲欧美日韩,黄色视频在线播放免费观看,ABO涨奶期羡澄,第一导航fulione,美女主播操b

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

基于PIC18系列單片機的DHT11溫濕度采集系統(tǒng)設計

CHANBAEK ? 來源:逗比小憨憨 ? 作者:逗比小憨憨 ? 2023-06-16 16:36 ? 次閱讀

基于PIC18系列(PIC18F4520)單片機+DHT11的溫濕度采集系統(tǒng)的設計與制作(Proteus仿真部分)

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 (); 
		}		
	} 
}
//config.c

#include "prototyper.h"

void Port_Init (void)
{
	TRISCbits.TRISC2 = 0; 			// Pin Used to Check Pwr on Ckt
	LATCbits.LATC2   = 1; 			//
	
	TRISD = 0x00;					// Port used for LCD
	LATD  = 0x00; 
}
//doubixiaohanhan
void LCD_Init (void)
{
	OpenXLCD (FOUR_BIT & LINES_5X7);
	while (BusyXLCD()); 
	WriteCmdXLCD (DISPLAY_ON);  		 // TURN DISPLAY ON cursor off
	while (BusyXLCD()); 									
	WriteCmdXLCD (0x80);				 // begin at the first line 
	while (BusyXLCD()); 
	WriteCmdXLCD (CLRSCR);	 			 // clear the lcd screen
}

void LCD_Stuff (void)
{
	while (BusyXLCD());
	putrsXLCD ("DHT11 Interfacing");
	
	while (BusyXLCD());
	WriteCmdXLCD (0xC0);				
	while (BusyXLCD());
	putrsXLCD ("Temp = "); //doubixiaohanhan
	
	while (BusyXLCD());
	WriteCmdXLCD (0xC9);
	while (BusyXLCD());
	putrsXLCD (".");
	
	while (BusyXLCD());
	WriteCmdXLCD (0xCC);
	while (BusyXLCD());
	putrsXLCD ("deg"); 
	
	
	while (BusyXLCD());
	WriteCmdXLCD (0x94);				
	while (BusyXLCD());
	putrsXLCD ("Humi = "); 
	
	while (BusyXLCD());
	WriteCmdXLCD (0x9D);
	while (BusyXLCD());
	putrsXLCD (".");
	
	while (BusyXLCD());
	WriteCmdXLCD (0xA0);
	while (BusyXLCD());
	putrsXLCD ("%");
}

void SerialInit (void)
{
   RCSTAbits.SPEN 	 = 0;	// disable serial port before configuring other parameters 
   TXSTAbits.SYNC    = 0;	// enable usart in asynchronous mode 
   //doubixiaohanhan
   			/******************* BaudRater Generation *************************/
   BAUDCONbits.BRG16 = 0;	// use the 8 bit spbrg protocol 
   TXSTAbits.BRGH    = 1;  	// use High speed 
   SPBRG = 0x19;			// to get a baud rate of 9600 bps @4MHZ

   RCSTAbits.SPEN 	 = 1;	// enable serial port //doubixiaohanhan
   TXSTAbits.TXEN    = 1;	// enable usart transmit	
}
//process.c

#include "prototyper.h"

void DelayFor18TCY (void)		
{
	Delay10TCYx (2);		        // a delay of 20 TCY
}

void DelayPORXLCD (void) 		
{
	Delay1KTCYx (15);     			// a delay of 15ms at 4 MHZ
}
//doubixiaohanhan
void DelayXLCD (void) 			
{
	Delay1KTCYx (5);				// a delay of 5ms at 4 MHZ  
}


void serialTx (unsigned char rx_data)
{
	TXREG = rx_data;
	Delay10TCY();	
}

void DHT11_Start (void)
{
	Data_Dxn = 0; 				// DataPin is set as an Output pin 
	
	Data_Out = 0; 				// Pull the DataBus line Low 
	Delay1KTCYx (20); 			// A Delay of At least 18ms @4MHZ 
		
	Data_Out = 1; 
	Delay10TCYx (3);			// A Delay of atleast 30us @4MHZ
	 	
	Data_Dxn = 1; 				// DataPin set as an Input pin//doubixiaohanhan
}

short int  DHT11_Response (void)
{	
	Delay10TCYx (4);			// A Delay of 40us @ 4MHZ
	
	if (Data_In == 0)			// If Data line is low 
	{
		Delay10TCYx (8);		// A Delay of 80us @ 4MHZ
		
		if (Data_In == 1)		// If Data Line is High 
		{
			Delay10TCYx (5);	// A Delay of 50us @ 4MHZ
			return 1; 
		}
	}	
}

unsigned char DHT11_Read (void)
{
	unsigned char i; 
	unsigned char data = 0x00; 
	unsigned char Time = 0; 
	
	for (i = 0; i < 8; i++)
	{
		while (!Data_In)			// Wait Till Line goes High
		{
			Time++; 
			if (Time > 100)
			{	
				break; 
			}
			
			Delay1TCY (); 			// A Delay of 1us @ 4MHZ
		}//doubixiaohanhan
		
		Delay10TCYx (3); 			// Wait for atleast 30us to check if bit is either 1 or 0
		
		if (!Data_In)				// Bit is 0				
		{
			data = (data < < 1) | 0; 
		}
		
		else 
		{
			data = (data < < 1) | 1; // Bit is 1
			
			Time = 0; 
			while (Data_In)			// Wait till Databus goes Low 
			{
				Time++; 
				if (Time > 100)
				{
					break; 
				}
				
				Delay1TCY (); 
			}		
		}
	}
	
	return data; 
}

unsigned char Check_Parity (unsigned char parity, unsigned char RHI, unsigned char RHD, unsigned char TI, unsigned char TD)
{	
	if (parity == (RHI + RHD + TI + TD))
	{
		return 1; 
	}
	else 
	{
		return 0; 
	}
}


void Humidity_Serial (unsigned char Int_Part, unsigned char Float_Part)
{
	unsigned char Tens; 
	unsigned char Ones; 
	unsigned char Dec; 
	
	Tens = Int_Part / 10; 
	Ones = Int_Part % 10;
	Dec = Float_Part;  
	
	Tens += 48;				// Convet To ASCII Counterparts
	Ones += 48;  			//
	Dec  += 48; 			// 
	
	serialTx ('H');
	Delay1KTCYx (2);
	serialTx ('\\r');
	
	serialTx (Tens);
	Delay1KTCYx (2);
	serialTx (Ones);
	Delay1KTCYx (2);
	serialTx ('.');
	Delay1KTCYx (2);
	serialTx (Dec);
	serialTx ('\\r');
	Delay1KTCYx (2);
	serialTx ('\\r');
	Delay1KTCYx (2);
}

void Temp_Serial (unsigned char Int_Part, unsigned char Float_Part)
{
	unsigned char Tens; 
	unsigned char Ones; 
	unsigned char Dec; 
	
	Tens = Int_Part / 10; 
	Ones = Int_Part % 10;
	Dec = Float_Part;  
	
	Tens += 48;				// Convet To ASCII Counterparts
	Ones += 48;  			//
	Dec  += 48; 			// 
	
	serialTx ('T');
	Delay1KTCYx (2);
	serialTx ('\\r');
	
	serialTx (Tens);
	Delay1KTCYx (2);
	serialTx (Ones);
	Delay1KTCYx (2);
	serialTx ('.');
	Delay1KTCYx (2);
	serialTx (Dec);
	serialTx ('\\r');
	Delay1KTCYx (2);
	serialTx ('\\r');
	Delay1KTCYx (2);
}

void ParityError (void)
{
	unsigned char i = 0; 
	unsigned char Parity [] = "Parity Error";
	
	while (Parity [i] != '\\0')
	{
		serialTx (Parity [i]);
		i++; 
		Delay1KTCYx (2);
	}
	
	serialTx ('\\r');
	Delay1KTCYx (2);
	serialTx ('\\r');
	Delay1KTCYx (2);
	
	Delay10KTCYx (50);
}

void SensorUnresponsive (void)
{
	unsigned char i = 0; 
	unsigned char Response [] = "Sensor Unresponsive"; 
	
	while (Response [i] != '\\0')
	{
		serialTx (Response [i]);
		i++; 
		Delay1KTCYx (2);
	}
	
	serialTx ('\\r');
	Delay1KTCYx (2);
	serialTx ('\\r');
	Delay1KTCYx (2);
	
	Delay10KTCYx (50);
}

void DisplayTemp (unsigned char Int_Part , unsigned char Float_Part)
{
	unsigned char Tens; 
	unsigned char Ones; 
	unsigned char Dec; 
	
	Tens = Int_Part / 10; 
	Ones = Int_Part % 10;
	Dec = Float_Part;
	
	while (BusyXLCD());
	WriteCmdXLCD (0xC7);
	
	if (Tens != 0)
	{
		while (BusyXLCD());	
		WriteDataXLCD (Tens + 48);
	}
	
	else 
	{
		while (BusyXLCD());
		putrsXLCD (" "); 		// Write nothing 	
	}
	
	while (BusyXLCD());	
	WriteDataXLCD (Ones + 48);
	
	while (BusyXLCD());
	WriteCmdXLCD (0xCA);
	
	while (BusyXLCD());	
	WriteDataXLCD (Dec + 48);	
}

void DisplayHumidity (unsigned char Int_Part , unsigned char Float_Part)
{
	unsigned char Tens; 
	unsigned char Ones; 
	unsigned char Dec; 
	
	Tens = Int_Part / 10; 
	Ones = Int_Part % 10;
	Dec = Float_Part;
	
	while (BusyXLCD());
	WriteCmdXLCD (0x9B);
	

	while (BusyXLCD());	
	WriteDataXLCD (Tens + 48);
		
	while (BusyXLCD());	
	WriteDataXLCD (Ones + 48);
	
	while (BusyXLCD());
	WriteCmdXLCD (0x9E);
	
	while (BusyXLCD());	
	WriteDataXLCD (Dec + 48);
}

void Parity_Error (void)
{
	while (BusyXLCD());
	WriteCmdXLCD (CLRSCR); 		// Clear Screen 
	
	while (BusyXLCD());
	putrsXLCD ("Parity Error!!");
	
	while (BusyXLCD());
	WriteCmdXLCD (CLRSCR); 		// Clear Screen 
}

void Sensor_Unresponsive (void)
{	
	while (BusyXLCD());
	WriteCmdXLCD (CLRSCR); 		// Clear Screen 
	
	while (BusyXLCD());
	putrsXLCD ("Sensor Unresponsive!");
	
	while (BusyXLCD());
	WriteCmdXLCD (CLRSCR); 		// Clear Screen 
}
//prototyper.h

#include < p18f4520.h >
#include < delays.h >
#include < xlcd.h >

#define CLRSCR 		0x01
#define DISPLAY_ON 	0x0C
#define DISPLAY_OFF 0x08


#define Data_Dxn TRISCbits.TRISC1
#define Data_Out LATCbits.LATC1
#define Data_In  PORTCbits.RC1
//doubixiaohanhan
//doubixiaohanhan
void DHT11_Start (void);
short int DHT11_Response (void);
unsigned char DHT11_Read (void);
unsigned char Check_Parity (unsigned char, unsigned char, unsigned char, unsigned char, unsigned char); 


void Port_Init (void);
void SerialInit (void); 
void serialTx (unsigned char); 

void Temp_Serial (unsigned char, unsigned char);
void Humidity_Serial (unsigned char, unsigned char);

void ParityError (void);
void SensorUnresponsive (void);

/*************************************** LCD Functions ************************************///doubixiaohanhan

void LCD_Init (void);
void LCD_Stuff (void); 

void DisplayTemp (unsigned char, unsigned char);
void DisplayHumidity (unsigned char, unsigned char);

void Parity_Error (void);
void Sensor_Unresponsive (void);
聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規(guī)問題,請聯系本站處理。 舉報投訴
  • 單片機
    +關注

    關注

    6062

    文章

    44915

    瀏覽量

    646669
  • Proteus
    +關注

    關注

    79

    文章

    1692

    瀏覽量

    108122
  • 仿真
    +關注

    關注

    51

    文章

    4234

    瀏覽量

    135290
  • DHT11
    +關注

    關注

    19

    文章

    277

    瀏覽量

    58258
  • 溫濕度采集系統(tǒng)

    關注

    0

    文章

    6

    瀏覽量

    6155
收藏 人收藏

    評論

    相關推薦
    熱點推薦

    溫濕度檢測系統(tǒng)》+折線圖顯示DHT11溫濕度數據

    ,與單片機之間,采用單總線通信方式。DHT11的數據結構:8bit濕度整數數據+8bit濕度小數數據+8bit溫度整數數據+8bit溫度小數數據+8bit校驗和本人只保留了
    發(fā)表于 06-28 22:25

    51單片機dht11溫濕度傳感器

    設計、軟件設計這三個方面來闡述。1.系統(tǒng)方案先來看一下整體的架構圖:硬件部分由STC89C52單片機、DHT11溫濕度傳感器、BT08藍牙串口模塊和Android手機組成。傳感器將
    發(fā)表于 07-14 07:45

    DHT11溫濕度傳感器介紹

    DHT11溫濕度傳感器介紹,1.實物原理圖2.模塊說明2.1 DHT11產品概述DHT11數字溫濕度傳感器是一款含有已校準數字信號輸出的
    發(fā)表于 07-21 09:04

    stm32單片機如何從DHT11獲取到溫濕度的呢

    stm32獲取DHT11模塊溫濕度數值原理解析stm32單片機如何從DHT11獲取到溫濕度的呢?首先可以通過
    發(fā)表于 11-22 06:11

    DHT11溫濕度傳感器簡介

    DHT11溫濕度傳感器1、DHT11簡介DHT11數字溫濕度傳感器是一款含有已校準數字信號輸出的溫濕度
    發(fā)表于 02-16 06:55

    基于DHT11的多點溫濕度報警系統(tǒng)設計

    單片機為控制核心,采用DHT11溫濕度傳感器,12864LCD顯示模塊,實現了實驗室多點溫濕度參數的實時采集、顯示和超限報警功能。
    發(fā)表于 09-14 10:09 ?7993次閱讀
    基于<b class='flag-5'>DHT11</b>的多點<b class='flag-5'>溫濕度</b>報警<b class='flag-5'>系統(tǒng)</b>設計

    DHT11采集溫濕度源程序

    DHT11采集溫濕度并用LCD12864顯示的源程序.可以使用的哈,分享給大家
    發(fā)表于 01-07 16:56 ?171次下載

    溫濕度DHT11資料

    含有已校準數字信號輸出的溫濕度復合傳感器,它應用專用的數字模塊采集技術和溫濕度傳感技術,確保產品具有極高的可靠性和卓越的長期穩(wěn)定性。傳感器包括一個電阻式感濕元件和一個NTC測溫元件,并與一個高性能8位
    發(fā)表于 11-29 17:28 ?28次下載

    DHT11溫濕度傳感器的AVR單片機例程

    DHT11溫濕度傳感器的AVR單片機例程
    發(fā)表于 05-16 14:46 ?26次下載
    <b class='flag-5'>DHT11</b><b class='flag-5'>溫濕度</b>傳感器的AVR<b class='flag-5'>單片機</b>例程

    使用51單片機實現DHT11溫濕度檢測的代碼程序免費下載

    本文檔的做作業(yè)內容詳細介紹的是使用51單片機實現DHT11溫濕度檢測的代碼程序免費下載。
    發(fā)表于 10-18 11:31 ?142次下載
    使用51<b class='flag-5'>單片機</b>實現<b class='flag-5'>DHT11</b><b class='flag-5'>溫濕度</b>檢測的代碼程序免費下載

    51單片機DHT11溫濕度ESP8266WiFi手機APP顯示設計

    系統(tǒng)方案DHT11溫濕度傳感器采集數據傳送給單片機,單片機將數據處理之后通過ESP8266Wi
    發(fā)表于 11-04 16:21 ?120次下載
    51<b class='flag-5'>單片機</b><b class='flag-5'>DHT11</b><b class='flag-5'>溫濕度</b>ESP8266WiFi手機APP顯示設計

    基于51單片機+DHT11溫濕度+LCD1602顯示

    main.clcd1602.clcd1602.hdelay.cdelay.h項目展示DHT11溫濕度相關介紹DHT11產品概述DHT11數字溫濕度
    發(fā)表于 11-12 11:51 ?123次下載
    基于51<b class='flag-5'>單片機</b>+<b class='flag-5'>DHT11</b><b class='flag-5'>溫濕度</b>+LCD1602顯示

    687【畢設課設】基于單片機溫濕度DHT11智能晾衣架系統(tǒng)

    687【畢設課設】基于單片機溫濕度DHT11智能晾衣架系統(tǒng)
    發(fā)表于 11-13 10:36 ?20次下載
    687【畢設課設】基于<b class='flag-5'>單片機</b><b class='flag-5'>溫濕度</b><b class='flag-5'>DHT11</b>智能晾衣架<b class='flag-5'>系統(tǒng)</b>

    stm32獲取DHT11模塊溫濕度數據原理解析

    stm32獲取DHT11模塊溫濕度數值原理解析stm32單片機如何從DHT11獲取到溫濕度的呢?首先可以通過
    發(fā)表于 11-13 20:06 ?55次下載
    stm32獲取<b class='flag-5'>DHT11</b>模塊<b class='flag-5'>溫濕度</b>數據原理解析

    STM32單片機利用DHT11采集溫濕度

    測量原理:DHT11內部集成了一個8位單片機、電阻濕度傳感器和NTC來采集外部的溫濕度,單片機
    發(fā)表于 12-27 19:22 ?14次下載
    STM32<b class='flag-5'>單片機</b>利用<b class='flag-5'>DHT11</b><b class='flag-5'>采集</b><b class='flag-5'>溫濕度</b>