欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
STM32單片機+DHT11溫濕度測量程序
[打印本頁]
作者:
小白EE
時間:
2022-10-6 16:19
標題:
STM32單片機+DHT11溫濕度測量程序
利用stm32f103c6t6和DHT11實現溫濕度測量
制作出來的實物圖如下:
51hei圖片_20221006161053.jpg
(1.05 MB, 下載次數: 39)
下載附件
溫濕度測量
2022-10-6 16:14 上傳
STM32單片機源程序如下:
#include "stm32f10x.h" // Device header
#include "Delay.h"
#define MCU_Output 1
#define MCU_Input 0
extern uint8_t DHT11_exist_Plag;// DHT11狀態標志位,0表示DHT11不存在,1表示DHT11存在
extern uint8_t Hum_Tem_Data[];// 存放溫濕度數據數組
/****
*@brief 引腳初始化,將DHT11與PA10相連
*@parameter MCU_State:MCU_State=1時,單片機引腳配置為輸出模式。MCU_State=0則配置為輸入模式
*@ReturnValue 無
*/
void DHT11_DataPin_Init(uint8_t MCU_State)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
if(MCU_State)
{
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
}else
{
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
}
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);
}
/****
*@brief DHT11起始信號
*@parameter
*@ReturnValue
*/
void DHT11_Start(void)
{
Delay_s(1);
DHT11_DataPin_Init(MCU_Output);
GPIO_SetBits(GPIOA,GPIO_Pin_10);
GPIO_ResetBits(GPIOA,GPIO_Pin_10);
Delay_ms(20);
GPIO_SetBits(GPIOA,GPIO_Pin_10);
Delay_us(30);
DHT11_DataPin_Init(MCU_Input);
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_10)==0)
{
DHT11_exist_Plag=1;
while(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_10)==0);
while(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_10)==1);
}
}
/****
*@brief DHT11溫濕度測量
*@parameter 無
*@ReturnValue 無
*/
void DHT11_GetData(void)
{
int8_t i,j,Temp=0x00;
if(DHT11_exist_Plag==1)// 檢測DHT11是否存在,若DHT11不存在,則不必進行下面步驟
{
for(j=0;j<5;j++)
{
for(i=0;i<8;i++)
{
while(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_10)==0);
Delay_us(30);
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_10)==1)
{
Temp=Temp|(0x80>>i);// DHT11數據高位先出
while(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_10)==1);
}
}
Hum_Tem_Data[j]=Temp;
Temp=0x00;
}
if(Hum_Tem_Data[0]+Hum_Tem_Data[1]+Hum_Tem_Data[2]+Hum_Tem_Data[3]!=Hum_Tem_Data[4])// 校驗數據是否正確,若不正確則數組全部寫1
{
Hum_Tem_Data[0]=0xff;
Hum_Tem_Data[1]=0xff;
Hum_Tem_Data[2]=0xff;
Hum_Tem_Data[3]=0xff;
}
}else
{
DHT11_Start();
}
}
復制代碼
DHT11_數據手冊.pdf
(681.04 KB, 下載次數: 29)
2022-10-6 16:16 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
Keil代碼下載:
Keil代碼.7z
(176.88 KB, 下載次數: 107)
2022-10-8 03:01 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1