Disclaimer: *** NO WARRANTY AT ALL *** But the info given is correct. I hope. Well, check it out yourself if you don't believe me. ----8<--------8<--------8<--------8<--------8<--------8<--------8<---- Some short notes on the printer port of the PC ============================================== Base address ------------ Normally, this table is valid. LPT1 378h or 3BCh LPT2 278h or 378h LPT3 278h The base address can be read from the BIOS table (cut from Ralf Brown's interrupt list): Format of BIOS Data Segment at segment 40h: Offset Size Description 08h WORD Base I/O address of 1st parallel I/O port, zero if none 0Ah WORD Base I/O address of 2nd parallel I/O port, zero if none 0Ch WORD Base I/O address of 3rd parallel I/O port, zero if none 0Eh WORD [non-PS] Base I/O address of 4th parallel I/O port, zero if none [PS] Segment of Extended BIOS Data Segment Note: Above fields filled in turn by POST as it finds parallel ports. POST never leaves gaps. DOS and BIOS parallel device numbers may de redefined by re-assigning these fields. Registers --------- Base + 0 Data Register (r/w) Base + 1 Status Register (r/o) Base + 2 Control Register (r/w) Base + 0: Bits 0-7 Data being output to pins 2-9 (non-inverting). If read: if bit 5 of the control register is 0, you read the value that's previously been written (normal operation), otherwise the value read represents the data read from pins 2-9 [PS2 and some ATs only]. Base + 1: Bits 0-2 unused Bit 3 "Error"; if 0, paper is out, the printer is off-line or an error occurred. Indicates the level of pin 15 (non-inv.) Bit 4 "Selected" if 1; most printers tie this signal high Indicates the level of pin 13 (non-inv.) Bit 5 "Paper Out" if 1 Indicates the level of pin 12 (non-inv.) Bit 6 "Acknowledge" if 0 (normally for about 10ms) Indicates the level of pin 10 (non-inv.) Bit 7 "Busy" if 0; printing is in progress or sth. like that Indicates the level of pin 11 (inverted!) Base + 2: Bit 0 "Data Strobe"; set this to 1 for at least 1 microsecond to signal the printer that there is new data on the lines Controls pin 1; signal is inverted. Bit 1 "Autofeed XT"; if set, a LF is added to each CR by the printer. Controls pin 14; signal is inverted. Bit 2 "Init"; set this to 0 for at least 50us (Epson) to reset the printer. Controls pin 16; signal is not inverted. Bit 3 "Select input" (as seen by the printer); if 1, the codes "DC1" and "DC3" can activate and deactivate the printer. Controls pin 17. Signal is inverted. Bit 4 if 1: "Acknowledge" generates interrupt 0Fh (no external signal) Bit 5 [PS2 and some ATs] direction of the data lines. 0=output, 1=input Bits 6-7 not used Normal setting in a PC: 0Ch How to input data using the printer port ---------------------------------------- *** There is no possibility to switch the data lines of the printer port to input, except for some computers. Try writing FFh to Base+0 and 2Ch to Base+2, then short one of the data lines to ground, input Base+0 and see if one of the bits is 0. If yes, you're lucky. It works with all PS2's and some ATs. But there's a workaround: use a parallel-in-serial-out register, connect the serial output to one of the status lines and the control pins (latch, clock) to two of the data lines. Then give the appropriate signals to the register by writing the correct values to the data register and read in the data bit-wise through the status register. This is not very fast, but cheap. Or, even better: use a multiplexer (74LS157) with four of the status lines (those four that are non-inverting). Control it with one of the numerous outputs. How to do direct output to the printer -------------------------------------- 1. Write your data to Base+0. 2. Write 0Dh to Base+2. 3. Make sure there's a delay of at least one microsecond :-) (your code will do that for you...) 4. Write 0Ch to Base+2. 5. Input from Base+1 and check if Bit 7 is 1. If not, wait for some time but make sure you break the loop with "time out" if it takes too long. 6. ... and repeat this whole procedure as often as you like. Pinout ------ 1 Strobe 2-9 Data 0-7 10 Acknowledge 11 Busy 12 Paper out 13 Select (this is an input!) 14 Autofeed XT 15 Error 16 Init 17 Select Input (this is an output!, name as seen by the printer) 18-25 Ground ---->8-------->8-------->8-------->8-------->8-------->8-------->8----