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

156                          8. INTERMEDIATE LEVEL PROJECTS

                                   8.7 PROJECT 5—7-SEGMENT LED DICE

                 8.7.1 Description
                   This is a dice project. When the User button is pressed, two dice numbers (between 1 and 6)
                 are displayed on the four-digit 7-segment LED. Normally, a 0 is displayed which means that
                 the project is ready and the user can press the button. The two generated numbers are
                 displayed such that digit 3 and digit 1 are disabled. For example, the numbers 2 and 4 are
                 displayed as “x 2x4,” where x is a blank. The numbers are displayed for 5s. After this time,
                 a 0 is displayed to indicate that the system is ready and the user can press the button again to
                 generate a set of new dice numbers.


                 8.7.2 Aim

                   The aim of this project is to show how an electronic dice can be designed using the Nucleo-
                 F411RE development board and a four-digit 7-segment display.


                 8.7.3 Block Diagram

                   The block diagram of the project is as in Fig. 8.16.


                 8.7.4 Circuit Diagram
                   The circuit diagram of the project is as in Fig. 8.8. Additionally, the onboard User button is
                 used to create external events.

                 8.7.5 The PDL

                   The PDL of the program is shown in Fig. 8.18.


                 8.7.6 Program Listing
                   Fig. 8.19 shows the program listing (program: DICE). The program listing is very similar to
                 the one given in Fig. 8.15. In this program, the User button is configured as digital input. tim is
                 defined of type Ticker, lower byte of PORT C is grouped together into a variable called Seg-
                 ments. Array Digits is declared at the beginning of the program so that it is a global integer
                 array. All the digits are disabled, and function called Refresh has been attached to the Ticker
                 with a period of 5ms so that the function is called periodically at every 5ms. The main pro-
                 gram runs in a loop. Initially, variable Dice is set to 0 so that 0 is displayed to indicate that the
                 system is ready for the user to press the User button to generate the dice numbers. The gen-
                 erated numbers are stored in variables Temp1 and Temp2. Variable Dice is then set to:
                 Dice5Temp1 * 100+Temp2 so that the two dice numbers are displayed at digit positions
                 2 and 0. The numbers are displayed for 5s, and after this time variable Dice is set to 0 to in-
                 dicate that the system is ready again.
   165   166   167   168   169   170   171   172   173   174   175