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

138                          8. INTERMEDIATE LEVEL PROJECTS

                       /***********************************************************************

                                           2-DIGIT MULTIPLEXED LED
                                           =======================
                       In this program a 2-digit 7-Segment LED is connected to PORT C of the
                       Nucleo-F411RE development board. The program displays the number 25 on
                       the display.
                       Author: Dogan Ibrahim
                       Date  : August 2018
                       File  : SevenSegMux2
                       ************************************************************************/
                       #include "mbed.h"
                       PortOut Segments(PortC, 0xFF);
                       int LEDS[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};

                       DigitalOut MSDEnable(PC_8);
                       DigitalOut LSDEnable(PC_9);
                       #define Enable 1
                       #define Disable 0
                       int main()
                       {
                           int MSDValue, LSDValue, CNT;
                           CNT = 25;                               // Number to be displayed
                           MSDEnable = Disable;                    // Disable MSD digit
                           LSDEnable = Disable;                    // Disable LSD digit

                           while(1)                                // Do forever
                           {
                               MSDValue = CNT / 10;                // MSD of the number
                               LSDValue = CNT % 10;                // LSD of the number
                               Segments = LEDS[MSDValue];          // Send to PORT C
                               MSDEnable = Enable;                 // Enable MSD digit
                               wait(0.01);                         // Wait 10ms

                               MSDEnable = Disable;                // Disable MSD digit
                               Segments = LEDS[LSDValue];          // Send to PORT C
                               LSDEnable = Enable;                 // Enable LSD digit
                               wait(0.01);                         // Wait 10ms
                               LSDEnable = Disable;                // Disable LSD digit
                           }
                       }

                 FIG. 8.5  Program listing.

                 8.2.6 Program Listing

                   The program listing (program: SevenSegMux2) is shown in Fig. 8.5. 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 and PC_9 bits are defined as MSDEnable
                 and LSDEnable and are configured as digital outputs. At the beginning of the main program,
   147   148   149   150   151   152   153   154   155   156   157