Advanced PIC Microcontroller Projects in C: From USB to RTOS with the PIC18F Series

This project is similar to Project 3, but here LEDs are shared, which uses fewer input/output pins.
The LEDs in Table 6.1 can be grouped as shown in Table 6.3. Looking at this table we can say that:
D4 can appear on its own
D2 and D6 are always together
D1 and D3 are always together
D5 and D7 are always together
| Required number | LEDs to be turned on |
|---|---|
| 1 | D4 |
| 2 | D2 D6 |
| 3 | D2 D6 D4 |
| 4 | D1 D3 D5 D7 |
| 5 | D1 D3 D5 D7 D4 |
| 6 | D2 D6 D1 D3 D5 D7 |
Thus, we can drive D4 on its own and then drive the D2,D6 pair together in series, the D1,D3 pair together in series, and also the D5,D7 pair together in series. (Actually, we could share D1,D3,D5,D7 but this would require 8 volts to drive if the LEDs are connected in series. Connecting them in parallel would call for even more current, and a driver IC would be required.) Altogether, four lines are needed to drive the seven LEDs of each dice. Thus, a pair of dice can easily be driven from an 8-bit output port.
The circuit diagram of the project is shown in Figure 6.16. PORTC of a PIC18F452 microcontroller is used to drive the LEDs as follows:
RC0 drives D2,D6 of the first dice
RC1 drives D1,D3 of the first dice
RC2 drives D5,D7 of...