Page 161 - ARM Based Microcontroller Projects Using MBED
P. 161

8.4  POLLING AND INTERRUPTS                     147






















            FIG. 8.12  Program using polling.

            operations and at the same time, it is required to respond when an external button is pressed.
            It is clear from this figure that the CPU is not very responsive to the button event and it can
            only check the state of the button when it completes executing the other code.
              Polling has the disadvantage that the CPU cannot respond to external events quickly dur-
            ing a polling routine. Also, if there is an error in the other code and the code happens to stay in
            an indefinite loop, then the CPU will never respond to the external events.



            8.4.2 Interrupts
              Interrupts are very important parts of all microcontrollers as they allow the microcontroller
            to respond to external events very quickly. As shown in Fig. 8.13, when an interrupt occurs
            due to an external or an internal event (e.g., the timer), the CPU stops executing the current
            instruction and jumps to execute the code named the interrupt service routine (ISR). After























            FIG. 8.13  The interrupt process.
   156   157   158   159   160   161   162   163   164   165   166