======================= 华丽的代码分割线===============================
所有代码#include "LED.h"
void WDOG_Init(void);
void WDOG_Feed(void);
void WDOG_Close(void);
void WDOG_Open(void);
void main(void)
{
DisableInterrupts;
WDOG_Init(); //初始化看门狗
init_LED();
EnableInterrupts;
WDOG_Open(); //开启看门狗
Delay(1500);
while(1)
{
LED1(0);
LED2(0);
LED3(0);
LED4(0);
//WDOG_Feed(); //喂狗
}
}
void WDOG_Init(void)
{
WDOG_UNLOCK = 0xC520;
WDOG_UNLOCK = 0xD928; //解锁看门狗寄存器(重新写入前必须解锁)两次写入不能超过20个时钟周期
WDOG_PRESC = 0x0700; //(7+1)分频
WDOG_TOVALH = 0x0110; //看门狗超时时间设置为3s
WDOG_TOVALL = 0x5E90;
}
void WDOG_Feed(void)
{
WDOG_REFRESH = 0xA602;
WDOG_REFRESH = 0xB480; //喂狗
}
void WDOG_Close(void)
{
WDOG_UNLOCK = 0xC520u;
WDOG_UNLOCK = 0xD928u;
WDOG_STCTRLH &= ~0x0001; //关闭看门狗 WDOTEN 0
}
void WDOG_Open(void)
{
WDOG_UNLOCK = 0xC520;
WDOG_UNLOCK = 0xD928;
WDOG_STCTRLH |= 0x0001; //打开看门狗 WDOTEN 1
}
|