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.

Inputs and Outputs<br />

XBY(0FC03h)=9BH<br />

On reset, the 8255 uses this mode, until you tell it differently.<br />

To read Port A, use<br />

PRINT XBY(0FC00H)<br />

or<br />

PH0. XBY(0FC00H)<br />

To read Port B or C, use the same statement, but with 0FC01H or 0FC02H to select the<br />

port you desire.<br />

To configure all all bits as outputs in mode 0, use this statement:<br />

XBY(0FC03h)=80H<br />

<strong>The</strong>n, to write a value to Port A, use<br />

XBY(0FC00h)=xx<br />

where xx is the value to be written.<br />

Use FC01h to write to Port B, and FC02h for Port C.<br />

Combinations of Inputs and Outputs<br />

Fourteen other combinations of inputs and outputs are possible by setting or clearing bits 0,<br />

1, 3, and 4 in the control word as shown in Figure 6-7. To change the mode settings, determine<br />

which bits to set and clear for the configuration you want, convert the value to decimal or<br />

hexadecimal, and write the value to 0FC03h.<br />

One handy feature of the 8255 is that you can read back the last value written to an output<br />

port. With the ports configured as outputs, you can use the same statements you use to read<br />

the input ports. At Port B or C, reading an output port gives the value in the output latch,<br />

which contains the last value you wrote to the port. Port A works a little differently. Instead<br />

of reading the output latch, you read the actual logic states on Port A’s pins. This means that<br />

at Port A, if a bit is shorted to ground, you will read back a 0 for that bit, even if the last<br />

value written to it was a 1.<br />

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

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

Saved successfully!

Ooh no, something went wrong!