如何使用STM32的PVD对电源的电压进行监控
O_InitStructure.O_Speed = O_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); //GPIO B } /******************************************************************* * Function Name : EXTI_Configuration * Description : Configures . * Input : None * Output : None * Return : None ********************************************************************/ void EXTI_Configuration(void) { EXTI_InitTypeDef EXTI_InitStructure; EXTI_DeInit(); EXTI_StructInit(&EXTI_InitStructure); EXTI_InitStructure.EXTI_Line = EXTI_Line16; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; EXTI_InitStructure.EXTI_LineCmd = ENABLE; EXTI_Init(&EXTI_InitStructure); // Configure EXTI Line16 to generate an interrupt } /*************************************************************************** * Function Name : NVIC_Configuration * Description : Configures Vector Table base location. * Input : None * Output : None * Return : None **************************************************************************/ void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; #ifdef VECT_TAB_RAM /* Set the Vector Table base location at 0x20000000 */ NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0); #else /* VECT_TAB_FLASH */ /* Set the Vector Table base location at 0x08000000 */ NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0); #endif STM32 中文应用文档 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); // Configure one bit for preemption priority NVIC_InitStructure.NVIC_IRQChannel = PVD_IRQChannel; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); // Enable the PVD Interrupt } 中断程序: /************************************************************************** * Function Name : PVD_IRQHandler * Description : This function handles PVD interrupt request. * Input : None * Output : None * Return : None ***************************************************************************/ void PVD_IRQHandler(void) { if (PWR_GetFlagStatus(PWR_FLAG_PVDO)) GPIO_WriteBit(GPIOB, 1 < 5, Bit_SET); else GPIO_WriteBit(GPIOB, 1 < 5, Bit_RESET); } 注:在void EXTI_Configuration(void)中,对于EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; 中的初始化值,根据你的需要进行修改,具体细节如下: EXTI_Trigger_Rising --- 表示电压从高电压下降到低于设定的电压阀值产生中断; EXTI_Trigger_Falling --- 表示电压从低电压上升到高于设定的电压阀值产生中断; EXTI_Trigger_Rising_Falling --- 表示电压从高电压下降到低于设定的电压阀值、或从低电压上升到高于设定的电压阀值产生中断。
STM32PVD监 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)