Page 154 - Embedded Microprocessor Systems Real World Design
P. 154
In cases like this, you must make special concessions. Most small microcon-
trollers have a simulator available. This is software that runs on a PC and emulates
the microcontroller. A simulator allows you to develop code and test it right at your
desk. Of course, simulators have one serious drawback-they cannot predict the
real world. A simulator can only simulate with the inputs you provide, and if you
cannot predict all the real-world timings, neither can the simulator software. On
the other hand, if your microcontroller design is doing something that is
predictable and not dependent on real-world timing, a simulator may be the only
debug tool you need.
The real environment, with moving motors and clicking solenoids, is where most
embedded designs end up, and this is where the limitations of a simulator are really
revealed. If a simulator is not adequate and if you cannot get or use an emulator,
then you must turn to other debugging techniques, such as those we’ll discuss in
Chapter 6.
Microprocessor Hardware
An embedded system has unique hardware constraints that must be accommodated
by the software.
The Stack
The stack, common to nearly all microprocessors, is where the software can
temporarily store values until they are needed. When a subroutine is called, the
processor saves the return address on the stack. The stack is a last in, first out
(LIFO) buffer-the last value placed “on” the stack is the first value removed, much
like spring-loaded stacks of plates in a restaurant buffet line.
Most (but not all) microprocessors have PUSH and POP instructions (or some
equivalent) that can add values to or remove values from the stack. This allows the
programmer to save registers during an interrupt and restore them later. The stack
in your PC can hold millions of bytes of information. The stack in an embedded
design is not always as flexible:
First, the stack in some microcontrollers is limited. The PIC17C42, for example,
has a 16-level stack and no PUSH or POP instructions. The stack is used for return
addresses only.
In processors that have a hardwired stack (implemented as fixed registers in the
microprocessor IC), you cannot have several levels of subroutines; the stack will
overflow. As already mentioned, you cannot pass parameters on the stack (at least,
not very many) for the same reason.
SofhUare Design 135