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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 6<br />

Output Examples<br />

Figure 6-4 shows some basic outputs that you can connect to U14:<br />

(A) Outputs can directly drive any TTL or HCTMOS logic input powered at 5 volts.<br />

(B) To interface to 5-volt HCMOS or 4000-series CMOS devices, add a pull-up resistor to<br />

ensure that high outputs are greater than 3.5 volts.<br />

(C) To translate an output to a lower voltage, use a 74HC4050 buffer or 74HC4049 inverter<br />

powered at the lower voltage.<br />

(D) To translate an output to a higher voltage, use a 74LS26 NAND or similar high-voltage,<br />

open-collector gate, with a pullup resistor to the higher voltage.<br />

(E) For high-current outputs, you can use Texas Instruments’ 7545X series of peripheral<br />

drivers. <strong>The</strong> 75452 NAND gate can sink up to 300 milliamperes at 0.5V.<br />

(F) U14 can directly drive an LED. Since the 74LS374 can sink more current than it can<br />

source, connect the LED so that it turns on when the output is low. With a 220-ohm<br />

current-limiting resistor, the LED’s forward current is around 13 milliamperes.<br />

(G) As with inputs, an optocoupler is another way to interface different voltages, and to<br />

electrically isolate an output from the microcontroller circuit.<br />

Reading and Controlling Individual Bits<br />

Unlike assembly language for the 8052, BASIC-52 has no logical operators for setting and<br />

clearing individual bits in a byte. But you can use the .AND. and .OR. operators to<br />

accomplish the same thing.<br />

Listing 6-1. Displays the value of each bit at input port E000h.<br />

10 A=XBY(0E000H)<br />

20 PRINT “Bit 0 = ”,(A.AND.1)<br />

30 PRINT “Bit 1 = ”,(A.AND.2)/2<br />

40 PRINT “Bit 2 = ”,(A.AND.4)/4<br />

50 PRINT “Bit 3 = ”,(A.AND.8)/8<br />

60 PRINT “Bit 4 = ”,(A.AND.10H)/10H<br />

70 PRINT “Bit 5 = ”,(A.AND.20H)/20H<br />

80 PRINT “Bit 6 = ”,(A.AND.40H)/40H<br />

90 PRINT “Bit 7 = ”,(A.AND.80H)/80H<br />

100 END<br />

96 <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!