100% found this document useful (1 vote)
70 views

Lecture # 12: Printer Interface

The document discusses printer interfaces and interrupt-driven input/output. It describes how the printer interface uses IRQ7 and how to program interrupt 0x0f. It provides code for interrupt-driven printer I/O using a buffer. It also discusses using timer interrupts to send printing to the printer in the background. It describes printer cable connectivity and how to interconnect parallel port interfaces between computers to enable communication by connecting corresponding nibbles. It provides an algorithm for flow control when transferring data between interconnected computers.

Uploaded by

api-3812413
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
70 views

Lecture # 12: Printer Interface

The document discusses printer interfaces and interrupt-driven input/output. It describes how the printer interface uses IRQ7 and how to program interrupt 0x0f. It provides code for interrupt-driven printer I/O using a buffer. It also discusses using timer interrupts to send printing to the printer in the background. It describes printer cable connectivity and how to interconnect parallel port interfaces between computers to enable communication by connecting corresponding nibbles. It provides an algorithm for flow control when transferring data between interconnected computers.

Uploaded by

api-3812413
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

System Programming Course Code: CS609

[email protected]

Lecture # 12

Printer Interface and IRQ7

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.

Interrupt Driven Printer I/O


char buf [1024]; int i = 0;
void interrupt (*oldint)( );
void interrupt newint ();
void main (void)
{
outport(( *lpt), inport( *lpt) | 4);
outport(( *lpt), inport( *lpt) | 0x10);
oldint =getvect (0x0F);
setvect (0x0F, newint);
outport(0x21, inport( 0x21) & 0x7F);//corrected
keep(0,1000);
}

Virtual University of Pakistan 98


System Programming Course Code: CS609
[email protected]

void interrupt newint ( )


{
outport( *lpt, Buf[ i]);
outport(( *lpt)+2, inport(( *lpt)+2) &0xFE);
outport(( *lpt)+2, inport(( *lpt)+2) | 1);
i++;
if( i== 1024)
{
outport(0x21, inport(0x21)|0x80);//corrected
setvect(0x0F,oldint);
freemem(_psp);
}
}

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.

Virtual University of Pakistan 99


System Programming Course Code: CS609
[email protected]

Printing in the 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);
}

void interrupt newint()


{
if ((( inport((*lpt) +1)) & 0x80) == 0x80)
{
outport (*lpt,st[i++]);
outport ((*lpt)+2, inport((*lpt)+2) & 0xfe);
outport ((*lpt)+2, inport((*lpt)+2) | 1);
}
if (i==32)
{
setvect (0x08,oldint);
freemem(_psp);
}
(*oldint) ();
}

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

Virtual University of Pakistan 100


System Programming Course Code: CS609
[email protected]

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

Printer Cable Connectivity


1 STROB
2 D0
3 D1
4 D2
5 D3
6 D4
7 D5
8 D6
9 D7
10 ACK
11 BUSY
12 PE
13 SLCT
14 AUTO FEED
15 ERROR
16 INIT
17 SLCT IN
18-25 GND

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.

Virtual University of Pakistan 101


System Programming Course Code: CS609
[email protected]

Computer to Computer communication

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.

Virtual University of Pakistan 102


System Programming Course Code: CS609
[email protected]

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.

Virtual University of Pakistan 103


System Programming Course Code: CS609
[email protected]

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.

BUSY ACK PE SLC ER


Sender
1 B3 B2 B1 B0
Receiver send
back LOW
Nibble and D4=0
received as
BUSY = 1 by
Sender
Receiver
0 B3 B2 B1 B0
D4 D3 D2 D1 D0

Virtual University of Pakistan 104


System Programming Course Code: CS609
[email protected]

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.

Virtual University of Pakistan 105


System Programming Course Code: CS609
[email protected]

BUSY ACK PE SLC ER


Sender
Receiver send
0 B7 B6 B5 B4
back Hi Nibble
and turns
D4 = 1 received
as BUSY = 0 by
Sender
Receiver
1 B7 B6 B5 B4

D4 D3 D2 D1 D0

Virtual University of Pakistan 106

You might also like