#include"wwdg.h"
#include"stm32f10x.h"
#include"delay.h"
#include"led.h"
u8 wwdg_cnt=0x7f;
void Wwdg_Init(u8 tr,u8 wv,u32 pre)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_WWDG,ENABLE);
wwdg_cnt=tr&wwdg_cnt;
WWDG_SetPrescaler(pre);
WWDG_SetWindowValue(wv);
WWDG_Enable(wwdg_cnt);
WWDG_ClearFlag();
Wwdg_NVIC_Init();
WWDG_EnableIT();
}
void Wwdg_NVIC_Init(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel=WWDG_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=2;
NVIC_InitStructure.NVIC_IRQChannelSubPriority=3;
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void WWDG_IRQHandler(void)
{
WWDG_SetCounter(wwdg_cnt);
WWDG_ClearFlag();
LED1=!LED1;
}
#include"led.h"
#include"stm32f10x.h"
void Led_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOE,ENABLE);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
GPIO_SetBits(GPIOB,GPIO_Pin_5);
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOE,&GPIO_InitStructure);
GPIO_SetBits(GPIOE,GPIO_Pin_5);
}
#include "stm32f10x.h"
#include"delay.h"
#include"led.h"
#include"wwdg.h"
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
delay_init();
Led_Init();
LED0=0;
delay_ms(300);
Wwdg_Init(0x7f,0x5f,WWDG_Prescaler_8);
while(1)
{
LED0=1;
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
WWDG_Enable(wwdg_cnt);初始化里有这个,原子的代码就是加了这句就可以了
哦,你用的精英,我在看看
在中断里设个断点,然后debug下
一周热门 更多>