Page 310 - Programming Microcontrollers in C
P. 310
The MC68HC16 295
embedded controls, it is necessary to place the vectors into ROM. In
that case, the use of the routine vector.c is the best approach.
The use of the @port command is certainly not found in the
ANSI standard. It is possible to create a complete interrupt service
routine without the use of the @port. However, if C is used to the
maximum, the isr will have some built-in inefficiencies. For ex
ample, the language has no direct register commands so it is necessary
to create a function that saves the status of the computer on entry to
the routine, and another to restore the machine status prior to the
return from the interrupt. Also, a special function must be created to
execute the RTI instruction at the end of the interrupt service rou
tine. These assembly routines can be created as function calls and
saved in the header file. When they are used, it is wise to study care
fully the code generated by the compiler to make certain that there
are no errors in the code. For example, if a function should happen to
clear some space on the stack for local storage, the placement of an
RTI instruction in the C code sequence would cause the return op
eration to be executed before the stack is restored. Such an error will
cause serious problems in system performance if not corrected.
Both the @far and the @port commands are not in compliance
with the ANSI standard. It is recommended that you use these com
mands sparingly because their use causes nonportable code to be
generated with the compiler. So far in this text, we have used two
significantly different compilers. Each compiler manufacturer claims
that their compiler complies to ANSI. In the case of the C6805 com
piler from Byte Craft, it probably conforms as closely as can be
expected for such a primitive machine. Both the MC68HC11 and the
MC68HC16 compilers comply more closely to the standard than the
C6805. Both of these machines are so much more computer that one
should expect very close compliance. Any extension to the basic lan
guage should be used with care. The above two commands are
desirable and provide useful functions for the embedded control field.
The Cosmic compilers also have an extension that has not been
used in this text. The way in which they define the internal registers
to the machine is not standard, and it does not permit very efficient
use of bit manipulation by the compiler. The approach used here is
shown in the various header files written for the parts. The compiler
writer assumes that the use of a construct like