独立看门狗(IWDG)由专用的内部低速时钟(LSI)驱动,能够在低功耗模式下正常工作。
根据寄存器描述,IWDG最大时间可以是(0xFFF/(32K/512))=65.52s
代码如下:
#define FEED_IWDG() {R32_IWDG_KR=0xAAAA;}
看门狗初始化
void IWDG_Enable()
{
R32_IWDG_KR=0x5555;
R32_IWDG_CFG |= (7<<12);
R32_IWDG_CFG &=0xFFFFF000;
R32_IWDG_CFG |=0xFFF;
R32_IWDG_KR=0xCCCC;
}
操作演示
void main()
{
IWDG_Enable();
PRINT("R32_IWDG_CFG = %x\\r\\n", R32_IWDG_CFG);
while(1){
FEED_IWDG();
}
}
如果不喂狗,缩减狗时间,操作如下:
void IWDG_Enable()
{
R32_IWDG_KR=0x5555;
R32_IWDG_CFG |= (7<<12);
R32_IWDG_CFG &=0xFFFFF000;
R32_IWDG_CFG |=0x10;
R32_IWDG_KR=0xCCCC;
}
void main()
{
IWDG_Enable();
PRINT("R32_IWDG_CFG = %x\\r\\n", R32_IWDG_CFG);
while(1){
}
}
运行结果如下:
文章来源:debugdabiaoge
|