Interfacciamento porta parallela. e primi esempi in Java Alessandro Memo. Some basics of a parallel port.
Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.
Interfacciamento porta parallela
e primi esempi in Java
A port contains a set of signal lines that the CPU sends or receives data with other components. We use ports to communicate via modem, printer, keyboard, mouse etc. In signaling, open signals are "1" and close signals are "0" so it is like binary system. A parallel port sends 8 bits and receives 5 bits at a time, with the use of three different registers.
Thus it is often called as printer Port or Centronics port (this name came from a popular printer manufacturing company 'Centronics' who devised some standards for parallel port). You can see the parallel port connector in the rear panel of your PC. It is a 25 pins female (DB25) connector (to which printer is connected). On almost all the PCs only one parallel port is present.
The IEEE 1284 Standard which has been published in 1994 defines five modes of data transfer for parallel port. They are: 1) Compatibility Mode 2) Nibble Mode 3) Byte Mode 4) EPP 5) ECP Typically, we’ll use only Compatibility Mode.
Some basics of a parallel port
The old PC has LPT parallel port function only for sending data. Many devices nowadays have attached to this port and can work bidirectional (ECP and EPP mode).
Data Port can sink 24 mA at logic 0 and can source 2.6 mA at logic 1. Notice that the external device don't try to pull these DP lines to ground for a long period. The latch IC could be burn.
Parallel Port – Data bits
Status Port use for feedback signal from printer to the computer. Only 5 MSB bits are used and accessible.
Only 1 bit is inverting input, ie. S7, use for busy signal. S6 bit use for acknowledge signal, this signal used when the printing goes on with interrupt handshake operation. This is a hardware interrupt. In some PC/AT's card and bi-directional card, S2 is used to reflex the state of IRQ, weather it is on or off state. This bit only for internal use.
Parallel Port – Status bits
Control Port is used for controlling the function of printer. Only 4 bits used by printer and 1 bit used for interrupt enable flag.
The most important things must be taken if you connect your own device are : the C0, C1 and C3 logic are inverting at socket connector terminal. This means that, when you send logic 1 (high) to this related bit, the logic output terminal is 0 (low). The C2 and C4 are normal. Note that, C4 bit only for the adapter card function.
Parallel Port – Control bits
Parallel Port – Control bits
Besides that, in some PC/AT's LPT adapter card, bit C5 is used for control direction (and also in bi-directional card). It means that, if this bit is high, Data Port can act as input port, the latch output is tri-state. Data from outside can be read from Data Port.
Control Port can sink 7 mA at logic 0 and can source 0.6 mA at logic 1.
LPT printer parallel interface in PC computer type have specification like this :
In a new card (bidirectional card), simple send a byte to DP port and then read back again. If the result was not an FF Hex or if the result exactly the same to the byte wrote, then the card is installed at that port. This happened because, if the card not installed, the accessing port is a tri-state all, there is no connection to the hardware logic. Tri-state logic interpreted as logic 1.
Software - Java
import jnpout32.*;// interfacciamento alla DLL
public class minimo
static short dato;// variabili di classe
static short indirizzo;
static pPort lpt;
public static void main ( String args[ ])
lpt = new pPort ();// istanza di una nuova porta
indirizzo = 0x378;// indirizzo Data Port LPT1
dato = 0x77;// un dato qualsiasi
lpt.output (indirizzo,dato);// scrivo il dato
System.out.println ("Scrittura nel Port: " + indirizzo +
" del dato: " + dato);
dato = (short) lpt.input (indirizzo);// leggo il dato
System.out.println ("Lettura dal Port: " + indirizzo +
" del dato: " + dato);
Definition and declaration of port:
pPort <MiaPorta> = new pPort();
Methods of classpPort :
ParallelPort output method:
public void output (short port, short value)
ParallelPort input method:
public short input (short port)
Set all bits on Data port to zero:
public void setAllDataBits (short value)
Set PinNumber <pin> to <value>:
public void setPin (short pin, short value)
Extension of methods of classpPort :
Set Data Bit at selected index to a value of 1 or 0
while preserving current values of all other Data bits:
public void setDataBit (short index, short value)
Set Control Bit at selected index to a value of 1 or 0
while preserving current values of all other Control bits:
public void setControlBit (short index, short value)
Get Status Bit at selected index to a value of 1 or 0:
public void GetStatusBit (short index, short value)
NB: attention to the type (short) !!!
dato_in = ((<MiaPorta>.input(STATUS_PORT)^0x80) >> 3);
Checking LPT Bi-directional
The bi-directional card used bit C5 to control the direction of data in Data Port. If the C5 bit is low, the Data Port act as output port and if it is high, the Data Port is used for input port.
When the Data Port act as output port, the data is latch at the output, so if we read this data back from the Data Port, the data must always the same as that we send. But if Data Port act as input port, the read data must be FF Hex, because the latch of Data Port is in tri-state.