Page 171 - ARM Based Microcontroller Projects Using MBED
P. 171

8.7  PROJECT 5—7-SEGMENT LED DICE                 157
                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
                       Dice = 0
                       Flag = 3
                       DO FOREVER
                              Generate a random number 1 to 6 in Temp1
                              Generate a second random number 1 to 6 in Temp2
                              Dice = Temp1 * 100 + Temp2
                              Wait 5 seconds
                              Dice = 0
                       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
                              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.18  Program PDL.
   166   167   168   169   170   171   172   173   174   175   176