Hardware Prototyping:Program DICE1

Program DICE1

This program will generate a random number at the display between 1 and 6 when the input button in pressed. A continuous loop will increment a register from 1 to 6, and back to 1. The loop is stopped when the button is pressed and the number displayed. The display is retained when the button is released.

First, the allocation of the segments to the pins on the display chip must be established. The segments of the display are labeled from a to g, as shown in Figure 10.15. They must be lit in the appropriate combinations to give each display number; for instance, segments ‘b’ and ‘c’ must be lit for the number ‘1’ to be displayed. A table is useful here to work out the codes required for output to the display (Table 10.2).

The display is active high in operation. This means a 1 at the pin will light that segment. This arrangement is also described as common cathode, as all the LED cathodes are connected together at the common terminal. A common anode display will therefore operate active low. The binary or hexadecimal code for each digit will be included in the program in the form of a program data table.

The program represented in the flowchart (Figure 10.16) uses a spare register as a counter, which is continuously decremented from 6 to 0. When the button is pressed, the current number is used to select from the table of codes using the method described in Program 10.2. This results in the pseudo-random number code being displayed, and remaining visible until the button is pressed again. Because the number is selected by manually stopping a fast loop, the number cannot be predicted. In the flowchart, the jump destinations have been labeled, and these labels will be used in the program source code. The table subroutine is also named ‘table’ to match the source code subroutine start label.

Leave a comment

Your email address will not be published. Required fields are marked *