Page 163 - ARM Based Microcontroller Projects Using MBED
P. 163
8.5 PROJECT 3—FOUR-DIGIT 7-SEGMENT LED COUNTER 149
BEGIN/MAIN
Group PORT C pins as a single variable
Define the segment bit patterns
Create an array to store the four digits values
Configure PC_8,PC_9,PC_10,PC11 as outputs
Create a Ticker variable and attach to function Refresh
CNT = 0
Flag = 3
DO FOREVER
Increment CNT
Wait 1 second
ENDDO
END/MAIN
BEGIN/Refresh
DO FOREVER
Extract all four digits and store in an array
IF Flag = 3 THEN
Flag = 2
Disable Digit 0
Send bit pattern corresponding to Digit 3 to PORT C
Enable Digit 3
ELSE IF Flag = 2 THEN
Flag = 1
Disable Digit 3
Send bit pattern corresponding to Digit 2 to PORT C
Enable Digit 2
ELSE IF Flag = 1 THEN
Flag = 0
Disable Digit 2
Send bit pattern corresponding to Digit 1 to PORT C
Enable Digit 1
ENDIF
IF Flag = 0 THEN
Flag = 3
Disable Digit 1
Send bit pattern corresponding to Digit 0 to PORT C
Enable Digit 0
ENDDO
END/Refresh
FIG. 8.14 Program PDL.