CS-220, Sec. 90, Week 9-B
R. Eckert

INPUT/OUTPUT

Classification of I/O according to the number of bits sent at a time:

   Serial (one at a time)

   Parallel (many at a time--typically 8)

Classification of I/O according to how the timing of the transfer is
managed:

   Synchronous--Transmission and reception is synchronized by a common
   clock. Data sent/received at particular instants in the common clock
   cycle. (Like memory read/write operations).

   Asynchronous--Transmission and reception synchronized by special
   status and control signals. For example:

       Receiver Ready for Data (from receiver)
       Valid Data Available (from transmitter)
       Data Accepted (from receiver)

       Use of these signals is called "handshaking".

I/O Programming Techniques:

   Polling (programmed I/O)--Program continually monitors status signals
   until the I/O device is ready to do the I/O.

   Interrupt-Driven I/O--Device sends a special "interrupt" signal to the
   processor. The processor can respond by suspending execution of the
   current program and executing a special program called an "interrupt
   service routine (ISR)." The ISR will control the I/O. After it is done
   executing, control is returned to the program that was executing
   before the device generated the interrupt.


THE CENTRONICS PARALLEL PRINTER INTERFACE AS AN EXAMPLE OF PROGRAMMED I/O

The Centronics Parallel Printer Interface is a standard for parallel
communication between a microcomputer and a printer. It consists of three
ports: an eight-bit status port (input), an eight-bit data port (output),
and an eight-bit command or "strobe" port (output). This can be
visualized as follows:
                                              ---------------
                       | |     -------       |               |
 ------------------    | |<---| Status|<-----|               |
|                  |   | |<---| Port  |<-----|               |
|                  |   | |     -------       |   Centronics  |
|  Microprocessor  |---| |     -------       |   Parallel    |
|                  |---| |--->| Data  |----->|   Printer     |
|                  |   | |--->| Port  |----->|               |
|                  |   | |     -------       |               |
|                  |   | |     -------       |               |
 ------------------    | |--->|Control|----->|               |
                       | |--->| Port  |----->|               |
                       | |     -------       |               |
                     Data Bus                 ---------------

On an IBM-PC compatible computer, the parallel printer ports are at three
consecutive port addresses. The first of these is the Data Port address,
the second the Status Port address, and the last the Control Port
address. When the system is booted, the address of the Data Port of the
principal parallel printer port (called LPT1) is stored at memory address
40h:8. A program can read the word stored at that location in order to
determine the printer's data port address. If, for example, you read that
address and determine that it contains a 3BCh, you know that the
printer's data port address is 3BCh, its status port address is 3BDh, and
its control port address is 3BEh.

The meaining of the bits in each of the printer ports is given below--

Status Port:
              |7|6|5|4|3|2|1|0|
               | | | | | | | |____ 1=timeout
               | | | | | | |______ unused
               | | | | | |________ unused
               | | | | |__________ 1=error occurred
               | | | |____________ 1=printer online
               | | |______________ 1=printer out of paper
               | |________________ 0=printer acknowledgement (ACK)
               |__________________ 0=printer busy (don't send new char)

Data Port: Should contain the 8-bit ASCII code for the next character to
be sent to the printer for printing.

Control Port:
              |7|6|5|4|3|2|1|0|
               | | | | | | | |____ 1=strobe (output data to printer)
               | | | | | | |______ 1=generate an auto linefeed
               | | | | | |________ 0=initialize (reset) printer
               | | | | |__________ 1=enable printer to read data port
               | | | |____________ 1=enable ACK as an interrupt
               |_|_|______________ unused

PRINTING A CHARACTER USING THE POLLING TECHNIQUE--

1. Read the Status Port and test the busy bit (bit-7) until not busy

2. Output the ASCII code of the next character to the Data Port

3. Send a "strobe" signal (1-->0) to the strobe bit (bit-0) of the
   Control Port