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

18                 2. MICROCONTROLLER-BASED PROJECT DEVELOPMENT CYCLE

                          ELSE IF HEX_NUM ¼ “E” THEN
                               DEC_NUM ¼ 14
                          ELSE IF HEX_NUM ¼ “F” THEN
                                 DEC_NUM ¼ 15
                          ENDIF
                      END


                   The required flow chart is shown in Fig. 2.14. Notice that it is much easier to write the PDL
                 statements than drawing the flow chart shapes and writing text inside them.


                   EXAMPLE 2.2
                   It is required to write a program to calculate the sum of integer numbers between 1 and 100. Show
                   the required algorithm using a PDL and also draw the equivalent flow chart. Assume that the sum
                   will be stored in variable called SUM.
                   Solution 2.2
                   The required PDL is:
                      BEGIN
                          SUM ¼ 0
                          I ¼ 1
                          DO 100 TIMES
                                SUM ¼ SUM + I
                                Increment I
                          ENDDO
                      END


                   The required flow chart is shown in Fig. 2.15.

                   EXAMPLE 2.3
                   An LED is connected to a microcontroller output port. Additionally a button is connected to one of
                   the input ports. It is required to turn ON the LED when the button is pressed, and otherwise to turn
                   OFF the LED. Show the required algorithm using a PDL and also draw the equivalent flow chart.
                   Solution 2.3
                   The required PDL is:
                      BEGIN
                          DO FOREVER
                                IF Button is pressed THEN
                                     Turn ON LED
                                ELSE
                                     Turn OFF LED
                                ENDIF
                          ENDDO
                      END
   27   28   29   30   31   32   33   34   35   36   37