And this is the code
Watch dog timer is very popular feature of modern processors .It provide a facility to automatically reset the microcontroller when it goes to infinite loop or when a microcontroller hang up .The counter inside the watch dog timer register simply gives a signal when it count up and this signal can be used to trigger internal interrupt or to reset the microcontroller . And this feature is very important when you have a project that will run for long period of time . Like a dog watch house 24 hours a day and when thief enter house dog bark and inform to his keeper similarly this timer also watch microcontroller every time and when uncertainity occurs to microcontroller then it inform by generating some kind of signal and according to this signal necessary action can be taken .
The above example works in similar way . PORTA has continuous output of alternating sequence and when certain unexpected event occur watch dog timer generate a signal and PORTD LEDbar is turned on . that's all about the concept behind it . But to know how it works we need to have some knowledge of register inside the watch dog timer . All explanation of register to use a watch dog timer is shown below . These are taken from the data sheet of avr microcnotrller . If you do not have that data sheet please download from this link and have a look at these registers .doc2466_ATMEGA_16