Page 153 - Programming Microcontrollers in C
P. 153
138 Chapter 3 What Are Microcontrollers?
Modern large 8-bit systems are very nearly as complete as
yesterday’s mini-computers. Programs for microcontrollers are also
getting large, and they are increasingly being written by a team of
programmers instead of a single programmer. The management of
the programming task is much more important when a team is involved
because the person-to-person interface is the most “dangerous” in all
programming. It is easy for people to make mistakes; misspelled
words, interchanged order of parameters in a function argument,
passing incorrect data to a function, etc., are all problems that can
(and often will) arise when several people try to write a single
program. Each person on the team can probably keep a maximum of
six or seven function interfaces in mind, and even then mistakes will
be made. When the program is really large, there will be dozens of
function interfaces and sources of possible error will abound. For
example, most of the time programmers will try to use what is in
mind rather than look up a questionable function call.
How can these problems be minimized? Fortunately, there are
several steps you can take to keep errors down to a manageably low
level. A big one is to make certain that an ANSI-certified compiler can
be used for any program and that the computer will enforce strict type
checking in the program. This will cause most of the errors due to
carelessness or simple accidents to be caught at compile time and not
during the debugging phase. If such errors are not caught by the
compiler, they are among the most difficult to find when they show up
at run time. Programs can be improved by following these conventions:
1. Use a consistent constant definition naming convention. Use all capital
letters for the names of constants defined in #define statements.
2. Make all function names thoroughly descriptive. Use several words
for each name if possible, and capitalize the first letter of each
word so that the words can be distinguished easily. For example,
a function that returns the time should have a name like
TimeOfDay() or Time_Of_Day(). The important thing is
that the name describe the function in some detail. Be consistent
with naming conventions. If you start with names having no un
derscores, keep this convention throughout the entire program.
3. Make use of typedef and the fact that structures create new types.
Where possible, create a type that is descriptive to your program.
For example, in the C language the interface to all input/output and