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

144                          8. INTERMEDIATE LEVEL PROJECTS

                          {
                              Segments = LEDS[Digits[3]];         // Send to PORT C
                              Enable3 = Enable;                   // Enable Digit 3
                              wait(0.005);                        // Wait 5ms
                              Enable3 = Disable;                  // Disable Digit 3

                              Segments = LEDS[Digits[2]];         // Send to PORT C
                              Enable2 = Enable;                   // Enable Digit 2
                              wait(0.005);                        // Wait 5ms
                              Enable2 = Disable;                  // Disable Digit 2

                              Segments = LEDS[Digits[1]];         // Send to PORT C
                              Enable1 = Enable;                   // Enable Digit 1
                              wait(0.005);                        // Wait 5ms
                              Enable1 = Disable;                  // Disable Digit 1

                              Segments = LEDS[Digits[0]];         // Send to PORT C
                              Enable0 = Enable;                   // Enable Digit 0
                              wait(0.005);                        // Wait 5ms
                              Enable0 = Disable;                  // Disable Digit 0
                          }
                      }

                 FIG. 8.10,  CONT’D


                   There are several algorithms for extracting the digits of an integer number. In this project,
                 the number to be displayed cannot be greater than four digits long. Assuming that the num-
                 ber CNT is, for example, 2356, the digits are extracted as follows:


                                 Calculations                        Digits Extracted
                                 Digits[3]¼CNT/1000;                 Digits[3]¼2 (MSD)
                                 Y¼CNT 1000*Digits[3];               Y¼356
                                 Digits[2]¼Y/100;                    Digits[2]¼3
                                 W¼Y 100*Digits[2];                  W¼56
                                 Digits[1]¼W/10;                     Digits[1]¼5
                                 Digits[0]¼W% 10;                    Digits[0]¼6 (LSD)



                 8.3.7 Modified Program
                   The program in Fig. 8.10 displays the leading zeroes. For example, number 10 is displayed
                 as 0010. We can remove the leading zeroes by disabling their digit. For example, when
                 displaying “0010,” we can disable the Enable3 and Enable2 digits so that the display shows
                 “10” and not “0010.” The program given in Fig. 8.11 (program: SevenSegMux5) shows how
                 the leading zeros can be disabled.


                 8.3.8 Suggestions for Additional Work
                   Modify the program as shown in Fig. 8.10 to display the letters “HELO.”
   153   154   155   156   157   158   159   160   161   162   163