18.11.2014 Views

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 8<br />

Listing 8-1. Controls eight LEDs at an output port.<br />

10 A=0E000H: REM address of LEDs<br />

20 L=0FFH: REM initial control value for LEDs<br />

20 XBY(A)=L: REM turn off all LEDs<br />

30 DO<br />

40 INPUT “Select an LED (0-7): ”,B<br />

50 INPUT “Turn on or off (0=off, 1=on)? ”,C<br />

60 IF C=0 THEN L=L.AND.(0FFH-2**B)<br />

70 IF C=1 THEN L=L.OR.2**B<br />

90 XBY(A)=L<br />

80 WHILE 1=1<br />

90 END<br />

outputs of a 74LS374 addressed at E000h. <strong>The</strong> LEDs are connected as in Figure 8-1B , with<br />

logic-low outputs turning on the LEDs. Listing 8-1 tests the circuit by allowing you to turn<br />

individual LEDs on and off.<br />

Bi-color LEDs<br />

Bi-color LEDs have both a red and a green LED inside a single package. By turning on one,<br />

both, or neither, you can use a single indicator to show as many as four states. Some bicolor<br />

LEDs have two leads, while others have three. Figure 8-2 illustrates.<br />

In the 3-lead, or common-cathode type, the cathodes of both LEDs connect internally (A).<br />

To turn on an LED, you ground the cathodes through a current-limiting resistor and apply<br />

power to the anode of the desired LED. When both LEDs are powered, you get an amber<br />

light. Removing power from both turns the LED off, giving a total of four states that the<br />

device can display. Instead of the one current-limiting resistor shown, you can connect a<br />

resistor to each anode, to set the current through each LED individually.<br />

In a 2-lead, or parallel-connected, bicolor LED, the anode of each LED connects internally<br />

to the other’s cathode (B). To turn on the red LED, you apply +5V to terminal A and ground<br />

terminal B. To turn on the green LED, you do the reverse: terminal A is ground, and terminal<br />

B is +5V. With this type, you can’t turn on both LEDs at once.<br />

With either type, by adding an inverter, you can use a single output to control both LEDs<br />

(C, D).<br />

128 <strong>The</strong> <strong>Microcontroller</strong> <strong>Idea</strong> <strong>Book</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!