如果VDD或者VDDA电压高于或低于PVD设定阈值都产生中断,表现为每中断一次,LED1就亮变灭或者灭变亮。
- /********************************************************************************
- * @file PWR/PVD/main.c
- * @author MCD Application Team
- * @version V3.4.0
- * @date 10/15/2010
- * @brief Main program body.
- ******************************************************************************/
- /* Includes ------------------------------------------------------------------*/
- #include "stm32f10x.h"
- #include "stm32_eval.h"
- void EXTI_Configuration(void);
- void NVIC_Configuration(void);
- /**
- * @brief Main program.
- * @param None
- * @retval None
- */
- int main(void)
- {
- /*!< At this stage the microcontroller clock setting is already configured,
- this is done through SystemInit() function which is called from startup
- file (startup_stm32f10x_xx.s) before to branch to application main.
- To reconfigure the default setting of SystemInit() function, refer to
- system_stm32f10x.c file
- */
- /* Initialize LEDs and Key Button mounted on STM3210X-EVAL board */
- STM_EVAL_LEDInit(LED1);
-
- GPIO_SetBits(GPIOC, GPIO_Pin_7);
- /* Enable PWR and BKP clock */
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);//电源管理部分时钟开启
- /* Configure EXTI Line to generate an interrupt on falling edge */
- EXTI_Configuration();
- /* NVIC configuration */
- NVIC_Configuration();
-
- /* Configure the PVD Level to 2.9V */
- PWR_PVDLevelConfig(PWR_PVDLevel_2V9);// 设定监控阀值
- /* Enable the PVD Output */
- PWR_PVDCmd(ENABLE);// 使能PVD
-
- while (1)
- {
- }
- }
- /**
- * @brief Configures EXTI Lines.
- * @param None
- * @retval None
- */
- void EXTI_Configuration(void)
- {
- EXTI_InitTypeDef EXTI_InitStructure;
- /* Configure EXTI Line16(PVD Output) to generate an interrupt on rising and
- falling edges */
- EXTI_ClearITPendingBit(EXTI_Line16);
- EXTI_InitStructure.EXTI_Line = EXTI_Line16;// PVD连接到中断线16上
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;//使用中断模式
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling;//电压上升或下降越过设定阀值时都产生中断。
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;// 使能中断线
- EXTI_Init(&EXTI_InitStructure);// 初始
- }
- /**
- * @brief Configures NVIC and Vector Table base location.
- * @param None
- * @retval None
- */
- void NVIC_Configuration(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
-
- /* Configure one bit for preemption priority */
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);//中断优先级配置
-
- /* Enable the PVD Interrupt */ //设置PVD中断
- NVIC_InitStructure.NVIC_IRQChannel = PVD_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
- }
- /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/
注意:GPIO驱动LED模式为GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;还是推挽输出。中断处理函数:
点击(此处)折叠或打开
- void PVD_IRQHandler(void)
- {
- if(EXTI_GetITStatus(EXTI_Line16) != RESET)
- {
- /* LED1翻转 */
- STM_EVAL_LEDToggle(LED1);
- /* Clear the Key Button EXTI line pending bit */
- EXTI_ClearITPendingBit(EXTI_Line16);
- }
- }
阅读(953) | 评论(0) | 转发(0) |