8fa5924841d31aa0a2b8255495360ee7.ppt
- Количество слайдов: 26
Lecture # 11
Programmable Peripheral Interface (PPI)
Programmable Peripheral Interface (PPI) • Device Used as Parallel port Interface (I/O controller) is PPI
Programmable Peripheral Interface (PPI) CPU PPI Parallel I/O Device Printer
Accessing the Parallel Port Through BIOS Functions
Accessing the Parallel Port Through BIOS Functions Services INT 17 H 00 Display Characters 01 Initialize Printer 02 Request Printer DX Port Interface Number register 0=LPT 1, 1=LPT 2, 2=LPT 3
Accessing the Parallel Port Through BIOS Functions All the function Return in AH the Current Printer Status 7 6 Printer Busy 5 4 3 2 1 0 Time out Receive Mode Selected Out of Paper Printer Off. Line Transfer Error
Accessing the Parallel Port Through BIOS Functions Time Out Byte 0040: 0078 LPT 1 0040: 0079 LPT 2 0040: 007 A LPT 3
Accessing the Parallel 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 the Status Byte
Importance of the Status Byte If((pstate&0 x 29)!=0)or ((pstate&0 x 80)==0) or ((pstate&0 x 10)==0) {printerok=FALSE; } else {printerok=TRUE; }
Importance of the Status Byte 17 H/00 H Write a character on entry AH=00 AL=ASCII code DX=Interface# On exit AH=Status Byte 17 H/01 H Initialize Printer on entry AH=01 DX=Interface# On exit AH=Status Byte 17 H/02 H Get Printer Status on entry AH=02, DX=Interface# On exit AH=Status Byte
Printing Program
Printing Program REGS regs; FILE *fptr; void main(void) { fptr=fopen(“c: \temp\abc. text”, ”rb”); regs. h. ah=1; regs. x. dx=0; int 86(0 x 17, ®s); while(!feof(fptr)) {regs. h. ah=2; regs. x. dx=0; int 86(0 x 17, ®s); if ((regs. h. ah & 0 x 80)==0 x 80) { regs. h. ah=0; regs. h. al=getc(fptr); int 86(0 x 17, ®s); }}}
Printing Program 1 #include <dos. h> void interrupt (*old)( ); void interrupt newint ( ); main( ) { old = getvect(0 x 17); setvect(0 x 17, newint); keep(0, 1000); } void interrupt new () { if (_AH==0) { if ((_AL>='A')&&(_AL<='Z')) return; } (*old)(); }
#include <dos. h> void interrupt (*old)( ); void interrupt newfunc ( ); main( ) { old=getvect(0 x 17); setvect(0 x 17, newfunc); keep(0, 1000); } void interrupt newfunc( ) { if (_AH==0) { if ( _AL != ‘ ‘ ) } (*old)(); } Printing Program 2
void interrupt (*old)( ); void interrupt newfunc ( ); main() { old=getvect(0 x 17); setvect(0 x 17, newfunc); keep(0, 1000); } void interrupt newfunc ( ) { if ( _AH == 0 ) { (*old)(); _AH=0; (*old)(); } else (*old)(); } Printing Program 3
Direct Parallel Port Programming
Direct Parallel Port Programming • BIOS support up to three parallel ports • Address of these LPT ports is Stored in BIOS Data Area 40: 08 word 40: 0 A word LPT 1 LPT 2 40: 0 C word LPT 3 40: 0 E LPT 4 word
Direct Parallel Port Programming Dump File Text
Direct Parallel Port Programming unsigned int far * lpt = (unsigned int far *) 0 x 00400008 ; unsigned int temp; temp=*(lpt); *lpt=*(lpt + 1); *(lpt + 1)=temp;
Direct Parallel Port Programming Port Registers • 40: 08 store the base address for lpt 1 • The parallel port interface has 3 ports internally • If the Base address is 0 X 378 then the three Ports will be 0 x 378, 0 x 379 0 x 37 A
Printer Data Port Base +0 = Data Port 7 6 5 4 3 2 1 0
Printer Status Register Base + 1 = Printer Status 7 6 Busy=0 5 4 3 ACK=0 PE=1 SL=1 Out of Paper ERR=0 2 0 Printer Online Printer is ready for Next Character Printer is Busy 1 0 0 0
Printer Control Register = Base + 2 7 0 6 0 5 0 IRQ ENABLE Execute Interrupt When ACK=0; 4 IRQ 3 SI 2 IN initialize SELECT In. Line Turn Computer on line 1 ALF 0 ST Auto Line STROB Field
Direct Parallel Port Programming file *fptr; unsigned far *base=(unsigned int far *)0 x 00400008 void main ( ) { fptr=fopen(“c: \abc. txt”, ”rb”); while( ! feof (fptr) ) { if(( inport (*base + 1 ) & 0 x 80) == 0 x 80) { outport(*base, getc(fptr)); outport((*base)+2, inport((*base+2) & 0 x. FE); outport((*base)+2, inport((*base+2) | 0 x 01); } }}
8fa5924841d31aa0a2b8255495360ee7.ppt