//EX16AVR ATmega8A watchdog reset//atuhor:QI小米粥//data:2018.3.29#include#includevoid delay(void) //延时半秒
{
int a,b,c;
for(a=0;a<8;a++)
for(b=0;b<28;b++)
for(c=0;c<250;c++) {}
}
void delay1(void) //延时半秒
{
int a,b,c;
for(a=0;a<8;a++)
for(b=0;b<25;b++)
for(c=0;c<250;c++) {}
}
void main(void)
{
DDRB |=BIT(0);
PORTB |=BIT(0);
while(1)
{
//watchdog program
WDTCR |=0X18;//写预定标的之前一定要WDTC置位
WDTCR |=0X0F;//watchdog time out 2.2s实测2.8s可能是因为不准吧
delay();
delay();
delay();
delay();
delay();
delay();
delay1();
//delay();
//delay();
//delay();
//delay();
//delay();
//delay();
WDTCR |=0X18;
WDTCR =0X07;
/*
//验证最长多少秒,可以不重启,示波器显示2.77s
PORTB |=BIT(0);
delay();
delay();
delay();
delay();
delay();
delay();
delay1();
PORTB &=~BIT(0);
delay();
delay();
delay();
delay();
delay();
delay();
delay1();
*/
}
}
网友评论