Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
dll
PC parallel port is 25 pin D-shaped female connector in the back of the computer. It is normally
used for connecting computer to printer, but many other types of hardware for that port is
available today.
Not all 25 are needed always. Usually you can easily do with only 8 output pins (data lines) and
signal ground. I have presented those pins in the table below. Those output pins are adequate for
many purposes.
pin function
2 D0
3 D1
4 D2
5 D3
6 D4
7 D5
8 D6
9 D7
Pins 18,19,20,21,22,23,24 and 25 are all ground pins
The typical parallel port I/O addess configurations seen on PCs with ISA bus:
Those are the typical I/O addresses used in ISA bus based systems. In PCI bus based
systems the LPT1 port on motherboard is typically at I/O-address 378h or 3BCh. If the
systems has extra LPT ports on multi-IO card in PCI bus, those extra LPT ports work
differently than the "normal parallel port" described in this document, and the same
control methods can't be applied to them (they are on different I/O addresses and could
use different control register system that could be card specific, the driver software that
comes with the card makes them to look like LPT ports for the applications using standard
operating system printing routines).
The following examples are for DOS system (they might or might not work on other
systems). The code examples are designed to be used with LPT1 port that resides in I/O
address 378h.
Assembler
The input pins can be read from the I/O address LPT port base address + 1.
The meaning of the buts in byte you read from that I/O port:
Assembler
MOV DX, 0379H
IN AL, DX
You get the result for read from AL register
//import java.lang.Integer;
public class ioTest
{
static short datum;
static short Addr;
static pPort lpt;
do_read_range();
Addr=0x378;
datum=0x77;
do_write();
// etc...
Addr++;
do_read();
Addr--;
do_read();
do_read_range();
}
//======================================================================
//========================================================================
//============
// load 'jnpout32.dll'
Static { System.loadLibrary("jnpout32");}
}
//========================================================
//=========================================================
class pPort
{
ioPort pp; // wrapper class for 'Jnpout32.dll'
// with methods:
// int Out32(int port, int value);
// int Inp32(int port);
short portAddress; // address of data port
short currentVal; // current value of port bits
public pPort()
{
pp = new ioPort();
portAddress = (short)0x378; // Hex Address of Data Byte of PC Parallel Port
setAllDataBits((short)0); // initialize port bits to 0
currentVal = 0x00;
}
/**
* set all bits on Data port to zero
**/
public void setAllDataBits(short value)
{
pp.Out32(portAddress, value);
currentVal = value;
}
/**
* Set Data Bit at selected index to a value of 1 or 0
* while preserving current values of all other Data bits
**/
void setDataBit(short index, short value)
{
switch(index)
{
case 0:
if (value==0) // Set Data[0] to 0
default:
System.out.println("index must be 0 - 7");
}
pp.Out32(portAddress, currentVal);
}