📄 延长watchdog的方法.txt
字号:
/*你可曾经为硬件看门狗的复位时间太短,而苦恼过,这个方法帮你解决问题.
用定时器喂狗,如果超过一定时间(程序跑飞,或整个中断都关闭,都会导致定时器不喂狗,导致看门狗的复位,从而延长了看门狗的复位时间)不喂就复位.
下面我以lcpRD2为例: */
sfr wdtres=0xa6; //
uchar count;
ledflash()
{ LED1=~LED1;
}
watchdog1()
{wdtres=0x1e;
wdtres=0xe1;
}
watchdog2()
{count=0;//1s
}
time0() interrupt 1
{ TH0=0xc1;// 16000 c1 80 最多65536-16383
TL0=0x80;
count++;
if(count<170)
{ watchdog1();
}
TF0 = 0;
}
main()
{count=0;
_alarm=0;
delay_10ms(20);
_alarm=1;
delay_10ms(20);
_alarm=0;
delay_10ms(30);
_alarm=1;
delay_10ms(30);
LED1=0;
delay_10ms(30);
LED1=1;
delay_10ms(30);
TMOD=0x21;//T0为定时
TH0=0xc1;//65536-15000
TL0=0x80;
TR0=1;//定时器开始工作
ET0=1;//允许定时器T0中断
EA=1;//开总中断
watchdog1();
while(1)
{
delay_10ms(50);
LED1=0;
delay_10ms(50);
LED1=1;
delay_10ms(50);
delay_10ms(50);
delay_10ms(50);
delay_10ms(25);
//delay_10ms(50);
watchdog2();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -