程序:
void WWDG_Init(u8 tr,u8 wr,u8 fprer)
{
RCC->APB1ENR|=1<<11;
WWDG_CNT=tr&WWDG_CNT;
WWDG->CFR|=fprer<<7;
WWDG->CFR&=0XFF80;
WWDG->CFR|=wr;
WWDG->CR|=WWDG_CNT;
WWDG->CR|=1<<7;
MY_NVIC_Init(2,3,WWDG_IRQn,2);
WWDG->SR=0X00;
WWDG->CFR|=1<<9;
}
int main(void)
{
u8 t;
u8 len;
u16 times=0;
STM32_Clock_Init(9); //72MHz
delay(1000);
LED_Init();
KEY_Init();
LED0_SET(0);
delay(24000);
//IWDG_init(4,625);
WWDG_Init(0x7f,0x5f,3);
while(1)
{
LED0_SET(1);
//delay(8000);
}
}
void WWDG_Set_Counter(u8 cnt)
{
WWDG->CR=(cnt&0x7f);
}
void WWDG_IRQHandler(void)
{
WWDG_Set_Counter(WWDG_CNT);
WWDG->SR=0X00;
flag1=!flag1;
if(flag1==0)
{
LED1_SET(0);
//LED1_SET(0);
}
else
{
LED1_SET(1);
//LED1_SET(1);
}
}
功能:
初始化时,LED0先亮300ms,然后熄灭。接着窗口看门狗中断,LED1灯闪烁。
|