资源简介

STM32F4驱动人体红外传感器HC-SR501,使用STM32F4的外部中断,代码里文件夹是传感器的驱动移植文件,一个是最终修改工程,上传温湿度及红外探测次数到onenet平台~

资源截图

代码片段和文件信息

/**
  ******************************************************************************
  * @file    infrared.c 
  * @author  jinhao
  * @version V1.0.0
  * @date    22-April-2016
  * @brief   Main program body
  ******************************************************************************
  * @attention
  *
  * 

© COPYRIGHT 2016 STMicroelectronics


  *
  * Licensed under MCD-ST Liberty SW License Agreement V2 (the “License“);
  * You may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
  *
  *        http://www.st.com/software_license_agreement_liberty_v2
  *
  * Unless required by applicable law or agreed to in writing software 
  * distributed under the License is distributed on an “AS IS“ BASIS 
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  ******************************************************************************
  */
  
/* Includes ------------------------------------------------------------------*/
#include “stm32f4xx.h“
#include 

#include “infrared.h“

/* Defines --------------------------------------------------------------------*/


/* Variables ------------------------------------------------------------------*/


/* Functions ------------------------------------------------------------------*/
void Infrared_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;

RCC_AHB1PeriphClockCmd(Infrared_RCCENABLE); 

GPIO_InitStructure.GPIO_Pin=Infrared_Pin;
    GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN;
    GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_PuPd=GPIO_PuPd_DOWN;
    GPIO_Init(Infrared_GPIO &GPIO_InitStructure);
}

void Infrared_EXTI_Init(void)
{
EXTI_InitTypeDef EXTI_InitStructure;

/* 连接 EXTI 中断源 到INT1引脚 */
SYSCFG_EXTILineConfig(Infrared_Exti_PortInfrared_Exti_Pin);

/* 选择 EXTI 中断源 */
EXTI_InitStructure.EXTI_Line = Infrared_Exti_Line;
/* 中断模式 */
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
/* 上升沿下降沿触发 */
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;  
/* 使能中断/事件线 */
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
}

void Infrared_NVIC_Init(void)
{
NVIC_InitTypeDef NVIC_InitStruct;

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);

/* 配置中断源1 */
   NVIC_InitStruct.NVIC_IRQChannel = Infrared_IRQn;
   /* 配置抢占优先级:1 */
   NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 1;
   /* 配置子优先级:1 */
   NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1;
   /* 使能中断通道 */
   NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
   NVIC_Init(&NVIC_InitStruct);
}

void Infrared_Init(void)
{
Infrared_GPIO_Init();
Infrared_EXTI_Init();
Infrared_NVIC_Init();
}

u16 Infrared_Count = 0;

void Infrared_IRQHandler(void)
{
   //确保是

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-03-02 13:30  stm32f4人体红外传感器\
     目录           0  2018-03-02 13:30  stm32f4人体红外传感器\infrared\
     文件        3705  2018-03-02 13:52  stm32f4人体红外传感器\infrared\infrared.c
     文件        1257  2018-03-02 13:37  stm32f4人体红外传感器\infrared\infrared.h
     目录           0  2018-03-05 09:00  stm32f4人体红外传感器\stm32f407_iot\
     目录           0  2018-03-05 08:59  stm32f4人体红外传感器\stm32f407_iot\MDK\
     目录           0  2018-03-02 13:26  stm32f4人体红外传感器\stm32f407_iot\MDK\DebugConfig\
     文件        2084  2015-10-27 12:06  stm32f4人体红外传感器\stm32f407_iot\MDK\DebugConfig\Target_1_STM32F407ZGTx.dbgconf
     文件        2084  2015-10-27 12:06  stm32f4人体红外传感器\stm32f407_iot\MDK\DebugConfig\stm32f4_project_STM32F407ZGTx.dbgconf
     文件      126179  2018-03-05 08:46  stm32f4人体红外传感器\stm32f407_iot\MDK\JlinkLog.txt
     文件         762  2018-02-26 09:06  stm32f4人体红外传感器\stm32f407_iot\MDK\JlinkSettings.ini
     目录           0  2018-03-02 13:26  stm32f4人体红外传感器\stm32f407_iot\MDK\Listings\
     文件       77596  2018-03-02 13:28  stm32f4人体红外传感器\stm32f407_iot\MDK\Listings\startup_stm32f40_41xxx.lst
     文件      218881  2018-03-05 08:46  stm32f4人体红外传感器\stm32f407_iot\MDK\Listings\stm32f407_ex.map
     目录           0  2018-03-05 08:46  stm32f4人体红外传感器\stm32f407_iot\MDK\objects\
     文件        9817  2018-03-02 13:28  stm32f4人体红外传感器\stm32f407_iot\MDK\objects\dstream.crf
     文件         237  2018-03-02 13:28  stm32f4人体红外传感器\stm32f407_iot\MDK\objects\dstream.d
     文件       19532  2018-03-02 13:28  stm32f4人体红外传感器\stm32f407_iot\MDK\objects\dstream.o
     文件       15087  2018-03-02 13:28  stm32f4人体红外传感器\stm32f407_iot\MDK\objects\edpkit.crf
     文件         276  2018-03-02 13:28  stm32f4人体红外传感器\stm32f407_iot\MDK\objects\edpkit.d
     文件       38368  2018-03-02 13:28  stm32f4人体红外传感器\stm32f407_iot\MDK\objects\edpkit.o
     文件       14474  2018-03-05 08:23  stm32f4人体红外传感器\stm32f407_iot\MDK\objects\fault.crf
     文件         357  2018-03-05 08:23  stm32f4人体红外传感器\stm32f407_iot\MDK\objects\fault.d
     文件       18572  2018-03-05 08:23  stm32f4人体红外传感器\stm32f407_iot\MDK\objects\fault.o
     文件      448737  2018-03-05 08:46  stm32f4人体红外传感器\stm32f407_iot\MDK\objects\infrared.crf
     文件        2018  2018-03-05 08:46  stm32f4人体红外传感器\stm32f407_iot\MDK\objects\infrared.d
     文件      489520  2018-03-05 08:46  stm32f4人体红外传感器\stm32f407_iot\MDK\objects\infrared.o
     文件      463613  2018-03-05 08:44  stm32f4人体红外传感器\stm32f407_iot\MDK\objects\main.crf
     文件        2238  2018-03-05 08:44  stm32f4人体红外传感器\stm32f407_iot\MDK\objects\main.d
     文件      498748  2018-03-05 08:44  stm32f4人体红外传感器\stm32f407_iot\MDK\objects\main.o
     文件      443768  2018-03-02 13:28  stm32f4人体红外传感器\stm32f407_iot\MDK\objects\misc.crf
............此处省略258个文件信息

评论

共有 条评论