3.2 Main Loop

After initialization, the system calls a periodic self-test and state machine function every 0.5s when the Periodic Interrupt Timer (PIT) sets a flag. If this function is not called, the WDT will never be cleared, and the microcontroller will reset. The WDT runs in Windowed mode, triggering a microcontroller reset if clearing the WDT too quickly.

After running the state machine, the hour flag and the button 3 memory test flag are checked. If they are active, the appropriate flag is cleared, and the memory scan is performed. The memory scan is placed in the loop rather than the self-test because it is called infrequently and is very slow to complete. Figure 3-2 shows this behavior.

Figure 3-2. Main Loop Flowchart after Start-up