Page 169 - ARM Based Microcontroller Projects Using MBED
P. 169
8.6 PROJECT 4—FOUR-DIGIT 7-SEGMENT LED EVENT COUNTER 155
if(Digits[3] != 0) // If MSD Digit non zero
{
Segments = LEDS[Digits[3]]; // Send to PORT C
Enable3 = Enable; // Enable Digit 3
}
}
else if(Flag == 2) // If to refresh Digit 2
{
Enable3 = Disable;
Flag = 1;
if(Digits[2] != 0 || (Digits[2] == 0 && Digits[3] != 0))
{
Segments = LEDS[Digits[2]]; // Send to PORT C
Enable2 = Enable; // Enable Digit 2
}
}
else if(Flag == 1) // If to refresh Digit 1
{
Enable2 = Disable;
Flag = 0;
if(Digits[1] != 0 || (Digits[3] != 0 || Digits[2] != 0))
{
Segments = LEDS[Digits[1]]; // Send to PORT C
Enable1 = Enable; // Enable Digit 1
}
}
else if(Flag == 0) // If to refresh Digit 0
{
Enable1 = Disable;
Flag = 3;
Segments = LEDS[Digits[0]]; // Send to PORT C
Enable0 = Enable; // Enable Digit 0
}
}
int main()
{
Enable3 = Disable; // Disable Digit 3
Enable2 = Disable; // Disable Digit 2
Enable1 = Disable; // Disable Digit 1
Enable0 = Disable; // Disable Digit 0
tim.attach(&Refresh, 0.005);
while(1) // Do forever
{
if(button == 0) // If button is pressed
{
CNT++; // Increment CNT
while(button == 0); // Wait until button released
}
}
}
FIG. 8.17, CONT’D