main.c
#include "led.h"
#include "delay.h"
#include "sys.h"
#include "key.h"
#include "usart.h"
#include "iwdg.h"
int main(void)
{
delay_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
uart_init(9600);
LED_Init();
KEY_Init();
delay_ms(300);
IWDG_Init(4,625);
LED0=0;
while(1)
{
if(KEY_Scan(0)==WKUP_PRES)IWDG_Feed();
delay_ms(10);
};
}
iwdg.c
#include "iwdg.h"
#include "led.h"
void IWDG_Init(u8 prer,u16 rlr)
{
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
IWDG_SetPrescaler(prer);
IWDG_SetReload(rlr);
IWDG_ReloadCounter();
IWDG_Enable();
}
void IWDG_Feed(void)
{
IWDG_ReloadCounter();
}
iwdg.h
#ifndef __WDG_H
#define __WDG_H
#include "sys.h"
void IWDG_Init(u8 prer,u16 rlr);
void IWDG_Feed(void);
#endif
|