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

8.6  PROJECT 4—FOUR-DIGIT 7-SEGMENT LED EVENT COUNTER     151
               /*****************************************************************************

                                   4-DIGIT MULTIPLEXED LED COUNTER
                                   ===============================
               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 counts up every second starting from 0. Leading zeroes are disabled
               in this program. The display routine runs insid ethe timer interrupt service
               routine called Refresh, which is called automatically every 5ms.


               Author: Dogan Ibrahim
               Date  : August 2018
               File  : SevenSegMux6
               *****************************************************************************/
               #include "mbed.h"
               Ticker tim;
               PortOut Segments(PortC, 0xFF);
               int LEDS[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
               int W, Y, CNT = 0, Flag = 3;
               int Digits[4];
               //
               // Digit Enable bits
               //
               DigitalOut Enable3(PC_8);
               DigitalOut Enable2(PC_9);
               DigitalOut Enable1(PC_10);
               DigitalOut Enable0(PC_11);

               #define Enable 1
               #define Disable 0
               //
               // Thsi is the Interrupt Service Routine (ISR) which is called at every
               // 5ms by Ticker
               //
               void Refresh()
               {
               //
               // Extract digits of CNT into Digits[]. Digits[3] holds the MSD digit
               // and Digits[0] holds the LSD digit
               //
                   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;

                   if(Flag == 3)                               // If to refresh Digit 3
                   {
            FIG. 8.15  Program listing.
                                                                                     (Continued)
   160   161   162   163   164   165   166   167   168   169   170