在线观看www成人影院-在线观看www日本免费网站-在线观看www视频-在线观看操-欧美18在线-欧美1级

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

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

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

CHANBAEK ? 來(lái)源:逗比小憨憨 ? 作者:逗比小憨憨 ? 2023-06-16 16:36 ? 次閱讀

基于PIC18系列(PIC18F4520)單片機(jī)+DHT11的溫濕度采集系統(tǒng)的設(shè)計(jì)與制作(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);
聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • 單片機(jī)
    +關(guān)注

    關(guān)注

    6066

    文章

    44946

    瀏覽量

    648315
  • Proteus
    +關(guān)注

    關(guān)注

    79

    文章

    1692

    瀏覽量

    108291
  • 仿真
    +關(guān)注

    關(guān)注

    51

    文章

    4250

    瀏覽量

    135454
  • DHT11
    +關(guān)注

    關(guān)注

    19

    文章

    277

    瀏覽量

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

    關(guān)注

    0

    文章

    6

    瀏覽量

    6158
收藏 人收藏

    評(píng)論

    相關(guān)推薦
    熱點(diǎn)推薦

    基于arduino的dht11溫濕度傳感器的使用

    本文介紹了DHT11溫濕度傳感器電氣特性、DHT11封裝形式及接口說明與典型應(yīng)用電路,其次介紹了DHT11溫濕度傳感器時(shí)序圖與連接圖,最后介
    發(fā)表于 01-22 15:50 ?4.5w次閱讀
    基于arduino的<b class='flag-5'>dht11</b><b class='flag-5'>溫濕度</b>傳感器的使用

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

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

    51單片機(jī)dht11溫濕度傳感器

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

    DHT11溫濕度傳感器介紹

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

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

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

    DHT11溫濕度傳感器簡(jiǎn)介

    DHT11溫濕度傳感器1、DHT11簡(jiǎn)介DHT11數(shù)字溫濕度傳感器是一款含有已校準(zhǔn)數(shù)字信號(hào)輸出的溫濕度
    發(fā)表于 02-16 06:55

    基于DHT11的多點(diǎn)溫濕度報(bào)警系統(tǒng)設(shè)計(jì)

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

    DHT11采集溫濕度源程序

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

    溫濕度DHT11資料

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

    DHT11溫濕度傳感器的AVR單片機(jī)例程

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

    使用51單片機(jī)實(shí)現(xiàn)DHT11溫濕度檢測(cè)的代碼程序免費(fèi)下載

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

    51單片機(jī)DHT11溫濕度ESP8266WiFi手機(jī)APP顯示設(shè)計(jì)

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

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

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

    stm32獲取DHT11模塊溫濕度數(shù)據(jù)原理解析

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

    STM32單片機(jī)利用DHT11采集溫濕度

    測(cè)量原理:DHT11內(nèi)部集成了一個(gè)8位單片機(jī)、電阻濕度傳感器和NTC來(lái)采集外部的溫濕度單片機(jī)
    發(fā)表于 12-27 19:22 ?14次下載
    STM32<b class='flag-5'>單片機(jī)</b>利用<b class='flag-5'>DHT11</b><b class='flag-5'>采集</b><b class='flag-5'>溫濕度</b>
    主站蜘蛛池模板: 好男人社区www在线观看 | 欧美国产精品主播一区 | www.97色| 亚洲综合精品一区二区三区中文 | 奇米影视四色7777 | 天天干b | 六月色| 国产高清免费在线观看 | 人人玩人人弄人人曰 | 2022国产情侣真实露脸在线 | 啪啪免费视频网站 | 午夜看片网址 | 色多多www | 国产亚洲精品成人一区看片 | 亚洲成网站 | 免费日本黄色网址 | www.最色| 性网站免费 | 日韩第五页 | 国产特级毛片aaaaaa毛片 | 狠狠操夜夜爽 | 欧美精品一二区 | 午夜视频在线观看一区二区 | 中国人黑人xxⅹ性猛 | 三a大片 | 欧美tube44videos| 午夜片 飘香香影院 | 天天干夜夜笙歌 | 婷婷丁香在线观看 | 毛片观看网址 | 色黄视频 | 国模一区二区三区私啪啪 | 国产区亚洲区 | 日韩大尺度视频 | 真实的国产乱xxxx在线 | 国产在线99| 国产好深好硬好爽我还要视频 | 久久青草91免费观看 | 国产69精品久久 | 欧美在线成人午夜影视 | www.九九热 |