Page 307 - Programming Microcontrollers in C
P. 307

292    Chapter 6  Large Microcontrollers

                          tor number. When programming the interrupt vectors in the several
                          peripheral modules of the MC68HC16, the programmer will select
                          the interrupt vector. When it comes time to place the interrupt ser­
                          vice routine address in the proper memory location, it is to the
                          vector address—NOT the vector number—that this value must be
                          assigned.
                              When setting up the vector table, a wise programmer will fill all
                          of the possible unused vector addresses with the address of a dummy
                          function that provides an orderly return to the program in the event
                          of an unexpected interrupt. Usually the first 0x18 or 24 vectors should
                          be filled with this address. An example function that can be used for
                          this type of operation is
                   static @port void _init_vector(void)
                   { }
                              This program will compile to a single RTI (return from interrupt)
                          that will return the program control to the location when the interrupt
                          occurred. A static function is not used often. When a function is
                          declared static, it can be seen only in the file in which it is defined.
                              Following is a listing of the routine vector.c. This program
                          is modeled closely after that provided with the Cosmic MC68HC16
                          C compiler.

                   extern@far@portvoid_stext(void);/*startup routine*/
                   extern @port void OC3_Isr(void); /* ISR address */
                   static @port void _init_vector(void);


                   static const struct reset {
                   @far @port void (*rst)(void); /* reset + code
                   extension */
                   unsigned short isp; /* initial stack pointer */
                   unsigned short dpp; /* direct page pointer */
                   @port void (*vector[252])(void); /* interrupt vectors */
                   }_reset = {
                     _stext,             /* 1-start address */
                     0x03fe,             /* 2-stack pointer */
                     0x0000,             /* 3-page pointer */
                     _init_vector, /* 4-Breakpoint */
                     _init_vector, /* 5-Bus Error */
   302   303   304   305   306   307   308   309   310   311   312