Download Programmable Peripheral Interface-System Programming-Lecture Notes and more Study notes System Programming in PDF only on Docsity!
Lecture # 11
• Device Used as Parallel port Interface (I/O
controller) is PPI
Programmable Peripheral Interface
(PPI)
Programmable Peripheral Interface
(PPI)
CPU PPI
Parallel I/O Device Printer
The PPI acts as an interface between the CPU and a parallel I/O device. A I/O device
cannot be directly connected to the buses so they generally require a controller to be
placed between the CPU and I/O device. One such controller is the PPI. Here we will see
how we can program the PPI to control the device connected to the PPI which generally
is the printer.
Accessing the Parallel Port
Through BIOS Functions
Int 17H
Accessing the Parallel Port
Through BIOS Functions
Port Interface Number
0=LPT1,1=LPT2,2=LPT
DX
register
02 Request Printer
01 Initialize Printer
00 Display Characters
Services
INT 17H
Int 17H is used to control the printer via the BIOS. The BIOS functions that perform the
printer I/O are listed in the slide above with its other parameter i.e DX which contains the
LPT number. A standard PC can have 4 PPI named LPT1, LPT2, LPT3 and LPT4.
Accessing the Paralle l Port Through BIOS Functions
• Specify the number of Attempts BIOS perform
before giving a time out Error
• This byte Varies Depending upon the speed
of the PC
• Busy =0 Printer is Busy
• Busy =1 Printer is not Busy
Importance of Status Byte
Importance of the Status Byte
If((pstate&0x29)!=0)or
((pstate&0x80)==0) or
((pstate&0x10)==0)
{printerok=FALSE;}
else
{printerok=TRUE;}
The status of the printer can be used in the above described manner to check if the printer
can perform printing or not. In case there is a transfer error , the printer is out of paper or
there is a timeout the printer could not be accessed. Or if the printer is busy or if the
printer is offline the printer cannot be accessed. The pseudo is just performing these
checks.
Importance of the Status Byte
17H/00H Write a character on entry AH= AL=ASCII code DX=Interface# On exit AH=Status Byte
17H/01H Initialize Printer on entry AH= DX=Interface# On exit AH=Status Byte
17H/02H Get Printer Status on entry AH=02, DX=Interface# On exit AH=Status Byte
Printing Programs
The above program intercepts int 17H. Whenever a certain program issues int 17H to
print a character the above TSR program will intercept the service and do nothing if A or
Z is to be printed rest of the characters will be printed normally. Only the As and the Zs
in the printing document will be omitted.
Sample Program
#include <dos.h> void interrupt (old)( ); void interrupt ne wfunc ( ); main( ) { old=getvect(0x17); setvect(0x17,newfunc); keep(0,1000); } void interrupt ne wfunc( ) { if (_AH==0) { if ( _AL != „ „ ) (old)(); } }**
Printing Program 2
In this sample program again int 17H is intercepted. The new interrupt function will
ignore all the spaces in the print document.
Sample Program
#include <dos.h> void interrupt (old)( ); void interrupt newfunc ( ); main() { old=getvect(0x17); setvect(0x17,newfunc); keep(0,1000); } void interrupt newfunc ( ) { if ( _AH == 0 ) { (old)(); _AH=0; (old)(); _AH=0; (old)(); } (old)(); }*
Printing Program 3
In this program interrupt 17h is again intercepted. Whenever a character is to printed the
new function call the old function thrice. As a result a single character in the print
document will be repeated 4 times.
Direct Parallel Port
Programming
Now we will see how the register within the PPI can be accessed directly to control the
printer.
Swapping LPTs
Direct Parallel Port Programming
*unsigned int far * lpt = (unsigned int far ) 0x00400008 ;
unsigned int temp; temp=(lpt); lpt=(lpt + 1);*
*(lpt + 1)=temp;
The LPTs can be swapped i.e LPT1 can be made LPT2 and vice versa for LPT2. This can
be accomplished simply by swapping their addresses in the BIOS data area as shown in
the slide above.
Direct Parallel Port Programming
Port Registers
- 40:08 store the base address for lpt
- The parallel port interface has 3 ports
internally
- If the Base address is 0X378 then the
three Ports will be 0x378,0x379 0x37A
LPT Ports
Direct Parallel Port Programming
Port Registers
Base +0=Data Port
Base +1=Printer Status
Busy=0 ACK=0 PE=1 SL=1 ERR=0 0 0 0
Out of Paper Printer Online Printer is ready for Next Character
Printer is Busy
The first port (Base +0) is the data port. Data to be sent/received is placed in this port. In
case of printer the (Base + 1) is the printer status port as described in the slide. Each bit
represents the various status of the printer quite similar to the status byte in case of BIOS
service.
Printer Control Register
0 0 0 IRQ SI IN ALF ST
Printer Control Register =Base + 2
STROB
Auto Line Field
IRQ ENABLE initialize
SELECT InLine Turn Computer on line
Direct Parallel Port Programming
Port Registers
Execute Interrupt When ACK=0;
(Base +2) is the printer control register it is used to pass on some control information to
the printer as described in the slide.