Page 157 - ARM Based Microcontroller Projects Using MBED
P. 157
8.3 PROJECT 2—FOUR-DIGIT MULTIPLEXED 7-SEGMENT LED 143
/*************************************************************************
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 3579 on the display.
Author: Dogan Ibrahim
Date : August 2018
File : SevenSegMux4
**************************************************************************/
#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 Y, W, CNT = 3579;
int Digits[4]; // Array to store digits
Enable3 = Disable; // Disable Digit 3
Enable2 = Disable; // Disable Digit 2
Enable1 = Disable; // Disable Digit 3
Enable0 = Disable; // Disable Digit 3
//
// 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;
while(1)
FIG. 8.10 Program listing.
(Continued)