Page 455 - Programming Microcontrollers in C
P. 455

440    Chapter 8  MCORE, A RISC Machine

                          This location is entry number 6 in the vector table. The main()
                          function is broken into two sections, the initialization, and the
                          applications section. In initialization, inituart() establishes
                          connection with the serial I/O functions.  The function
                          attach_semaphore(‘a’) connects a semaphore to this process.
                          This semaphore is passed to the kpinit() function along with a
                          pointer to the beginning of the array a[] and also its length. The
                          address of the interrupt handler is placed into the autovector location
                          by the vector() function call, and finally the fast interrupts are
                          enabled when Enable_Fast_Interrupts() is executed.
                              In the main() application loop, the program waits for the release
                          of the semaphore sem that was attached earlier. At this time, the
                          keyboard handler has collected a buffer of data and has detected the
                          input of an ‘=’. Also, the decode has been completed so that it is
                          possible to execute puts(a) to send the contents of the buffer to
                          the serial port. After the data are written to the output, to continue
                          operation, it is necessary to reattach the original semaphore if it is
                          available and proceed. This particular program will remain in the
                          inner loop forever reading inputs from the keyboard and outputting
                          them to the serial port whenever an ‘=’ button is depressed.
                              Usually at this point, a single listing of the whole program is
                          included in the text. It is a duplicate of the various smaller segments
                          shown above. Here I will refer to the program listing that is contained
                          on the CD-ROM. It can be found under the directory chapter8
                          and has the name kbinit.c.

            Integrating Keyboard and Clock

                              The next piece of code will integrate the keyboard with the clock
                          developed earlier. The purpose of this program is to show the ease of
                          integrating these two programs and the use of more than one interrupt
                          simultaneously with the interrupt handler developed earlier. The main
                          change in the clock program will be to alter the reset_time()
                          function. This new function will receive inputs from the keypad. The
                          code developed in the previous section can be used, but it will have
                          to be altered significantly to be of use in this program. Here, we will
                          want to set up the keyboard input to interrupt when any key is
                          depressed and send a flag to the executing program when one or two
                          appropriate keys have been depressed. Let us increase the minutes
   450   451   452   453   454   455   456   457   458   459   460