Page 363 - Programming Microcontrollers in C
P. 363
348 Chapter 7 Advanced Topics
interface for a component, I take the time when it is being created to
write stub functions to provide any necessary interface to test the
function. Every small function is tested as it is written.
The hierarchy of these functions is built upward. Those functions
that make use of the lower-level functions are coded and tested, and
so forth until the whole project is completed. Every function is written
and tested as it is created so that, as the program builds upward, it is
always based on known working modules. And this approach is used
to complete the whole program.
At every phase in the construction of the project the key words
are test, test, test. Every function is tested at its creation and, therefore,
the whole project is built upon relatively simple, small functions that
have been tested and work. Does this approach guarantee that no
bugs will be built into the program? Does it guarantee that the final
integrated version of the program will work as desired? In both cases,
the answer is a resounding NO. However, you have at least some
chance of creating a program that can be debugged and will meet the
desired specification. Also, you will find that writing and testing a
series of small functions always requires less time than writing and
testing the aggregate, more complicated function.
In summary, make your functions small, test them until there is no
possibility of hidden errors, revise them and retest them always with
the intent of reducing the function size. Then, when you have completed
the function, parade it in front of your peers and see if they can suggest
ways to improve the functions. Build your project with such blocks
and you will have a reasonable chance of meeting your deadlines.
In this chapter on the M68HC12, we will discuss programming
into the chip a part of the features of a telephone, or perhaps of an
electronic phone book. Note that the problem discussed here is but a
small part of the control of a telephone. A telephone book function is
one complete module that is a part of the telephone control.
As it stands, the HC12 has a small amount of EEPROM into
which a phone book can be stored. The chip also has a large amount
of FLASH ROM in which the program is stored. The FLASH memory
has some disadvantages that discourage its use to store the telephone
book data. On these chips, the FLASH memory is broken into two
parts. The smaller portion of the FLASH is called BOOT FLASH
and the larger portion is specified for general program storage. If
you need to erase any memory, the whole block, either the BOOT or