Code:
void WATCH_DOG_INIT(void)
{
watch_dog_F =1;
// Start timed equence
WDTCR |= (1<<WDCE) | (1<<WDE);
// Set new prescaler(time-out)
WDTCR = (1<<WDE) | (1<<WDP2) | (1<<WDP1)|(1<<WDP0) |(0<<WDCE);
}
void RSET_WATCH_DOG(void)
{
wdt_reset(); // reset watch dog
watch_dog_counter = 10;
}
ISR() // 1ms isr
{
if(watch_dog_F ==1)
{
watch_dog_mili--;
if(watch_dog_mili==0)
{
watch_dog_mili=1500;
if(watch_dog_counter > 0)
{
watch_dog_counter--;
wdt_reset();
}
}
}
}
int main(void)
{
WATCH_DOG_INIT();
while(1)
{
/* Some work done over here */
RSET_WATCH_DOG();
}
}