stm32正点原子学习笔记(29)独立看门狗实验
iwdg.c
1 #include"iwdg.h" 2 3 void iwdg_init(uint8_t IWDG_Prescaler,uint16_t Reload) 4 { 5 IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); 6 IWDG_SetPrescaler(IWDG_Prescaler); 7 IWDG_SetReload(Reload); 8 IWDG_ReloadCounter(); 9 IWDG_Enable(); 10 11 }
iwdg.h
1 #ifndef __IWDG_H 2 #define __IWDG_H 3 4 #include "stm32f10x.h" 5 6 void iwdg_init(uint8_t IWDG_Prescaler,uint16_t Reload); 7 8 9 #endif
main.c
1 #include "exti.h" 2 #include "iwdg.h" 3 4 5 int main(void) 6 { 7 delay_init(); 8 LedInit(); 9 Exti_Init(); 10 iwdg_init(4,625);//1s,看门狗超时时间 11 LED0on; 12 delay_ms(200); 13 14 while(1) 15 { 16 if(KEY0_PRES==KEY0_PRES) 17 { 18 IWDG_ReloadCounter(); 19 } 20 } 21 }