Table 10–6 Digital I/O port byte
Bit 7 Bit 6 Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Port I/O Line
X
7
X
6
X
5
X
4
X
3
X
2
X
1
X
0
For example, writing 00011100 to port C (base a 2) will configure
port C I/O lines 0, 1, 5, 6, and 7 to be inputs and lines 2, 3, and 4 to be
outputs:
OUT 122h, 1Ch (00011100 binary = 1C hexadecimal)
3. Write a "1" to the control register (base re 3). This places the I/O
chip into “preset” mode:
OUT 123h, 1
(control register, preset mode)
4. Write a bit pattern to appear at the outputs of the desired I/O port when
the I/O chip is put in “operation” mode; all input bits are unaffected.
5. Write a "3" to the control register (base re 3). This places the I/O
chip back into “operation” mode:
OUT 123h, 3
(control register, operation mode)
Writing and reading from I/O
Writing to or reading from the desired I/O port is accomplished with
single program statements:
1. To write a bit pattern to the desired I/O port:
OUT 122h, FFh
All output bits of port C go high; all input bits are unaffected.
2. To read a bit pattern from the desired I/O port:
PORTC = INP(122h)
The byte read from port C is assigned to variable PORTC.
81