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 12<br />

Listing 12-1. Causes an encoder to transmit requested data.<br />

10 REM 8255 mode set: Ports A,C = output, Port B = input<br />

20 XBY(0FC03H)=82H<br />

30 DO<br />

40 INPUT “Enter the decoder’s address (0-15): ”,A<br />

50 INPUT “Enter the data to send (0-15): ”,D<br />

60 REM Write the address and data information to Port A<br />

70 XBY(0FC00H)=(D*10H+A)<br />

80 REM Toggle TE (Port C, bit 7)<br />

90 XBY(0FC03H)=0EH<br />

100 XBY(0FC03H)=0FH<br />

110 WHILE 1=1<br />

120 END<br />

Computer-controlled Receiver<br />

Instead of, or in addition to, computer control of the transmitter, you can also add a computer<br />

interface at the receiver. For example, a data logger might accept data from a remote<br />

transmitter and process the data or store it for later use. Figure 12-7 shows a receiver similar<br />

to Figure 12-2’s, with the manual controls replaced by port bits of an 82(C)55.<br />

<strong>The</strong> circuit uses different port bits from Figure 12-6’s circuit, so you can connect both a<br />

transmitter and a receiver to one 8255 if you wish. <strong>The</strong> low nibble of Port C is configured<br />

as an output, and sets A1-A4 on the decoder. As in the previous circuit, A5 is tied high so you<br />

can set the address with 4 bits. Port B is configured as an input, and its bits 4-7 store the<br />

data received at the decoder’s D6-D9. VT is inverted and then connects to the 8052’s INT1<br />

(pin 13). You can use any CMOS inverter.<br />

Listing 12-2 is a BASIC-52 program that sets up the 8255 to receive data at port B, in Mode<br />

0. <strong>The</strong> program writes an address to the decoder’s address inputs, and also turns off TE (PC.7<br />

in Figure 12-6, to ensure that the encoder on this end (if connected) isn’t transmitting while<br />

the decoder is receiving. <strong>The</strong> program uses an edge-detecting interrupt to ensure that the<br />

program won’t re-interrupt if VT is still low when the interrupt routine ends.<br />

<strong>The</strong> main program is a do-nothing loop that waits for an interrupt. When VT goes high,<br />

indicating that a valid transmission has been received, the 8052-BASIC executes an interrupt<br />

routine that reads the data at bits 4-7 of Port B and displays it on the host computer.<br />

Using VT to generate an interrupt is a handy way to detect when new data has arrived, but<br />

you don’t have to use interrupts. If you don’t enable interrupt 1, you can read Port 3’s bit 3<br />

periodically to find out if a new transmission has arrived. Or, you can leave VT unconnected<br />

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