Lecture # 12: Printer Interface
Lecture # 12: Printer Interface
Lecture # 12
Printer
Interface
Printer ACK
Interface
INT
PIC IRQ7
Printer
The printer interface uses the IRQ 7 as shown in the slide above. Therefore if interrupt
driven I/O is to be performed int 0x0f need to be programmed as an hardware interrupt.
Above is a listing of a program that uses int 0x0f to perform interrupt driven I/O. To
enable the interrupt 0x0f three things are required to be done. The interrupt should be
enabled in the printer control register, secondly it should also be unmasked in the IMR in
PIC. The program can then intercept or set the vector of interrupt 0x0f by placing the
address of its function newint();
The newint() will now be called whenever the printer can perform output. This newint()
function writes the next byte in buffer to the data registers and then send a pulse on the
strobe signal to tell the printer that data has been sent to it. When whole of the buffer has
been sent the int 0x0f vector is restored, interrupt is masked and the memory for the
program is de-allocated.
The above listing might not work. Not all of the printer interfaces are designed as
described above. Some modifications in the printer interface will not allow the interrupt
driven I/O to work in this manner. If this does not work the following strategy can be
adopted to send printing to the printer in background.
#include <stdio.h>
#include <dos.h>
#include <bios.h>
#include <conio.h>
#include <stdlib.h>
void interrupt (*oldint)();
void interrupt newint();
unsigned int far * lpt = (unsigned int far *)0x00400008;
char st[80]= "this is a test print string !!!!!!!!!!!";
int i ;
void main ()
{
oldint = getvect(0x08);
setvect(0x08,newint);
keep(0,1000);
}
This program uses the timer interrupt to send printing to the printer in the back ground.
Whenever the timer interrupt occurs the interrupt function checks if the printer is idle or
not. If it’s the printer is idle it takes a byte from the buffer and sends it to the data port of
the printer interface and then sends a pulse through the strobe signal. When the buffer is
full the program restores the int 8 vector and the relinquishes the memory occupied by
the program.
Printer Cable Connectivity
Not all the bits of the internal registers of the PPI are available in standard PCs. In
standard PCs the PPI is connected to a DB25 connector. And some of the bits of its
internal registers are available as pin outs as describes in the slide above.
Computer to Computer
Connectivity
It might be desirable to connect one computer to another via PPIs to transfer data. One
might desire to connect them such that one port of PPI at one end is connected to another
port of the other PPI at the other end. But interconnecting the whole 8 bits of PPI cannot
be made possible as all the bits of the internal ports are not available as pinouts. So the
answer is to connect a nibble (4-bits) at one end to the nibble at the other. In this way two
way communication can be performed. The nibbles are connected as shown in the slide
above.
PPI Interconnection
P0 2 15 Q3
P1 3 13 Q4
P2 4 12 Q5
P3 5 10 Q6
P4 6 11 Q7
Q3 15 2 P0
Q4 13 3 P1
Q5 12 4 P2
Q6 10 5 P3
Q7 11 6 P4
The pins that are interconnected are shown in the slide above. Another thing worth
noticing is that the 4th bit of the data port is connected to the BUSY and vice versa. The
BUSY is inverted before it can be read from the status port. So the 4th bit in data port at
PC1 will be inverted before it can be read at the 7th bit of status register at PC2.
Flow Control
An algorithm should be devised to control the flow of data so the receiver and sender
may know when the data is to be received and when it is to be sent. The following slides
illustrate one such algorithm.
D4 D3 D2 D1 D0
Sender
0 B3 B2 B1 B0
Sender sends
LOW Nibble
and D4 = 0
received as
BUSY = 1
Receiver
1 B3 B2 B1 B0
BUSY ACK PE SLC ER
E7 E6 E5 E4 E3
First the low nibble of the byte is sent from the sender in bit D0 to D3 of the data port. D4
bit is cleared to indicate the low nibble is being sent. The receiver will know the arrival of
the low nibble when its checks BUSY bit which should be set (by the interface) on
arrival.
The receiver then sends back the nibble turning its D4 bit to 0 as an acknowledgement of
the receipt of the low nibble. This will turn the BUSY bit to 1 at the sender side.
D4 D3 D2 D1 D0
Sender
1 B7 B6 B5 B4
Sender sends Hi
Nibble and turns
D4 = 1 received
as BUSY = 0 by
Receiver
Receiver
0 B7 B6 B5 B4
BUSY ACK PE SLC ER
The sender then send the high nibble and turns its D4 bit to 1 indicating the transmission
of high nibble. On the receiver side the BUSY bit will turn to 0 indicating the receipt of
high nibble.
The receiver then sends back the high nibble to the sender as an acknowledgment.
D4 D3 D2 D1 D0