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

8.3  PROJECT 2—FOUR-DIGIT MULTIPLEXED 7-SEGMENT LED      145
               /*****************************************************************************

                                       4-DIGIT MULTIPLEXED LED
                                       =======================
               In this program two 2-digit 7-Segment LEDs are connected to PORT C of the
               Nucleo-F411RE development board to form a 4-digit 7-Segment display. The
               program displays the number 5 on the display.
               In this modified program the leading zeroes are disabled so that for
               example number 5 is displayed as "   5" and not as "0005"

               Author: Dogan Ibrahim
               Date  : August 2018
               File  : SevenSegMux5
               *****************************************************************************/
               #include "mbed.h"

               PortOut Segments(PortC, 0xFF);
               int LEDS[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
               DigitalOut Enable3(PC_8);
               DigitalOut Enable2(PC_9);
               DigitalOut Enable1(PC_10);
               DigitalOut Enable0(PC_11);
               #define Enable 1
               #define Disable 0
               int main()
               {
                   int W, Y, CNT;                              // Number to be displayed
                   int Digits[4];                              // Array to store digits

                   Enable3 = Disable;                          // Disable Digit 3
                   Enable2 = Disable;                          // Disable Digit 2
                   Enable1 = Disable;                          // Disable Digit 1
                   Enable0 = Disable;                          // Disable Digit 0
               //
               // Extract digits of CNT into Digits[]. Digits[3] holds the MSD digit
               // and Digits[0] holds the LSD digit
               //
                   CNT = 5;                                    // Number to be displayed
                   Digits[3] = CNT / 1000;
                   Y = CNT - 1000*Digits[3];
                   Digits[2] = Y / 100;
                   W = Y - 100*Digits[2];
                   Digits[1] = W /10;
                   Digits[0] = W % 10;

                   while(1)                                    // Do forever

            FIG. 8.11  Modified program.
                                                                                     (Continued)
   154   155   156   157   158   159   160   161   162   163   164