Arrange LEDs as seven-segment displays
The circuit in Figure 1 modifies the circuit in a previous Design Idea (Reference 6). It adds the 21st LED, but it modifies the assembler code to use just 98 words without the main routine (Listing 1). It can also suit any of a Microchip baseline or midrange PIC microcontroller’s eight pins.
- Build a look-up table of 10 values for seven-segment coding (see table “Code7Segment” in Listing 1).
- Build a look-up table of 3×7 values to store the successive configurations for I/O lines, each configuration containing only one high output and one low output to drive one LED at a time, for each digit (see table “Cfg2LinesOut” in Listing 1).
- Build a look-up table of 3×7 values to store the successive high and low state for the I/O lines that are acting as outputs to light only one LED at a time for each digit (see table “Light1LED” in Listing 1).
- The subroutine DispDigit rotates to the right seven times, through Carry flag, and the seven-segment code of a digit. It then calls the subroutine LEDon each time you set Carry.
- The subroutine LEDon activates the LED related to the I/O configuration code, which you can extract from table “Cfg2LinesOut,” and lights it according to the high or low state code, which you extract from table “Light1LED.” The subroutine ends by a jump to a critical 1- to 3-msec delay subroutine. Increasing this delay increases the flicker effect, and decreasing this delay dims the LED.
- Cycle digits of units, tens, and hundreds through steps 4 and 5.
For the PIC10F2xx series, which contains only three I/O lines, Figure 2 shows an example of driving one digit, and Listing 2 shows the corresponding assembler code.