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

184                          8. INTERMEDIATE LEVEL PROJECTS

                 8.16.4 Program Listing
                   The program listing (program: HiLo) is shown in Fig. 8.47. The program consists of two
                 nested while loops. The outer loop executes indefinitely. The inner loop executes until the
                 secret number has been found (while variable the FLAG is 0). Just after the outer loop a head-
                 ing is displayed and the secret random number is generated between 1 and 100 using the rand
                 () function. Inside the inner loop, the user attempts to guess the secret number and receives
                 the messages You are HIGH, You are LOW,or Success depending on whether or not the
                 guessed number is high, low, or equal to the secret number, respectively. When the user finds
                 the secret number, the number of attempts made to find the number is also displayed after the
                 Success message (Fig. 8.48).




                                  8.17 PROJECT 14—SERIAL INTERRUPT

                 8.17.1 Description

                   The PC serial communications link can be attached to an ISR so that, for example, when a
                 key is pressed on the keyboard it generates an interrupt and the program jumps to the ISR. In
                 this project, the User LED flashes initially every 100ms and the rate of flashing is increased by
                 pressing the + key on the keyboard. Pressing the + key generates an interrupt. Inside the ISR
                 the flashing rate is increased by 100ms to up to 1s. Pressing the + key again resets the flashing
                 rate back to 100ms.



                 8.17.2 Aim
                   The aim of this project is to show how serial interrupts can be programmed.



                 8.17.3 The PDL
                   Fig. 8.49 shows the program PDL. This figure is in two sections: the main program (MAIN)
                 and the ISR.



                 8.17.4 Program Listing
                   The program listing (program: SerISR) is shown in Fig. 8.50. At the beginning of the pro-
                 gram, LED1 is configured as digital output. The main program attaches the serial communi-
                 cation link to a function called ISR and it initially flashes the User LED every 100ms. Inside
                 function ISR, the flashing rate is increased by 100ms every time the + key is pressed. When the
                 flashing rate is greater than 1s, it is reset back to 100ms.
   193   194   195   196   197   198   199   200   201   202   203