+ All Categories
Home > Documents > Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

Date post: 27-Mar-2015
Category:
Upload: evan-hutchison
View: 216 times
Download: 0 times
Share this document with a friend
27
Interfacciamento porta parallela e primi esempi in Java Alessandro Memo Alessandro Memo
Transcript
Page 1: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

Interfacciamento porta parallela

e primi esempi in Java

Alessandro Memo Alessandro Memo

Page 2: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

Some basics of a parallel port

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.

Page 3: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

Some basics of a parallel port

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.

Page 4: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

Some basics of a parallel port

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.

Page 5: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

D0

12345678910111213

141516171819202122232425

D1D2D3D4D5D6D7S7S6S5S4S3S2S1S0

C7C6C5C4C3C2C1C0

DATA PORT

CONTROL PORT

STATUS PORT

Some basics of a parallel port

The parallel portcontains three groups of bits:

• data bits (D0-D7)

• status status (S3-S7)

• control bits (C0-C3)

• and ground bits (18-15)and ground bits (18-15)

GND

Page 6: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

Parallel Port – Data bits

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.

Page 7: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

pin num

BIT SIGNAL NAME

INPUT OUTPUT

DATA PORT

0x0378

9

8

7

6

5

4

3

2

D7

D6

D5

D4

D3

D2

D1

D0

D7

D6

D5

D4

D3

D2

D1

D0

These bits may be input, but all you

will get is the value

currently residing in the output latch, unless the interface is

genuinely bi-directional

Latched TTL push-

pull outputs

with 2.2nF slow-down capacitors

Parallel Port – Data bits

Page 8: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

Parallel Port – Status 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.

Page 9: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

pin num

BIT SIGNAL NAME

INPUT OUTPUT

STATUS PORT

0x0379

11

10

12

13

15

na

na

na

S7

S6

S5

S4

S3

S2

S1

S0

BUSY

ACK

PAPER_OUT

SELECT

ERROR

IRQ

not available

not available

TTL inputs

no pull-up

resistor

not available

not available

not available

not available

not available

not available

not available

not available

not available

not available

not available

Parallel Port – Status bits

Page 10: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

Parallel Port – Control bitsControl 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.

Page 11: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

Parallel Port – Control bits

pin num

BIT SIGNAL NAME

INPUT OUTPUT

CONTROL PORT

0x037A

na

na

na

na

17

16

14

1

C7

C6

C5

C4

C3

C2

C1

C0

not available

not available

DIRECTION

IRQ ENABLE

SLCT IN

INIT

LINE FEED

STROBE

not available

not available

not available

not available

may be used as inputs if

corresponding output bits are set to "1

not available

not available

not available

not available

open collector

output with 4.7K pull-up resistor and 2.2nF slow-

down capacitor

Page 12: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

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.

Parallel Port – Control bits

Page 13: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

Standard Interface Description

LPT printer parallel interface in PC computer type have specification like this :

• Data transfer rate : 1000 cps (maximum)• Synchronization : by externally-supplied

STROBE pulses.• Handshaking -ACK or +BUSY signals.• Logic level : input data and all interface

control signal are compatible with the TTL level.

Page 14: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

Standard Interface Description

Page 15: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

Checking LPT Installed

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.

Page 16: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

Software - Java1. Predisporre una cartella per ogni applicazione

che si intende sviluppare, e copiare al suo interno i file pPort.class e ioPort.class

2. Copiare (se non è già presente) il file jnpout32pkg.dll nella cartella C:\WINDOWS\system32, oppure in alternativa copiarlo nella cartella dell’applicazione

3. Inserire nel programma la direttiva

import jnpout32.*;

Page 17: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

import jnpout32.*; // interfacciamento alla DLL

public class minimo{

static short dato; // variabili di classestatic 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 datoSystem.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);}

}

Page 18: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

Methods of class pPort :

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)

Definition and declaration of port:pPort <MiaPorta> = new

pPort();

Page 19: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

Extension of methods of class pPort :

Set Data Bit at selected index to a value of 1 or 0while 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 0while 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) !!!

Page 20: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

dato_in = ((<MiaPorta>.input(STATUS_PORT)^0x80) >> 3);

Page 21: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.
Page 22: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

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.

Checking LPT Bi-directional

Page 23: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.
Page 24: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.
Page 25: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.
Page 26: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.
Page 27: Interfacciamento porta parallela e primi esempi in Java Alessandro Memo.

Esercizi riepilogativi

1. Leggere lo stato di tutti i tasti2. Individuare lo stato di un solo tasto (bit

S6)3. Accendere e spegnere dei LED (Data

Port) 4. Ruotare i LED con una frequenza di 1

secondo5. Ruotare i LED fino alla pressione di un

tasto particolare6. Accendere e spegnere tutti i LED del

Data Port seguendo sequenze prestabilite associate ai vari tasti (proposto)


Recommended