Introduction
Many embedded applications contain user interfaces assembled from multi-segment LED displays.
In this chapter, we consider how such displays may be interfaced to the 8051 family of microcontrollers.
Mx led display
Context
● You are developing an embedded application using one or more members of the 8051 family of microcontrollers.
● The application has a time-triggered architecture, constructed using a scheduler.
● You are creating the user-interface for your application.
Problem
How do you display information on one or more multi-segment LED displays?
Background
We consider some essential background material in this section.
What is a multi-segment LED?
Multiple LEDs are often arranged as multi-segment displays: combinations of eight segments (see Figure 21.1) and similar seven-segment displays (without a decimal point) are particularly common.
Such displays are arranged either as ‘common cathode’ or ‘common anode’ pack- ages: the connection of the LEDs within each package is illustrated in Figure 21.2.
In either case, in addition to the common pin, we must provide appropriate signals to each of the LEDs in order to generate the digits we require (see ‘Solution’).
The required current per segment varies from about 2 mA (very small displays) to about 60 mA (very large displays, 100mm or more).
Basic hardware requirements (driving a single digit)
For reasons that we discussed in IC BUFFER [page 118], we cannot generally connect a multi-segment LED directly to a microcontroller port as illustrated in Figure 21.3. As you will recall, this is because the port cannot safely handle the required current (typically around 80 mA per digit).
In most cases, we require some form of buffer or driver IC between the port and the MS LED.
For small displays (around 9 mA per segment), the simple 240 and 241 buffers (see IC BUFFER [page 118]) are a cost-effective solution. Figure 21.4 shows a 74×241 (non- inverting buffer) used to drive a single, eight-segment LED display. Note that a 74×240 (inverting) buffer can be used as an alternative.
In most circumstances (such as the multiplexed displays we will focus on here), the basic 240 / 241 buffers have insufficient current capacity and an IC driver chip will generally be used. For example, Figure 21.5 shows a single common cathode LED digit connected to a single port via another octal buffer: the UDN2585A. As we discussed
in IC DRIVER [page 134], each of the (eight) channels in this device can simultane- ously source up to 120 mA of current (at up to 25V): this is enough, for example, for even the largest of LED displays.
Here, the output of the 2585 in response to a Logic 0 input will be approximately Vcc. As a result, the resistor values are again calculated as shown in Figure 21.4.
Hardware for multiple digits
As discussed in ‘Background’, driving a single multi-segment display is straightfor- ward. Suppose, however, that we need to drive four digits, perhaps for a simple digital clock. To do so using the approach discussed in ‘Background’ would require four spare ports. In many applications, you will not have four ports available. In addition, to use four ports often requires a separate driver (buffer) circuit and resistor pack for each digit: this can significantly increase the system cost.
The most common solution, discussed here, is to multiplex the displays. This means that (in this example) we drive each display for only a quarter of the time: as long as we cycle around all of the displays at between 20 and 50 Hz, the user will not generally notice that the displays are not being simultaneously driven. Even with a simple imple- mentation, this basic approach allows us to drive up to eight LEDs (each with decimal points) using only two ports. More commonly, this allows us to drive four LED digits using 12 port pins. As in many 8051 applications (even those using external memory) Port 1 and most of Port 3 are available, this approach can be used in many applications.
A simple circuit suitable for creating a cost-effective multiplexed display is shown in Figure 21.6. Here, the information required to drive each digit is supplied on Port X, while the selection of the digits is controlled by Port Y.
Note that Port Y must control (sink) the current coming from eight individual LEDs: this may be up to around 140 mA, even for a collection of small displays and
can approach 500 mA for large (100 mm) displays. As a result, we cannot directly drive the displays from a port, but must use, for example, a ULN 2003 or 2803 as a (sink) buffer. Note that you can replace the 2003 / 2803 (or equivalent) with four NPN transistors (e.g. 2N2222), but this is seldom cost-effective.
You will also need a buffer on Port X to source sufficient current: the UDN 2585A is, again, a good choice here. Use of such a source buffer is often essential, since – to achieve a bright display – we usually supply up to four times the normal display cur- rent, for a quarter of the time (thus keeping the average current at the required value). Your microcontroller will have a greatly reduced life if you try to provide this current from the naked chip.
Again, the values of R in Figure 21.6 are calculated as shown in Figure 21.4. In this case, it can be helpful to use a ‘resistor pack’ to implement the circuit: such packs contain seven or eight resistors, in a standard (dual in line: DIL or similar) package.
Solution
We consider here both the software codes required to display digits on the display and the refresh rates needed for flicker-free operation.
Basic software
The software to control the LED digits in arrangements like those shown in Figures21.4 and 21.5 is easy to write. If, for example, we connect the display to Port 3, we can control it by simply writing:
Controlling more than one digit per port (Software issues)
We need to update all the displays at a rate of approximately 50 Hz, if we can: if nec- essary, rates as low as 20 Hz will do. If we have N LED modules, each will be active for approximately 1/N of the time. Note that, if you choose to drive the displays at high current values, the timing needs to be reasonably accurate, otherwise you may reduce the life of the display and driver components by exposing them to excessively high currents for sustained periods.
Overall, for a typical four-module display, we aim to update one module at least every 5 milliseconds. This is easy to achieve using a suitable scheduler, as we demon- strate in the examples that follow.