STM32视频教程

DHT11温湿度传感器

作者:陈广
日期:2021-11-25


视频播放地址

点击播放

元件购买地址

如果链接失效,请找到【优信电子】店铺,然后搜以下东西。

DHT11温湿度传感器: https://item.taobao.com/item.htm?spm=a230r.1.14.16.49ba2013vrmKSV&id=641575273743&ns=1&abbucket=4#detail

杜邦线公对母,母对母,公对公各数根: https://item.taobao.com/item.htm?spm=a1z09.2.0.0.67002e8ds37D2b&id=554996667106&_u=ohtvhlod1e8

面包板: https://item.taobao.com/item.htm?spm=a1z10.3-c-s.w4002-21223910208.12.7dde6a4bsDd2YI&id=522572405070

USB逻辑分析仪购买地址

https://item.taobao.com/item.htm?spm=a1z09.2.0.0.67002e8ds37D2b&id=43809938149&_u=ohtvhloa8e7

DHT11温湿度传感器数据手册

http://iotxfd.cn/down/STM32/dht11-DataSheet.zip

代码

dht11.c 文件源码:

/*
 * dht11.c
 *
 *  Created on: Nov 26, 2021
 *      Author: cg2021
 */

#include "dht11.h"
#include "bit_banding.h"
#include "stm32f1xx_ll_gpio.h"

LL_GPIO_InitTypeDef GPIO_InitStruct = {0};

//将PC3设置为输出状态
void Set_GPIO_Output_State()
{
	GPIO_InitStruct.Pin = LL_GPIO_PIN_3;
	GPIO_InitStruct.Mode = LL_GPIO_MODE_OUTPUT;
	GPIO_InitStruct.Speed = LL_GPIO_SPEED_FREQ_HIGH;
	GPIO_InitStruct.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
	LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
}

//将PC3设置为输入状态
void Set_GPIO_Input_State()
{
	GPIO_InitStruct.Pin = LL_GPIO_PIN_3;
	GPIO_InitStruct.Mode = LL_GPIO_MODE_FLOATING;
	LL_GPIO_Init(GPIOC, &GPIO_InitStruct);
}

void Delay_ms(uint32_t delay)
{
	SysTick->CTRL = 0;
	SysTick->LOAD = 72000 * delay - 1;
	SysTick->VAL = 0;
	SysTick->CTRL = 5;
	while(!(SysTick->CTRL & 0x10000));
	SysTick->CTRL = 0;
}

int Dht11_Read(void)
{
	Set_GPIO_Output_State();
	PCout(3) = 0;
	Delay_ms(20);
	Set_GPIO_Input_State();
	return 0;
}
;

© 2018 - IOT小分队文章发布系统 v0.3