Page 309 - Programming Microcontrollers in C
P. 309
294 Chapter 6 Large Microcontrollers
program counter in this location will provide proper initialization of
the program counter.
In the example above, the interrupt service routine OC3_Isr is
placed in the address 0x46. Unfortunately, there is no easy way to
accomplish this placement. The structure address must be counted
by hand and the pointer placed at the correct location. The structure
members are initialized only up to the vector with the highest ad
dress. Note that the structure is global, so that its members will all be
initialized to zero unless otherwise assigned. Notice also that the
vectors up to vector number 0x18 are initialized. These vectors in
clude all of the program-generated exceptions. These areas are where
one would expect most of the problems to occur in debugging a pro
gram. The vector numbers 0x19 through 0xff are left initialized to
0. These vectors are all accessed by either the internal modules or
from external interrupts. If there are no hardware problems with the
system, it is unlikely that external devices will cause uncalled-for
interrupts, and if one of the internal modules causes an interrupt with
an uninitialized vector, the CPU16 will access the uninitialized inter
rupt vector.
One other problem can arise when debugging programs that
involve user-specified interrupts. In the event that the isr address
is improperly placed in the vector table, the program will become
lost whenever the interrupt occurs. If such a program exhibits bizarre
behavior, a good trick is to place a break point at the address 0. If the
vector is wrong, an interrupt will take the proper vector which will
contain a 0 and attempt to execute the code at the address 0. The
break point at this location will stop execution and give you a clue as
to the program error. A break point at _init_vector can also be
useful to determine where the program is when an unexplained
exception occurs.
If a compiler provides a mechanism that complies to the ANSI
standard and one that does not, it is better to choose the ANSI stan
dard mechanism rather than the nonstandard approach. For example,
ANSI states nothing about how to establish a vector table. The above
approach is but one of several that can be used to handle the place
ment of the vectors in the vector table. Another approach is to use the
vector macro that is found in hc16.h . The disadvantage to the
vector macro is that it can place a vector into RAM only. Often with