2,程序源码
PVD.h 文件
[mw_shl_code=c,true]/**
******************************************************************************
* @file PVD.h
* @Author XinLi
* @version v1.0
* @date 24-October-2017
* @brief Header file for PVD.c module.
******************************************************************************
* @attention
*
* <h2><center>Copyright © 2017 XinLi</center></h2>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
******************************************************************************
*/
#ifndef __PVD_H
#define __PVD_H
#ifdef __cplusplus
extern "C" {
#endif
/* Header includes -----------------------------------------------------------*/
#include "stm32f4xx.h"
/* Function definitions ------------------------------------------------------*/
#ifdef __cplusplus
}
#endif
#endif /* __PVD_H */
[/mw_shl_code]
PVD.c 文件
[mw_shl_code=c,true]/**
******************************************************************************
* @file PVD.c
* @author XinLi
* @version v1.0
* @date 24-October-2017
* @brief Power voltage detector driver.
******************************************************************************
* @attention
*
* <h2><center>Copyright © 2017 XinLi</center></h2>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
******************************************************************************
*/
/* Header includes -----------------------------------------------------------*/
#include "PVD.h"
#include <string.h>
/* Function declarations -----------------------------------------------------*/
/* Function definitions ------------------------------------------------------*/
/**
* @brief Power voltage detector initialize.
* @param [in] level: Power voltage detector level.
* @param [in] function: Power voltage detector callback.
* @return None.
*/
void PVD_Init(PVD_Level level, PVD_Callback function)
{
EXTI_InitTypeDef EXTI_InitStructure = {0};
NVIC_InitTypeDef NVIC_InitStructure = {0};
/**
* @brief Set power voltage detector level.
* @param [in] level: Power voltage detector level.
* @return None.
*/
void PVD_SetLevel(PVD_Level level)
{
PWR_PVDLevelConfig(level);
}
/**
* @brief Get power voltage detector level.
* @param None.
* @return Power voltage detector level.
*/
PVD_Level PVD_GetLevel(void)
{
uint32_t tmpreg = PWR->CR;
return (PVD_Level)(tmpreg & 0xE0);
}
/**
* @brief Set power voltage detector callback.
* @param [in] function: Power voltage detector callback.
* @return None.
*/
void PVD_SetCallback(PVD_Callback function)
{
callback = function;
}
/**
* @brief Get power voltage detector callback.
* @param None.
* @return Power voltage detector callback.
*/
PVD_Callback PVD_GetCallback(void)
{
return callback;
}
/**
* @brief Get power voltage detector output.
* @param None.
* @return Power voltage detector output.
*/
PVD_Output PVD_GetOutput(void)
{
uint32_t tmpreg = PWR->CSR;
return (PVD_Output)((tmpreg >> 2) & 0x01);
}
/**
* @brief This function handles the PVD Output interrupt request.
* @param None.
* @return None.
*/
void PVD_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line16) != RESET)
{
EXTI_ClearITPendingBit(EXTI_Line16);
main.c 文件
[mw_shl_code=c,true]/**
******************************************************************************
* @file main.c
* @author XinLi
* @version v1.0
* @date 24-October-2017
* @brief Main program body.
******************************************************************************
* @attention
*
* <h2><center>Copyright © 2017 XinLi</center></h2>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
******************************************************************************
*/
/* Header includes -----------------------------------------------------------*/
#include "main.h"
#include "PVD.h"
#include "LED.h"
一周热门 更多>