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

142                          8. INTERMEDIATE LEVEL PROJECTS

                   BEGIN
                           Group PORT C pins as a single variable
                           Define the segment bit patterns
                           Create an array to store the four digits values
                           Configure PC_8,PC_9,PC_10,PC11as outputs
                           CNT = 3579
                           DO FOREVER
                                  Extract all four digits and store in an array
                                  Send bit pattern corresponding to MSD to PORT C
                                  Enable Digit3
                                  Wait for 10ms
                                  Disable MSD Digit
                                  Send bit pattern corresponding to second digitto PORT C
                                  Enable Digit2
                                  Wait for 10ms
                                  Disable Digit2
                                  Send bit pattern corresponding to third digit to PORT C
                                  Enable Digit 1
                                  Wait for 10ms
                                  Disable Digit1
                                  Send bit pattern corresponding to LSD to PORT C
                                  Enable Digit0
                                  Wait for 10ms
                                  Disable Digit0
                           ENDDO
                   END
                 FIG. 8.9  Program PDL.

                 8.3.6 Program Listing

                   The program listing (program: SevenSegMux4) is shown in Fig. 8.10. At the beginning of
                 the program, PORT C lower byte bits are grouped together and assigned to variable called
                 Segments using the PortOut statement. PC_8, PC_9, PC_10, and PC_11 bits are defined as
                 Enable3, Enable2, Enable1,and Enable0 and are configured as digital outputs. At the begin-
                 ning of the main program, variable CNT is set to 3579 and all four digits are disabled. The
                 remainder of the program runs in an endless loop established using a while statement. Inside
                 this loop, the digit values of the number to be displayed (i.e., CNT) are extracted and stored in
                 an array called Digits, where Digits[0] corresponds to Digit 0 value, and Digits[3] corre-
                 sponds to Digit 3 value. The digit values are then sent to PORT C and the corresponding
                 digits are enabled for 5ms as in the previous project. The above process is repeated forever
                 until stopped by the user.
   151   152   153   154   155   156   157   158   159   160   161