#include <avr/wdt.h>
#include <avr/interrupt.h>
#include <util/delay.h>
volatile int f_wdt=0;
int counter=1;
ISR(WDT_vect)
{
PORTA=~counter++;
}
int main(void) {
DDRA=0xFF;
PORTA = 0xFF;
/* Clear the reset flag. */
MCUSR &= ~(1<<WDRF);
/* In order to change WDE or the prescaler, we need to
* set WDCE (This will allow updates for 4 clock cycles).
*/
WDTCSR |= (1<<WDCE) | (1<<WDE);
/* set new watchdog timeout prescaler value */
WDTCSR = 1<<WDP2 | 1<<WDP1 | 1<<WDP0; /* 2.0 seconds */
// wdt_enable(WDTO_4S); // don't used, cause system reset.
/* Enable the WD interrupt (note no reset). */
WDTCSR |= _BV(WDIE);
sei(); // don't forget to activate global interrupt
while(1)
{
}
}