Using watch-dog timer
This example illustrates how the watch-dog timer should not be used. A command used for resetting this timer is intentionally left out in the main program loop, thus enabling it to win the time battle and cause the microcontroller to be reset. As a result, the microcontroller will be reset all the time, which is reflected as PORTB LED blinking./*Header******************************************************/ void main() { OPTION_REG = 0x0E; // Prescaler is assigned to timer WDT (1:64) asm CLRWDT; // Assembly command to reset WDT timer PORTB = 0x0F; // Initial value of the PORTB register TRISB = 0; // All port B pins are configured as outputs Delay_ms(300); // 30mS delay PORTB = 0xF0; // Porta B value different from initial while (1); // Endless loop. Program remains here until WDT // timer resets the microcontroller }In order to make this example work properly, it is necessary to enable the watchdog timer by selecting the Watchdog Timer - Enabled option in mE programmer.