2–28
;----------------------------------------------------------
; Code to set the parallel port mode to bi-directional
;----------------------------------------------------------
MOV AH,0CDh ; AMPRO command
MOV AL,0Ch ; AMPRO function
MOV BX,01h ; Extended mode (use 00 to set output-only mode)
INT 13h
Within bi-directional mode, the port can be in its input state or output state. The code shown above
leaves the port in its input state. An IN instruction of I/O address 378h reads the current state of
the data lines.
To change the port between input and output states, write a 1 to bit five of the control register to
set the port to its input state; or a 0 to set it to its output state. Here is a cod e samp le fo r
dynamically changing the port direction (after it is in Extended Mode).
;----------------------------------------------------------
; Code to change the parallel port direction to input
;----------------------------------------------------------
MOV DX,37A
IN AL,DX
OR AL,20h ;set bit 5 (input)
OUT DX,AL
;
;----------------------------------------------------------
; Code to change the parallel port direction to output
;----------------------------------------------------------
MOV DX,37Ah
IN AL,DX
AND AL,0DFh ;clear bit 5
OUT DX,AL
Using the Control Lines for Additional I/O
Besides the eight data lines, you can use the four control lines (STB*, AUTOFD*, INIT*, and
SELIN*) as general purpose output lines. Similarly, you can use the five status lines (ERROR*,
SLCT, PE, ACK*, and BUSY) as general purpose input lines.
You can read the four control lines and use them as input lines. These lines have open collector
drivers with 4.7K ohm pull-ups. To use a control line as an input line, you must f irst write to its
corresponding bit in the control register. If the line is inverting (*), write a 0, o therwise write a 1.
This will cause the line to float (pulled up by the 4.7K ohm resistors). When a line fl oats, you can
use it as an input.
Enabling the Parallel Port Interrupt
Bit 4 in the Control Re gister enables the parallel p ort interru pt. If this bit is hig h 1, then a rising
edge on the ACK* (IRQ) line will produce an interrupt on the parallel po rt interrup t, IRQ7.