Listing 1 shows the ‘main’ function
and illustrates the super-loop concept.
After the system — which includes an
oscillator, I/O port configuration, and
peripherals like Timer1 — is initialized, the
global and peripheral interrupts are
enabled. The program then initializes the
application, which includes all application
data and the application’s state. (I’ll discuss the concept of
a state machine in a moment.) The program now enters
the super-loop where is stays forever. The two functions
within the super-loop are called repeatedly, over and over.
The reason for this is to allow all the different program
elements — like characters in an ESUART buffer to be
transmitted (system), for example, or user input from key
switches (app) — to be acted on in a timely manner. These
‘Task’ functions should be non-blocking; meaning they
should return as soon as possible to allow other elements
adequate processor time to do their tasks.
As system and application tasks become more
involved, it becomes necessary to employ some way of
breaking the tasks up into smaller ones that can be
accomplished more quickly to allow all elements enough
processor time. The state machine is one way to solve this
problem. Another method would be the use of a multi-tread operating system. The state machine is by far the
best solution for the smaller sized program memory of the
Wikipedia describes a state machine as “an abstract
machine that can be in one of a finite number of states.
The machine is in only one state at a time; the state it is in
at any given time is called the current state. It can change
from one state to another when initiated by a triggering
event or condition; this is called a transition. A particular
October 2017 17
Post comments on this article and find any associated files and/or downloads
■ FIGURE 2.
;'; .;'! (''-
;'; .;'! (''-
■ FIGURE 1.