Está en la página 1de 10

Parallel port basics:

In computers, ports are used mainly for two reasons: Device control
and communication. We can program PC's Parallel ports for both.
Parallel ports are mainly meant for connecting the printer to the PC.
But we can program this port for many more applications beyond
that.

Parallel ports are easy to program and faster compared to the


serial ports. But main disadvantage is it needs more number of
transmission lines. Because of this reason parallel ports are not used
in long distance communications. Let us know the basic difference
between working of parallel port and serial port. In serial ports, there
will be two data lines: One transmission and one receive line. To
send a data in serial port, it has to be sent one bit after another with
some extra bits like start bit, stop bit and parity bit to detect errors.
But in parallel port, all the 8 bits of a byte will be sent to the port at
a time and a indication will be sent in another line. There will be
some data lines, some control and some handshaking lines in
parallel port. If three bytes of data 01000101 10011100 10110011 is
to be sent to the port, following figures will explain how they are
sent to the serial and parallel ports respectively. We can understand
why parallel port communication is faster compared to that of serial.
In the PC there will be D-25 type of female connector having 25 pins
and in the printer; there will be a 36-pin Centronics connector.
Connecting cable will combine these connecters using following
convention. Pin structure of D-25 and Centronics connecters are
explained bellow.

Normally, data, control and status registers will have following


addresses. We need these addresses in programming.

Register LPT1 LPT2


Data register (Base Address + 0) 0x378 0x278
Status register (Base Address + 1) 0x379 0x279
Control register (Base Address + 2) 0x37a 0x27a

Note: All the parallel ports do not have bidirectional capability. Earlier
parallel ports had only output enabled in data pins since printers only
inputs data. But latter, to make parallel port capable of communicating
with other devises, bidirectional ports are introduced.

By default, data port is output port. To enable the bidirectional property


of the port, we need to set the bit 5 of control register.
To know the details of parallel ports available in your computer, follow
this procedure:

• Right click on My Computer, go to "Properties".

• Select the tab Hardware, Click Device manager.

• You will get a tree structure of devices. In that Expand


"Ports (Com1 & LPT)".

• Double Click on the ECP Printer Port (LPT1) or any other


LPT port if available.

• You will get details of LPT port. Make sure that "Use this
Port (enable)" is selected.

• Select tab recourses. In that you will get the address range
of port.

To start programming, you will need a D-25 type Male connector. Its
pin structures can be found in the connector as follows:
Programming the Parallel Port in DOS:

To start programming the port, we will use DOS. In DOS we have


commands to access the port directly. But, these programs will not
work on the systems based on Windows XP, Windows NT or higher
versions. For security reasons, higher versions of the windows do not
allow accessing the port directly. To program the parallel port in these
systems, we need to write kernel mode driver.

When we want to find out whether particular pin of the port is


high or low, we need to input the value of corresponding register as a
byte. In that, we have to find out whether the corresponding bit is high
or low using bitwise operators. We can't access the pins individually.
So, you need to know basic bitwise operations.

Main bitwise operators that we need are bitwise AND '&' and
bitwise OR '|'. To make a particular bit in a byte high without affecting
other bits, write a byte with corresponding bit 1 and all other bits 0; OR
it with original byte. Similarly, to make particular bit low, write a byte
with corresponding bit 0 and all other bits 1; AND it with original byte.

In Turbo C, there are following functions used for accessing the


port:

• outportb( PORTID, data);


• data = inportb( PORTID);
• outport( PORTID, data);
• data = inport( PORTID);

outport() function sends a word to port, inport() reads a word


from the port. outportb() sends a byte to port and inportb() reads a
byte from the port. If you include DOS.H header, these functions will be
considured as macro, otherwise as functions. Function inport() will
return a word having lower byte as data at PORTID and higher byte as
data at PORTID+2. So, we can use this function to read status and
control registers together. inportb() function returns byte at PORTID.
outport() writes the lower byte to PORTID and higher byte to
PORTID+1. So this can be used to write data and control together.
outportb() function write the data to PORTID. outport() and outportb()
returns nothing.
Let us start with inputting first. Here is an example program, copy it
and run in Turbo C or Borland C without anything connected to parallel
port. Then you should see data available in status register and pin
numbers 10, 11, 12, 13 and 15 of the parallel port. Pin 11 (active low)
is 0 and all other pins are 1 means it is OK.

To understand bitwise operations: you want to find data in pin 15,

bit no. 7654 3210 bit no. 7654 3210


data : XXXX 1XXX data : XXXX 0XXX
& with : 0000 1000 (0x08 ) & with : 0000 1000 (0x08 )
-> 0000 1000 (0x08 -> -> 0000 0000 (0x00 ->
bit 3 is high ) bit 3 is low)
value of (data & 0x08) will be 0x08 if bit 3 of register is high,
0therwise.
Interfacing of Seven Segment with Parallel port:-
Apparatus:

Seven segment C-5611, Parallel Port Connector cord, Jumper Wires


Bread Board.

Procedure:

1. Open windows 98 as OS
2. Connect the male connector of the parallel port cord to the PC
3. Now connect the Female Connector of cord with seven
segment C-5611 as shown in table.

Table: Connection between Seven Segment and Female


Connector

Seven Segment Pin Female Connector Pin


No. No.
1 6
2 5
3 19
4 4
5 9
6 3
7 2
8 20
9 7
10 8
Table: Relationship of decimal No. , Segment Display
and Hexadecimal Equivalent

Pin Out of seven segment


Computer Interfacing

Introduction: -

To communicate world the computers use peripherals (I/O devices). Commonly used
peripherals are: A/D converter, D/A converter, CRT, printers, hard disks etc. Peripherals
are connected to the microcomputer through electronic circuit. The interfacing circuit
converts the data available from an input device into compatible format for the computer.
Some interfacing devices are I/O ports, Programmable
Peripheral Interface (PPI) etc. This I/O port can be either of PC or Micro controller etc.
Interface actually get input from the input side and convert the data into the compatible
form which can be received in interpretable form and the same interface also collect the
signal from output side and reconvert in the form which can be received by input side.

Parallel Port Or Printer Port: -


As we know, the data, control and status lines are connected to there corresponding
registers inside the computer. So by manipulating these registers in program, one can
easily read or write to parallel port with programming languages like c& c++.
The registers found in a standard parallel are: -
 Data register: -This register is connected to data lines.
 Status Register: -This register is connected to status line.
 Control register: - This register is connected to control lines.
Here the word connection does not mean that there are some physical connections
between data\control\status lines. The registers are connected virtually connected
to the corresponding lines. So, whatever we write to these registers will appear in
corresponding lines as voltages. We can measure this voltage with the help of
multimeter. Whatever we give to parallel port as voltages can be read from these
registers. For example, if we write ‘1’ to data register, the line data0 will be
driven to +5V.

Address of these registers: -

In an IBM PC, these registers are I/O mapped and will have a unique address. We have to
find these addresses to work with parallel port. For a typical PC, the base address of
LPT1 is 0x378 and of LPT2 is 0x278. The Data register resides at this base address,
Status register at base address +1 and the control register is at base address +2. So, once
we have base address, we can calculate the register in this manner. The table below
shows the register addresses of LPT1 and LPT2.

Register LPT1 LPT2


Data register (base address +0) 0x37 0x278

8
Status register (base address +1) 0x37 0x279

9
Control register (base address +2) 0x37a 0x27a
Example of a Computer Interfaced Relay Driver Circuit

También podría gustarte