AT89S51中的內(nèi)部看門狗程序實現(xiàn)
#include
sfr WDTRST = 0xA6;
int Dog_Count=0;
void Clr_WDT();
void delay_50us(unsigned int t);
int main()
{
TMOD=0x11;
TH0=0x3C;TL0=0xB0; //50ms
TH1=0xFC;TL1=0x18; //1ms
ET0=1;ET1=1;
EA=1;
TR0=1;TR1=1;
Clr_WDT();
while(1)
{
Dog_Count=0;
}
return 0;
}
void Clr_WDT()
{
WDTRST = 0x1E;
WDTRST = 0xE1;
}
void IntTimer0 () interrupt 1
{
TH0=0x3C;
TL0=0x0B0;
}
void IntTimer1 () interrupt 3
{
if(Dog_Count<5000)
Clr_WDT();
Dog_Count++;
TH1=0xFC;
TL1=0x18;
}