Page 333 - Programming Microcontrollers in C
P. 333

318    Chapter 6  Large Microcontrollers

                              Lines 150 through 160 above are the interrupt service routine
                          OC3_Isr( ) and lines 161 through 166 comprise the PIT_Isr( ).
                          The main item that is observed here is the quality of the optimizer for the
                          compiler. In general, interrupt service routines, ISR, must save the com­
                          plete status of the machine prior to executing any code. The CCR along
                          with the PC are both saved by the interrupt sequence. The remainder of
                          the registers must also be saved if the ISR can use any of the additional
                          register resources of the computer. Usually this case will be found. Note,
                          for example, in OC3_Isr( ) the first instruction is

                   pshm k,z,y,x,d,e
                          This instruction causes the contents of all significant registers to be
                          saved on the stack, so that the status of the machine at the time the
                          interrupt occurred can be restored before control is returned to the
                          portion of the program that was interrupted. This restoration is com­
                          pleted by the two instructions
                   pulm k,z,y,x,d,e
                   rti
                          which refills all of the registers with the values they contained when
                          the ISR was entered, and the rti instruction restores the condition
                          code register to the value it had and the program counter is then
                          restored. Thus, the status of the machine is restored and the program
                          control is returned to the interrupted instruction. Note that the rou­
                          tine PIT_Isr( ) compiles to a much simpler routine. This routine
                          has simply two increment instructions and requires no register re­
                          sources. The optimizer recognizes this simple operation and does
                          not save the status beyond that saved when the interrupt occurred.
                              This routine has probably been pushed further than it should be,
                          for demonstration purposes. This routine demonstrates multiple in­
                          terrupts working simultaneously, keyboard input and output, and
                          generates a simple pulse-width modulation signal whose on period
                          is determined by a number entered from the keyboard. All of these
                          operations are quite similar to those shown in Chapter 5; however,
                          some major modifications in approach are required to meet the sev­
                          eral requirements of the peripheral components on the MC68HC16.
                          Let us now look at some other applications often used with
                          microcontrollers.
   328   329   330   331   332   333   334   335   336   337   338