Page 234 - Programming Microcontrollers in C
P. 234

Header File    219

                   extern void IC1_Isr(), OC3_Isr(),_stext();
                   void (* const vector[])()={0,0,0,0,0,0,0,OC3_Isr,0,
                   0,0,0,IC1_Isr, 0,0,0,0,0,0,0,_stext};
                              This two-line sequence identifies three functions, each of which
                          returns nothing. The first two are interrupt service routines that will
                          process interrupts from input capture 1 and output compare 3,
                          respectively. The third entry is the name of the entry point in the
                          start-up routine that is linked to the C program. The second line of
                          code indicates that vectoris an array of constpointers to functions
                          of the type void . There is one entry in this array for each interrupt
                          vector and the reset vector for the micro-controller. This array is
                          initialized with either zeros or the addresses of the interrupt service
                          routines in the proper locations. The address of the start-up routine is
                          placed in the last location in the array. This little program will be
                          compiled and linked to the final program. The name of the file that
                          contains this file is interrup.c , and it must be modified for each
                          program in which it is used. At link time, the address of vector[ ]
                          will be forced to 0xffd6 which is the beginning of the vector table
                          in the MC68HC11 family.
                              Some programmers will initialize the vector table with a known
                          address rather than 0. In the event that a spurious interrupt occurs and
                          takes the processor to an unused vector location, the processor would
                          certainly get lost if the vector table were filled with zeros. Placing a
                          known program into all unused vector locations will prevent this problem.
                              Another problem can occur in the operation of unattended
                          microcontrollers. It is possible that control of the microcontroller
                          could be diverted to unused ROM locations by serious noise spikes.
                          Such a loss of control will not be devastating if the system uses a
                          computer operating properly (COP) system. However, another safety
                          back-up that the programmer can incorporate into the program is to
                          fill all unused memory with the one-byte instruction swi (software
                          interrupt). This instruction causes the program to save the machine
                          status and pass control to the function addressed in the SWI vector
                          location. If this value contains the address of the start-up program,
                          the system will be restarted immediately if control is accidentally
                          moved to unused ROM.
   229   230   231   232   233   234   235   236   237   238   239