Page 141 - ARM Based Microcontroller Projects Using MBED
P. 141
7.16 PROJECT 13—7-SEGMENT LED DISPLAY 127
/**********************************************************************
7-SEGMENT LED COUNTER
=====================
In this modified versiuon of the program the BusOut statement is used
Author: Dogan Ibrahim
Date : August 2018
File : SevenSeg-2
***********************************************************************/
#include "mbed.h"
BusOut Segments(PC_0,PC_1,PC_2,PC_3,PC_4,PC_5,PC_6);
int LEDS[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
int main()
{
int CNT = 0; // Initialize CNT
while(1) // DO forever
{
Segments = LEDS[CNT]; // Send CNT to LED
wait(1.0); // Wait 1 second
CNT++; // Increment CNT
if(CNT == 10)CNT = 0; // Reset CNT to 0
}
}
FIG. 7.73 Modified program.
7.16.9 Another Modified Program
The program given in Fig. 7.72 can be modified using a function as shown in Fig. 7.74.In
the modified program (program: SevenSeg-3) function Display receives the number to be
displayed as its argument and then sends this number to the LED to display it.
7.16.10 Using Switch Statement
The program given in Fig. 7.74 can be modified using a switch statement. The modified
program (program: SevenSeg-4) is shown in Fig. 7.75. Here, a switch statement is used inside
function Display to display the required number on the 7-segment LED.