1.初始化
1.声明中断变量
NVIC_InitTypeDef NVIC_InitStructure;
2.打开WWDG时钟
RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG, ENABLE);
3.设置预分频器分频
WWDG_SetPrescaler(fprer);
4.设置窗口值
WWDG_SetWindowValue(wr);
5.喂狗
WWDG_SetCounter(WWDG_CNT);
6.中断配置
NVIC_InitStructure.NVIC_IRQChannel = WWDG_IRQn;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x02;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x03;
NVIC_Init(&NVIC_InitStructure);
7.首次清除WWDG中断标志位
WWDG_ClearFlag();
8.使能WWDG中断
WWDG_EnableIT();
2.WWDG中断
void WWDG_IRQHandler(void)
{
WWDG_SetCounter(WWDG_CNT);
WWDG_ClearFlag();
}