Have you wondered what is happening  when your system hangs and how is it coming back to its original state even after some false conditions occur?

It is the Watch Dog Timer or WDT that triggers a system reset or other correction action to the main program. The most common use of watchdog timers is in embedded systems, where this specialized timer is often a built-in unit of a micro-controller.

In PIC16F877A, the control register for WDT is in OPTION REGISTER. During normal operation, a WDT time-out generates a device RESET. If the device is in SLEEP mode, a WDT time-out causes the device to wake-up and continue with normal operation, this is known as a WDT wake-up.The WDT can be permanently disabled by clearing the WDTE configuration bit.