CET3510 – Lecture 8 – Parallel Port

Parallel Ports of PC
Methods of interfacing
The parallel port
consist of 25 pins:
8 data
4 control outputs
5 status inputs
8 pins are grounded
25 pin female (DB25)
The registers found in standard
parallel port are:
• Data register
• Status register
• Control register
Parallel Port Details
Parallel Port Details (Cont.)
Data registers are connected to data lines.
Control registers are connected to control lines.
Status register is connected to Status lines.
What you write to these registers, will appear in
corresponding lines as voltages. You can measure
it with a Multimeter.
Whatever you 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 (actually 3.5 V). This way we can
programmatically turn on and off any of the data lines and
control lines.
In an IBM PC, these registers are IO mapped and
will have unique address. We have to find these
addresses to work with parallel port.
For a typical PC ,
◦ the base address of LPT1 is 0x378
◦ the base address of LPT2 is 0x278.
The data register resides at this base address
The status register at base address + 1
The control register is at base address + 2.
So once we have the base address, we can calculate
the address of each registers in this manner. The
table in the next slide shows the register addresses
of LPT1 and LPT2.
The parallel port consists of three bytes in the PC I/O address
space, starting at address 0x378.
• The first byte at 0x378 is for 8 bits of output
• The second byte at 0x379 is for 5 bits of input, 3 bits unused
• The third byte at 0x37A is for 4 bits of output, 4 bits of setup
0x378 is the address of the parallel port data register
Base port numbers: 0x378, 0x278
The normal method
◦ Call linux.ioperm() to get permission to access the
◦ Use in() to read from the port (check x86 Instructions)
◦ Use out() to write to the port (check x86 Instructions)
◦ The command #include(“linux.hhf”) provides the
library for the functions of linux.ioperm()
The function ioperm (...) is Linux specific.
Call ioperm() to get permission to access the ports
Use in() to read data from the port.
Must use DX register to hold the 16-bit port number
◦ It allows an application program to access to the 80x86 I/Oaddresses within the range 0x000 to 0x3ff.
◦ These instructions read a byte, word, and double word from an
input port and place the input data into the accumulator
Example: in($379, AL) to read data from port $379
(line 10-line13) and place the information into the
register AL
out( ) provides a HLA language interface to the
machine instruction that outputs the accumulator to
the specified port (i.e., I/O port) using the I/O
address space instead of the memory address space.
Must use DX register to hold the 16-bit port number
mov($FF, AL);
mov($378, DX);
out(AL, DX)
// this will send binary data 1111_1111 stored in AL to data
port $378 (line2 - line9)
Give your program permission to access the port.
This is done by calling the ioperm() function
The syntax is ioperm(from, num, turn_on) , where:
◦ from is the first port number to give access to
◦ num the number of consecutive ports to give access to
◦ turn_on is a boolean value.
Example: ioperm(0x300, 5, 1) would give access to
ports 0x300 through 0x304 (a total of 5 ports). The
last argument is a Boolean value specifying whether
to give access to the program to the ports (true (1)) or
to remove access (false (0)). You can call ioperm()
multiple times to enable multiple non-consecutive
ioperm() can only give access to ports 0x000 through
The ioperm() call requires your program to have root
privileges; thus you need to run it as the root user
LEDS are connected to pins D0 to D7 and to
the ground pins, respectively
Light the LED or output data (value) by
out(AL, DX)
Value of AL is associated with the pins of the
parallel port
Example: To light D0 to D3 you should call
mov(15, AL);
mov($378, DX);
1 + 2 + 4 + 8 = 15.
You have to think the value you give to the
program as a binary number.
Every bit of the binary number control one
output bit. The following describes the
relation of the bits, parallel port output pins
and the value of those bits.
2 3 4 5 6 7
D 0 D1 D2 D3 D4 D 5 D6 D7
Value 1 2 4 8 16 32 64 128
Note: The value above is the numeric value to send to printer
How does it look In HLA under Linux?
program Interface;
begin Interface;
stdout.put ("You must be root to run this program“, nl);
//open port
//Get a data from keyboard by stdin.get(AL);
//Similar get a port number from key board
mov($AA, AL);
//send 1010 1010 to port $378
linux ioperm($378,3,0); //close port
End Interface;

similar documents