Page 191 - Programming Microcontrollers in C
P. 191

176    Chapter 4  Small 8-Bit Systems

                   0325 26 04 BNE $032B
                   0327 A6 01 LDA #$01 hrs=1;
                   0329 B7 C0 STA $C0 }
                                                  }
                   032B 20 E0 BRA $030D }
                   032D 81 RTS }


                          void __TIMER(void)
                   07F8 03 2E {
                   032E 1D 08 BCLR 6,$08 TCST.RTIF=0;
                   0330 3C C3 INC $C3 if (++count==122)
                   0332 B6 C3 LDA $C3
                   0334 A1 7A CMP #$7A
                   0336 26 04 BNE $033C
                        {
                   Timers
                   0338 3C C2 INC $C2 sec++;
                   033A 3F C3 CLR $C3 count=0;
                        }
                   033C 80 RTI }


                   07FE 03 00
                              At the beginning of the interrupt service routine there is an entry
                          07f8, which has a value of 032e, in the address column. This entry
                          places the address of the timer interrupt service routine 0x032e
                          into the timer vector 0x07f8. The code generated in the interrupt
                          service routine is straightforward and little different from what one
                          would expect an assembly language programmer to do. Note, how­
                          ever, that the return at the end of the interrupt service routine is an
                          RTI instruction. This is the instruction that causes the microcontroller
                          to restore the processor status to the state that existed when the inter­
                          rupt occurred. The normal return from subroutine RTS does not restore
                          the processor state. An RTI must be used to return from interrupt
                          service routines, and any function identified with a vector pragma
                          will be assumed to be an interrupt service routine by the compiler.
                              It was noted earlier that this timer routine is inaccurate. It is inac­
                          curate only because 122 periods of 8.192 milliseconds each total
                          0.999424 seconds. This seemingly small error will cause big problems
   186   187   188   189   190   191   192   193   194   195   196