void PVD_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
EXTI_InitTypeDef EXTI_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Enable the PVD Interrupt */
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);
/* Configure EXTI Line16(PVD Output) to generate an interrupt on rising edges */
EXTI_ClearITPendingBit(EXTI_Line16);
EXTI_InitStructure.EXTI_Line = EXTI_Line16;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger =EXTI_Trigger_Rising; //电压从高电压下降到低于电压的阀值产生中断
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
PWR_PVDLevelConfig(PWR_PVDLevel_2V9);
PWR_PVDCmd(ENABLE);
}
void PVD_IRQHandler(void)
{
u16 ledflag[2]={7,6};
if(PWR_GetFlagStatus(PWR_FLAG_PVDO))
{
EXTI_ClearITPendingBit(EXTI_Line16);
STMFLASH_Write(writeAddr,ledflag,2);
}
}
u16 led[2]={0};
int main(void)
{
u8 i=0;
RCC_Configuration();
delay_init();
LED_Init();
PVD_Config();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
STMFLASH_Read(writeAddr,led,2);
while(1)
{
if(led[0]==7)
{
GPIO_ResetBits(GPIOE,GPIO_Pin_5);
delay_ms(1000);
GPIO_SetBits(GPIOE,GPIO_Pin_5);
delay_ms(1000);
}
if(led[1]==8)
{
GPIO_ResetBits(GPIOB,GPIO_Pin_5);
delay_ms(1000);
GPIO_SetBits(GPIOB,GPIO_Pin_5);
delay_ms(1000);
}
}
}
断电时,把局部数组的值写入Flash, 然后上电读出数据,判断数据点亮LED。 现在是第一次断电,上电后LED正常工作;第二次断电,上电后LED不工作;第三次断电,上电后工作LED;第四次断电,上电后不工作。 求大神指导
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
没用的
一周热门 更多>