看门狗初始化,溢出时间是6.4ms
#include "iwdg.h"
void InitIWDG(void)
{
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);
IWDG_SetPrescaler(IWDG_Prescaler_256); // 40K/256=156HZ(6.4ms)
IWDG_SetReload(1250); // 1250 = 8s/6.4ms
IWDG_ReloadCounter(); // Î11·
IWDG_Enable();
}
如果下面的程序中的延时时间为2000ms,来一次喂狗,岂不是还没延时完成就已经看门狗复位了?
void PowerOFFPhone(void)
{
GPIO_WriteBit(GPIOB, RestPhone, Bit_RESET);
SoftDelayms(2000);
IWDG_ReloadCounter();
SoftDelayms(2000);
IWDG_ReloadCounter();
SoftDelayms(2000);
IWDG_ReloadCounter();
SoftDelayms(2000);
IWDG_ReloadCounter();
SoftDelayms(2000);
IWDG_ReloadCounter();
SoftDelayms(1000);
IWDG_ReloadCounter();
GPIO_WriteBit(GPIOB, RestPhone, Bit_SET);
BKP_WriteBackupRegister(BKP_DR1, 0X0000); // phone off state
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
延时方法多的是.最差的一种就是 延时函数.建议使用定时器或者时钟节拍.记数来延时.
一周热门 更多>