Page 451 - Programming Microcontrollers in C
P. 451

436    Chapter 8  MCORE, A RISC Machine

                          {
                              decode(savedata);
                              release_semaphore(semaph);
                          }
                          KPDRB.COLUMNS=0X0; /* write 0 to KPDR[15:8] */
                          KPSR.KDIE=OFF;/* disable key depress interrupt */
                          KPSR.KRIE=ON;  /* enable key release interrupt */
                       }
                       else  /* key release was detected */
                       {
                          KPSR.KPKR=ON;
                          KPSR.KPKD=ON;  /* clear key release and depress */
                          KPSR.KRSS=ON;  /* set key release synchronizer */
                          KPSR.KDSC=ON;  /* clear key depress synchronizer */
                          KPDRB.COLUMNS=0X0;/* write 0 to KPDR[15:8] */
                          KPSR.KDIE=ON;  /* enable key depress interrupt */
                          KPSR.KRIE=OFF;/* disable key release interrupt */
                       }
                   }
                              Notice in the code above that after the columns value is set and
                          before the row values are tested, there is a comment to kill some
                          time. It turns out that some time is required to allow propagation
                          from the command to the electrical connection on the external switch.
                          The delay() routine with an argument of 1, a 1-ms delay, worked
                          well, but this routine also uses the PIT. It is intended to use this
                          routine with the clock shown in the earlier section, so it is very
                          inconvenient to use the clock. Therefore, a series of instructions
                          around the keyboard controller were put together that would use up
                          the necessary time. These instructions would have to be executed to
                          set up correct conditions prior to the return from interrupt, so it is not
                          too much a waste of computer resources. To get enough delay, I used
                          some of these instructions more than one time. The code for this
                          time delay is shown below. The last six lines of code are required to
                          set up for the exit from the isr, and the first four are duplicates needed
                          to round out the time.
                   KPSR.KRSS=ON;
                   KPSR.KPKD=ON;      /* flip and flop some innocuous bits */
                   KPSR.KDIE=OFF;  /* just to kill time to synchronize */
                   KPSR.KRIE=OFF;  /* the command with data arrival at */
                   KPSR.KPKR=ON;      /* the chip’s edge */
                   KPSR.KPKD=ON;
                   KPSR.KRSS=ON;
   446   447   448   449   450   451   452   453   454   455   456