Page 140 - ARM Based Microcontroller Projects Using MBED
P. 140
126 7. USING THE Mbed WITH SIMPLE PROJECTS
/***********************************************************************
7-SEGMENT COUNTER
=================
In thsi project a 7-Segment LED is conencted to lower byte of PORT C
ofthe Nucleo-F411RE development board. The program counts from 0 to 9
every second
Author: Dogan Ibrahim
Date : August 2018
File : SevenSeg
***********************************************************************/
#include "mbed.h"
PortOut Segments(PortC, 0xFF);
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.72 Program listing.
For example, to display number 0 we have to send the hexadecimal number 0x3F to the LED.
Similarly, todisplaynumber1we have tosend the hexadecimalnumber0x06 tothe LED and so
on. Inside the program loop array LEDS is indexed by variable CNT and the resulting segment
pattern is sent to PORT C. Variable CNT is then incremented by 1 and the program waits for 1s.
WhenCNTreachesto10itisresetbackto0.Theaboveprocessrepeatsforever displayingnum-
bers 0–9 on the 7-segment LED.
7.16.8 Modified Program
The program given in Fig. 7.72 can be written differently using the BusOut statement. This
modified program (program: SevenSeg-2) is shown in Fig. 7.73. Used PORT C pin names are
defined in statement BusOut. The remainder of the program is same as in Fig. 7.72.