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. This step
ensures that known values appear when the I/O chip is placed in operation
mode.
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)
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.
I/O output program examples
To configure ports A, B, and C as all outputs, issue the commands:
OUT 123h, 2 ‘Direction’ Mode
OUT 120h, FFh
‘PortA’
OUT 121h, FFh
‘PortB’
OUT 122h, FFh
‘PortC’
OUT 123h, 3 ‘Operation’ Mode
Ports A, B, and C will now output all “1”s after issuing the following commands:
OUT 120h, FFh (portA)
OUT 121h, FFh (portB)
OUT 122h, FFh (portC)
or all “0”s after:
OUT 120h, 0 (portA)
OUT 121h, 0 (portB)
OUT 122h, 0 (portC)
66