Page 440 - Programming Microcontrollers in C
P. 440

A Clock Program     425

                          position. The next two calls send the hours to the screen. Then a
                          colon is printed. This sequence is repeated for the minutes and the
                          seconds except no colon is sent out after the seconds.
                              Our next problem is to set up the PIT. The PIT is to interrupt
                          once each 1.953125 milliseconds. The clock that drives the PIT runs
                          at 8192 Hz and we need a clock rate of 512 Hz. Therefore, we need
                          to count 16 clock ticks between interrupts. I will call this time TWO_MS
                          in the following code. The function below is an initialization function
                          to set up the PIT to operate as needed. Recall, data written to the
                          ITDR is transferred to the ITADR when the ITADR underflows. Data
                          written to the ITDR is automatically transferred to the ITADR if the
                          OVW bit is set when the ITDR is written. This bit will be set first and
                          then the value TWO_MS is written to the ITDR. Next, the reload mode
                          is enabled by setting the RLD bit in the ITCSR register. In this mode,
                          the value in the ITDR is automatically reloaded into the ITADR when
                          the ITADR underflows. This operation assures a periodic interrupt at
                          the period set by the value stored in the ITDR.
                              The interrupt handler shown in the section “Handling Interrupts”
                          will be used here. Recall that function contains a general-purpose
                          interrupt service routine that can be used for any of the autovector
                          interrupts in the MMC2001. For our purposes here, the interrupt vector
                          number 8 in Listing 8-9 will have to be changed from
                          unused_vector to the name of the PIT interrupt service routine.
                          We will call that routine pit_isr and it will be written in the next
                          section. The macro function vector() in the mmc2001.h header
                          file will be used to put the address of the header into the Fast
                          Autovector vector location. Also in the Interrupt Handler section you
                          will find Table 8-1. This table shows the allocation of the interrupt
                          vectors in the base vector table. This table is placed in a specified
                          location by the linker program. With the set-up used for our programs
                          in this book, I placed the system RAM at the address 0x30000000.
                          The first 0x200 entries in this table are the vector table whose outline
                          is shown in Table 8-1 and whose values are established by the interrupt
                          handler routine in Listing 8-9. There you will note that the Fast
                          Interrupt Autovector is offset 0x2c into the vector table. Therefore,
                          the address of the FAST_AUTOVECTOR in our program must be
                          0x3000002c. The next instruction in the code below will place the
                          address of the pit_isr interrupt service routine in this address.
   435   436   437   438   439   440   441   442   443   444   445