Page 152 - Programming Microcontrollers in C
P. 152
Coding Tips for Microcontrollers 137
is possible to read the data bits and display a disassembled version of
the code being read into the microcontroller. This display is also
quite useful in debugging the code.
Yet another display is called a logic analyzer. A logic analyzer is
an oscilloscope display that shows the logical status of the various
lines captured in the trace buffer. A logic analyzer is a separate device,
but it can have a built-in disassembler that displays the disassembled
code along with the condition of the designated lines.
The devices with logic analyzers and trace buffers are quite a bit
more expensive than the development boards discussed earlier. Some
of the development systems provide source level debugging capability
for high-level languages like C.
Another approach to development systems has been made
available in some of the newer microcontrollers. The microcontrollers
from the MC68HC16 family and those from the MC68300 family all
have a background mode of operation. When operating in the
background mode, these chips stop their normal computing and start
serial communications with an external computer. The background
mode can be entered as the result of an internal command or an
external signal. There are enough debug commands that can be
communicated over this port to allow complete debug of any program
that the microcontroller might be running. Minimum external circuitry
is needed to support the debug mode, so these high-powered chips
can operate as their own development environment. Here, the
development support is mostly software contained within the host
computer, and the deliverable system can contain all of the essential
components of a development system.
Coding Tips for Microcontrollers
One of the major tasks facing a programmer when writing code in
a high-level language for any microcontroller is to make the resulting
program as readable as possible. Other people who might later need to
read or modify your code must be able to understand what is going on
in your program. It is extremely important that mnemonics be used as
much as possible when dealing with various registers, their bit contents,
and special memory addresses throughout your programs; otherwise,
the resulting code will be a “quasi-C” program filled with many numbers
and funny-looking cast operations that will be largely incomprehensible
to others trying to maintain your program.