Page 172 - ARM Based Microcontroller Projects Using MBED
P. 172
158 8. INTERMEDIATE LEVEL PROJECTS
/*****************************************************************************
DICE
====
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 simulates two dice. Each time the User Button is pressed two dice
numbers are displayed between 1 and 6 on the 4-digit multiplexed LED. The
program is ready for the user to press the button when the display shows 0.
Notice that Digit 1 is disabled so that the displayed dice numbers are as
follows: For example if the numbers are 2,4, they are displayed as " 2 4"
and not as " 204"
Author: Dogan Ibrahim
Date : August 2018
File : DICE
*****************************************************************************/
#include "mbed.h"
Ticker tim;
PortOut Segments(PortC, 0xFF);
int LEDS[] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
DigitalIn button(BUTTON1);
int W, Y, Dice = 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] = Dice / 1000;
Y = Dice - 1000*Digits[3];
Digits[2] = Y / 100;
W = Y - 100*Digits[2];
Digits[1] = W /10;
Digits[0] = W % 10;
FIG. 8.19 Program listing.
(Continued)