ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 15.06.2025
Просмотров: 2214
Скачиваний: 1
Displays
Figure 8-1. LED interfaces to output ports. Use an HCMOS output if you want a high output to turn on the LED. Use either HCMOS or LSTTL if you want a low output to turn on the LED.
The Microcontroller Idea Book |
127 |
Chapter 8
Listing |
8-1. Controls eight LEDs at an output port. |
10 |
A=0E000H: REM address of LEDs |
20 |
L=0FFH: REM initial control value for LEDs |
20 |
XBY(A)=L: REM turn off all LEDs |
30 |
DO |
40 |
INPUT “Select an LED (0-7): ”,B |
50 |
INPUT “Turn on or off (0=off, 1=on)? ”,C |
60 |
IF C=0 THEN L=L.AND.(0FFH-2**B) |
70 |
IF C=1 THEN L=L.OR.2**B |
90 |
XBY(A)=L |
80 |
WHILE 1=1 |
90 |
END |
outputs of a 74LS374 addressed at E000h. The LEDs are connected as in Figure 8-1B , with logic-low outputs turning on the LEDs. Listing 8-1 tests the circuit by allowing you to turn individual LEDs on and off.
Bi-color LEDs
Bi-color LEDs have both a red and a green LED inside a single package. By turning on one, both, or neither, you can use a single indicator to show as many as four states. Some bicolor LEDs have two leads, while others have three. Figure 8-2 illustrates.
In the 3-lead, or common-cathode type, the cathodes of both LEDs connect internally (A). To turn on an LED, you ground the cathodes through a current-limiting resistor and apply power to the anode of the desired LED. When both LEDs are powered, you get an amber light. Removing power from both turns the LED off, giving a total of four states that the device can display. Instead of the one current-limiting resistor shown, you can connect a resistor to each anode, to set the current through each LED individually.
In a 2-lead, or parallel-connected, bicolor LED, the anode of each LED connects internally to the other’s cathode (B). To turn on the red LED, you apply +5V to terminal A and ground terminal B. To turn on the green LED, you do the reverse: terminal A is ground, and terminal B is +5V. With this type, you can’t turn on both LEDs at once.
With either type, by adding an inverter, you can use a single output to control both LEDs (C, D).
128 |
The Microcontroller Idea Book |
Displays
Figure 8-2. Ways to connect bicolor LEDs .
7-segment Displays
If you want to display numbers, 7-segment displays will do the job. Each digit on the display contains seven segments. Numerals are displayed by turning on different combinations of segments, as Figure 8-3 shows. Decoder chips make it easy to operate one or more displays with a minimum of programming and added components. Seven-segment displays are available as LEDs, where each segment is a light-emitting diode, and as LCDs, where each segment is a liquid-crystal display. We’ll look at the LED type first.
7-segment LEDs
A 7-segment LED contains seven individual LEDs arranged in the pattern shown in Figure 8-3. Sometimes there is also a decimal point (or two, one on each side). There are also special leading-digit modules that display only a 1 and a plus-or-minus symbol.
The Microcontroller Idea Book |
129 |
Chapter 8
Figure 8-3. A 7-segment display can show numbers from 0 to 9, plus hex digits A-F. In a common-cathode LED display, all of the cathodes connect together, while in a common-anode display, all of the anodes connect.
The displays come in two types: common-anode or common-cathode. In a common-anode display, the anodes of each segment connect internally. To use the display, you connect the anodes to a voltage source and turn on individual segments by grounding them through a current-limiting resistor. A common-cathode display is the opposite: the cathodes connect internally, so you ground the cathodes and apply voltages through current-limiting resistors at the segments you want to light.
Deciphering pinouts
Unfortunately, there isn’t much standardization for pinouts of 7-segment displays. If you don’t know the pinout for a display, you can find it by experimenting. You’ll need a 330-ohm resistor and a 5-volt supply.
Sometimes you’ll find CC or CA stamped on the package to indicate common cathode or common anode. If even this information is lacking, begin by connecting one lead of the
130 |
The Microcontroller Idea Book |
Displays
Figure 8-4. Four output port pins can control a 7-segment LED.
resistor to ground on your power supply. Clip the resistor’s other end to one of the LED’s pins. Use a test lead to touch the power supply’s +5V output to each of the other pins in turn.
If only one or two connections cause a segment to light, you have a common-anode display, and the common anode is the pin or pins that connect to +5V when the segment lights. (There
The Microcontroller Idea Book |
131 |
Chapter 8
Listing 8-2. Causes a 7-segment LED to display each digit in sequence.
10 |
REM configure all ports as outputs |
20 |
XBY(0FC03H)=80H |
30 |
REM write each value to the display in sequence |
40 |
FOR I=0 TO 9 |
50 |
XBY (0FC00H)=I |
60 |
REM delay after each write |
70 |
FOR J=1 TO 500:NEXT J |
80 |
NEXT I |
90 |
END |
may be two common-anode pins.) To find the pin that controls each segment, leave the +5V lead on a common-anode pin, and connect the resistor to each pin in turn, noting the results.
For a common-cathode display, to find the common-cathode pin or pins, connect a pin to +5V, and touch the others to ground through the 330-ohm resistor. The pin or pins that cause the segment to light are the common-cathode connections. To find the pin that controls each segment, move the +5V lead to each pin in turn, and note the results.
Interfacing
For 7-segment decoder/drivers, you can choose from single-digit and multi-digit chips.
Single-digit driver. Figure 8-4 shows a 7-segment display controlled by a 4511B latch/decoder/driver. The display shows the value of the 4-bit number at the 4511’s data inputs A-D. The 4511 will drive common-cathode displays directly. Common-anode displays require inverters at the segment outputs. You can use any output port bits to control the display. An 8-bit port will control a 2-digit display.
Listing 8-2 tests Figure 8-4’s circuits by displaying each digit in sequence. The program assumes that a display connects to bits 0-3 of Port A on an 8255 addressed at FC00h. If your system has different addressing, change the program to match.
Multi-digit driver. If you want to display more than a couple of digits, there are specialized chips that will drive and control multiple-digit displays. One example from Intersil (now part of Harris Semiconductor) is the ICM7218D multiplexed display driver, which can control up to 8 common-cathode digits. Figure 8-5 illustrates. For common-anode displays, use the ICM7218C.
The segments of all eight displays connect to the 7218D’s segment-driver outputs (a-g, dp). Each display’s common cathode connects to one of eight DIGIT outputs. An internal oscillator
132 |
The Microcontroller Idea Book |
Displays
Figure 8-5. The ICM7218D can control up to eight 7-segment LEDs.
turns on each of the digits in sequence. This means that each of the displays is on just 1/8 of the time.
The 7218D drives each segment at 20 milliamperes peak current, for an average current of just 2.5 milliamperes. The chip takes advantage of the fact that LEDs can withstand relatively high pulsed currents, and that a pulsed LED actually appears brighter than a constantlydriven LED with the same average current. Twenty milliamperes is well within the allowed
The Microcontroller Idea Book |
133 |
Chapter 8
Listing 8-3. Controls eight 7-segment LEDs with ICM7218 driver.
10 |
REM address of 8255 Port A |
20 |
A=0FC00H |
30 |
REM address of 8255 control word |
40 |
X=A+3 |
50 |
REM set 8255 for all outputs |
60 |
XBY(X)=80H |
70 |
REM set WR |
80 |
XBY(X)=9 |
90 |
REM write to each digit |
100 |
FOR M=0 TO 7 |
110 |
REM step through all numbers at each digit |
120 |
FOR I=0 TO 8 |
130 |
REM add 10h to turn off decimal point |
140 |
D=I+10H+M*20H |
150 |
GOSUB 500 |
160 |
REM delay to display each digit |
170 |
K=500 |
180 |
FOR J=1 TO K : NEXT J |
190 |
NEXT I |
200 |
NEXT M |
210 |
END |
490 |
REM write data to port A and toggle W (PC.4) |
500 |
XBY(A)=D |
510 |
XBY(X)=8H |
520 |
XBY(X)=9 |
530 |
RETURN |
range for peak current for most LEDs, and the 2.5-milliampere average current causes the displays to appear brighter than you might expect. With all digits displaying 8’s, this circuit draws 140 milliamperes, so be sure your power supply can handle it.
To write a value to the display, you select the digit with data-address inputs DA0-DA2, write the data to inputs ID0-ID7, and strobe WRITE low. The WRITE pulse must be at least 400 nanoseconds wide, and ID0-ID7 must remain valid for at least 125 nanoseconds after WRITE goes high. BASIC-52 is slow enough to meet these requirements, using XBY statements to write to the port that controls the 7218C.
Pin 9 allows you to select one of three modes, which determine what digits the displays show. In Code B mode, you can display the message HELP.
134 |
The Microcontroller Idea Book |
Displays
In Figure 8-5’s circuit, an 82(C)55 controls the 7218C. For complete control, the circuit requires 10 outputs. Bits 0-4 of Port A determine the data to be written, including a decimal point controlled by ID7. If you don’t need the decimal point, tie pin 7 of the 7218C low. Bits 5-7 of Port A select the digit to write to. If you have four or fewer displays, you can tie one or more of these lines low and free up another port bit.
Port C, bit 4 controls WRITE. The display-mode input is tied high to select hexadecimal mode. If you instead tie pin 9 to a port bit, you can turn off the display by bringing the bit low. To allow selecting different modes, connect an additional output bit to the 7218D’s MODE input.
Listing 8-3 uses the 7218D to display data, using Figure 8-5’s circuit.
7-segment LCDs
An alternative to LEDs is liquid-crystal displays (LCDs). Unlike LEDs, which consume several milliamperes per segment, LCDs are voltage-controlled and require very little operating current.
Compared to LEDs, LCDs are easy to read in bright light. However, because LCDs don’t emit light as LEDs do, but merely absorb or transmit it, you need additional lighting to see them in the dark. LCDs also tend to have narrower viewing angles than LEDs. So, whether to use LEDs or LCDs may depend on where and how you will use the display.
Most 7-segment LCD modules contain two or more digits. Like the LEDs, a 7-segment LCD creates a numeral by turning on selected segments.
Each LCD segment contains a thin layer of liquid crystal between two layers of glass. Liquid crystals are organic compounds that act as electrically controlled light polarizers. In a positive-image display (the most common type), applying a voltage across a segment causes the segment to appear dark, or opaque, while removing the voltage causes the segment to appear light-colored, or transparent. Negative-image displays are opaque when not powered, and transparent when powered. By applying and removing voltages across individual segments, you can display numeric, alphabetic, and other characters.
Applying a constant voltage to an LCD segment will eventually destroy it. Instead, you must drive the segment with an alternating voltage, typically a square wave that alternately applies +5 and -5V across the segment.
Single-digit driver. Figure 8-6 shows an LCD module driven by a 4543B LCD latch/decoder/driver. The 4543 is a lot like the 4511 LED driver, with the addition of a phase input that accepts a square wave for driving the segments. A typical drive frequency is around 100 Hertz. A 555 timer provides the phase input, or you can use any oscillator output.
The Microcontroller Idea Book |
135 |
Chapter 8
Figure 8-6. A 4543B driver can control a 7-segment LCD. A 555 timer controls the drive voltage.
As in Figure 8-4, you control the display by writing to inputs A-D. If the display contains other types of segments, such as ± or a leading 1, you can control these as well. For example, for a leading 1, connect digit 1’s two segments to pins 10 and 11 on the 4543. When you write 1 to the data inputs, the appropriate segments will light.
Multi-digit driver. As with the LEDs, there are driver chips for multi-digit LCD modules. Figure 8-7 shows Telcom Semiconductor’s (formerly Teldyne) TC7211A, which will drive four 7-segment LCDs, and includes an on-chip oscillator and backplane driver.
To display a number using Figure 8-7’s circuit, follow these steps:
136 |
The Microcontroller Idea Book |