I like the look of seven-segment LED displays and came up with a couple of fun applications for them: a scrolling display of the digits of pi (3.14159…) and my own desktop version of the National Debt clock. The five-digit Freescale MC14489 can be daisy-chained to support displays of more than just five digits, so I settled on stringing three of them together for a 15-digit display. This is long enough to give a pleasing appearance when scrolling, and to display all the digits of the national debt (at least for now). This is a versatile system which can be adapted to plenty of other uses, too.
My original plan for the scrolling pi display was to use a PIC microcontroller to actually calculate the digits prior to displaying them. There are some fairly sophisticated formulae called “spigot algorithms” (see sidebar) available which can calculate each successive decimal digit without having to calculate the previous digits. It looked like they could be converted into PIC code. I found that my math skills weren’t sufficient to get these algorithms to work (even in a spreadsheet), though, so I never got to try to write the PIC code. Instead, I settled for downloading the first 1,100 or so decimal digits of pi and storing them in the PIC which displays them in a loop. The pi data is stored in the PIC’s Flash memory during device programming with the POKECODE instruction (take a look at the source code file at the end of the article in the downloads). Be careful not to overwrite the program code!
The math for the National Debt clock is very straightforward — all we need to do is look up the current amount of debt and the rate of increase, enter them into the PIC, and then keep a running total with time. This information is available at www.brillig.com/debt_clock, among other places. Take a look at the PICBASIC PRO code (listing available in the downloads) and the embedded comments to see how a 15-byte array variable is used to hold either the pi digits or the national debt value. Addition of the numbers for the national debt is done on a byte-by-byte basis within the array variable, carrying from one byte to the next as necessary.
The MC14489 display drivers use a synchronous serial interface requiring three wires: data, clock, and enable. I selected a straightforward three-button user interface (up, down, and enter) to set the values for the National Debt clock. Since the display and the user interface are the only external interfaces for the PIC, a low pin count device is all that is needed.
I did want to store as many pre-calculated digits of pi in the PIC as possible, so I looked for a device with a fair amount of memory. The closest device I had on hand was a 16F819: an 18-pin device with 2K words of Flash. Other 18-pin devices with more memory (such as the 16F87 or 16F88) could also be used. The schematic is shown in Figure 1.
FIGURE 1. Schematic for the display.
I have omitted the LED displays for digits 1-5 and 6-10 for clarity, since they wire up the same as for digits 11-15. The user interface and MC14489 interface are on port B. This takes advantage of the available weak pull-ups on this port for the input buttons; it also reduces the parts count. The 16F819 has the option of using an internal oscillator and internal MCLR pull-up resistor which can free-up additional pins on port A. In this design, I have MCLR pulled up externally so the PIC can be easily reset. I am using the PIC’s internal oscillator to free-up I/O pins RA6 and RA7 for future use, and I set the oscillator frequency to 4 MHz by configuring the OSCCON register in the code. Several other I/O pins on port A and port B are available to add other functions, sensors, etc., to the circuit, or to interface the display module to external systems.
When you program your PIC, you will need to select the “INTIO2” oscillator configuration option to enable the internal oscillator. Note that not all programmer software uses Microchip’s standard name for this option; my software calls it “IntRC.”
The MC14489 makes it very easy to interface a microcontroller with common-cathode LED displays, but there is still a lot of wiring needed to multiplex those displays and connect them to the drivers (Figure 2).
FIGURE 2. Front and back of the prototype display; note the rat's nest of point-to-point wiring.
This is clearly a project that needs a custom printed circuit board (PCB) to be practical. I like ExpressPCB’s mini-board service because it’s very reasonably priced, but the fixed board size (3.8” by 2.5”) seemed too small to hold 15 LED displays plus the PIC and driver chips. After scouring parts suppliers to find small displays and dusting off my trigonometry skills to align them diagonally across the board, I came up with the board layout in Figure 3.
FIGURE 3. Layout of the PCB with a diagonal arrangement of the LED displays.
ExpressPCB doesn’t allow components to be placed at odd angles like this, so I had to create a custom pad array from scratch to fool the software into aligning the displays at the proper angle of about 31°. The displays I selected are made by Rohm; they come in several colors, and each LED display is only 7 mm wide with a character height of 8 mm or 0.31 inches. It’s a tight fit with a lot of curving traces around the displays but it works, and the diagonal line of displays complements the look.
I recommend using sockets for the four ICs to reduce the risk of damaging them during soldering. However, if you plan to mount the board behind a panel or in an enclosure, note that the height of the chips in their sockets exceeds the height of the displays themselves. The bypass capacitors can also be mounted horizontally to keep them below the plane of the displays. I have included extra pads on the unused I/O pins on the PIC so you can “roll your own” ICSP interface if you choose to solder the chips to the board (though you will have to add a diode between the MCLR pin and its pull-up resistor to protect the rest of the circuit from the programming voltage).
The display defaults to scrolling the digits of pi on power-up (Figure 4).
FIGURE 4. Displaying the first 15 digits of pi.
After scrolling all the digits, the display will pause and then restart from the beginning. If you press and hold the mode/enter button while powering up or resetting the PIC, the display enters National Debt clock mode.
First, you will enter the current value of the debt, starting with the most significant digit and using leading zeros as necessary. Select each digit with the up and down buttons, then press enter to adjust the next digit. Then, enter the rate of increase of the debt — in dollars per second — in the same manner.
Now, you can watch our debt pile up in near real time, or have a more relaxed experience watching pi scroll by. NV
|PIC 16F819 microcontroller, 18-DIP||PIC16F819-I/P-ND|
|(3) MC14489 five-digit LED display driver, 20-DIP||MC14489BPE-ND|
|(15) Seven-segment common-cathode LED display||Rohm LA-301xL series ("x" denotes color)|
|(4) Pushbutton momentary switch||450-1665-ND|
|(4) 4.7K ohm 1/4 watt resistor||4.7KQBK-ND|
|(2) 4.7 µF tantalum capacitor||399-3559-ND|
|(For programmed PICs and circuit boards, check for details at the end of this article.)|
Pi Scrolling Display
PCB and source code files.