推荐星级:
  • 1
  • 2
  • 3
  • 4
  • 5

STM32F103开发板 DHT11温湿度DS18B20 气体MQ-2光敏声控雨滴传感器实验程序

更新时间:2020-06-19 07:29:46 大小:34M 上传用户:xzxbybd查看TA发布的资源 标签:stm32f103传感器 下载积分:6分 评价赚积分 (如何评价?) 收藏 评论(0) 举报

资料介绍

STM32F103开发板 DHT11温湿度DS18B20 气体MQ-2光敏声控雨滴传感器实验程序


**--------------------------------------------------------------------------------------------------------

** Created by: FiYu

** Created date: 2015-12-12

** Version:     1.0

** Descriptions: DHT11温湿度传感器实验

**--------------------------------------------------------------------------------------------------------

** Modified by: FiYu

** Modified date:

** Version:

** Descriptions:

** Rechecked by:

**********************************************************************************************************/

#include "stm32f10x.h"

#include "delay.h"

#include "dht11.h"

#include "usart.h"


DHT11_Data_TypeDef DHT11_Data;


/**************************************************************************************

 * 描  述 : GPIO/USART1初始化配置

 * 入  参 : 无

 * 返回值 : 无

 **************************************************************************************/

void GPIO_Configuration(void)

{

GPIO_InitTypeDef GPIO_InitStructure;

/* Enable the GPIO_LED Clock */

RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO , ENABLE);  

  GPIO_DeInit(GPIOB); //将外设GPIOA寄存器重设为缺省值

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;    //推挽输出

GPIO_Init(GPIOB, &GPIO_InitStructure);

GPIO_DeInit(GPIOA); //将外设GPIOA寄存器重设为缺省值

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;    //推挽输出

GPIO_Init(GPIOA, &GPIO_InitStructure);


GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;    //浮空输入

GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_SetBits(GPIOB , GPIO_Pin_9);   //初始状态,熄灭指示灯LED1

}


/**************************************************************************************

 * 描  述 : 串口显示实时温湿度

 * 入  参 : 无

 * 返回值 : 无

 **************************************************************************************/

void DHT11_SCAN(void)

{

if( Read_DHT11(&DHT11_Data)==SUCCESS)

{

printf("\r\n读取DHT11成功!\r\n\r\n湿度为%d.%d %RH ,温度为 %d.%d℃ \r\n",\

DHT11_Data.humi_int,DHT11_Data.humi_deci,DHT11_Data.temp_int,DHT11_Data.temp_deci);

//printf("\r\n 湿度:%d,温度:%d \r\n" ,DHT11_Data.humi_int,DHT11_Data.temp_int);

}

else

{

printf("Read DHT11 ERROR!\r\n");

}

}


/**************************************************************************************

 * 描  述 : MAIN函数

 * 入  参 : 无

 * 返回值 : 无

 **************************************************************************************/

int main(void)

{

SystemInit(); //设置系统时钟72MHZ

GPIO_Configuration();

USART1_Init();    //初始化配置TIM

DHT11_GPIO_Config();   // 初始化温湿度传感器PB1引脚初始时为推挽输出

GPIO_ResetBits(GPIOB , GPIO_Pin_9);

delay_ms(500);

  while(1)

  {

GPIO_SetBits(GPIOB , GPIO_Pin_9);

    DHT11_SCAN();  //实时显示温湿度

delay_ms(1500);

}

}





部分文件列表

文件名大小
STM32F103开发板 传感器实验程序/
STM32F103开发板 传感器实验程序/实验1 - 光敏传感器/
STM32F103开发板 传感器实验程序/实验1 - 光敏传感器/PhotoSensor/
STM32F103开发板 传感器实验程序/实验1 - 光敏传感器/PhotoSensor/Libraries/
STM32F103开发板 传感器实验程序/实验1 - 光敏传感器/PhotoSensor/Libraries/CMSIS/
STM32F103开发板 传感器实验程序/实验1 - 光敏传感器/PhotoSensor/Libraries/CMSIS/CM3/
STM32F103开发板 传感器实验程序/实验1 - 光敏传感器/PhotoSensor/Libraries/CMSIS/CM3/CoreSupport/
STM32F103开发板 传感器实验程序/实验1 - 光敏传感器/PhotoSensor/Libraries/CMSIS/CM3/CoreSupport/core_cm3.c
STM32F103开发板 传感器实验程序/实验1 - 光敏传感器/PhotoSensor/Libraries/CMSIS/CM3/CoreSupport/core_cm3.h
STM32F103开发板 传感器实验程序/实验1 - 光敏传感器/PhotoSensor/Libraries/CMSIS/CM3/DeviceSupport/
STM32F103开发板 传感器实验程序/实验1 - 光敏传感器/PhotoSensor/Libraries/CMSIS/CM3/DeviceSupport/ST/
...

全部评论(0)

暂无评论