Upload
danyal-zahid
View
234
Download
3
Embed Size (px)
Citation preview
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 1/32
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 2/32
Port
• A port is a set of signal lines that the
micro rocessor or CPU uses to exchan e data
with other components.•
printers, modems, keyboards and display. Most
is 0 or 1.
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 3/32
Parallel Port Vs Serial Port• A parallel port sends and receives data eight bits
.
to be transferred very quickly; however, the
number of individual wires it contain.
• A serial ort sends and receives data one bit at
a time over one wire. While it takes eight times
as long to transfer each byte of data this way,
only a few wires are required.
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 4/32
Serial Vs Parallel Data
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 5/32
Comparison• Serial and Parallel
• 8 bits can be send at a• 1 bit can be send at a
t me
• Fast data transfer
t me
• Slow data transfer
for ground is required
• More components,
for ground is required
• less components, less
more chances of failure
• More cost
chances of failure
• Less cost
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 6/32
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 7/32
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 8/32
Parallel port
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 9/32
PortThe original IBM-PC's Parallel Printer Port had a
total of 12 digital outputs and 5 digital inputs
• 8 out ut ins accessed via the DATA Port
• 5 input pins (one inverted) accessed via the STATUS Port
• 4 output pins (three inverted) accessed via the CONTROL Port
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 10/32
I/O Ports Address
Address Description
From Until
000 00F DMA Controller (direct memory access)
020 02F Master Interrupts
030 03F Slave Interrupts
040 043 Timer
060 060 Keyboard
pea er
170 17F First disk drive
200 20F Game Port
2E8 2EF Serial Port 4 COM4
2F8 2FF Serial Port 2 COM2
378 37F Second parallel port LPT2
3B0 3BB Monochromevideo adapter
3BC 3BF First parallel port LPT1
3E0 3EF Serial port 3 COM3
© Dr J.Iqbal
3F8 3FF Serial port 1 COM1
220 22F Usually used by sound cards
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 11/32
Address of parallel port in windows
• Control panel
•
• OR right click – my computer and then properties
• Device manager
•
• Parallel port (right click, then click properties)
• esources rea a ress o e para e por
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 12/32
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 13/32
Address of parallel port in DOS
• c:\> debug <press enter>
-
• _________________________________________
Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-1999 Microsoft Corp.
-d 0040:0008
0040:0000 BC 03 78 03 78 02 C0 9F ..x.x...
0040:0010 23 C8 FE 80 02 92 10 20-00 00 36 00 36 00 64 20 #...... ..6.6.d
0040:0020 20 39 30 0B 30 0B 34 05-30 0B 3A 27 30 0B 30 0B 90.0.4.0.:'0.0.0040:0030 30 0B 38 09 0D 1C 00 00-00 00 00 00 00 00 00 00 0.8.............
0040:0040 F9 00 C3 00 00 00 00 00-00 03 50 00 E0 1F 00 00 ..........P.....
-
© Dr J.Iqbal
................
0040:0060 07 06 00 D4 03 29 30 80-02 00 18 00 B1 62 0D 00 .....)0......b..
0040:0070 00 00 00 00 00 00 08 00-14 14 14 14 01 01 01 01 ................0040:0080 1E 00 3E 00 31 08 00 60
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 14/32
Parallel port• Data Port
• Status Port
• Control Port
© Dr J.Iqbal(Note that the S7, C0, C1 & C3 signals are inverted)
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 15/32
Parallel Port Address
Address Port Name Read/Write
ase a a or r e
Base + 1 Status Port Read
Base + 2 Control Port Write
378H PORT: In this address the CPU writes the data to be sent to the printer.
It is an OUTPUT port. The eight data bits (D0-D7) are latched to appear in the
output connector.
379H PORT: This is an INPUT port. These signals are used by the CPU to
37AH PORT: In this port the computer writes the signals that control the
printer. Therefore, it is an OUTPUT port.
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 16/32
Pin Assignment used by Printer
Pin Signal IN/OUT Function
1 Strobe Out A low on this line indicates data is
ready
2-9 Data 0-7 Out Data Bus.
10 Ack InInterrupt Line. tells computer that data
has been received.
11 Busy In
Used when buffer is full. A high signal
asserted by the printer to indicate that it
is busy and cannot take data.
12 Paper Out In Communicate paper out
13 Select In High means printer is online/present
14 Auto Linefeed Out Advance a er
15 Error / Fault In Error has occurred
16 Init Out Reset - Active Low
© Dr J.Iqbal
17 Select Printer Out.
printer that it is selected.
18-25 Ground GND Ground
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 17/32
Output
STROBE/: (C0) Tells the printer when the eight data bits are ready to be read. Turns to a
low logic level when the data are ready.
AUTO FD/: (C1) Tells the printer to advance paper.
INIT/: (C2) Reset the printer.
SLCT IN/: (C3) Used to indicate to the printer that it is selected.
- : ata ts.
Inputs:
: n error as occurre . e s op sen ng more a a
SLCT: (S4) Tells the computer that a printer is present.
PE: S5 The rinter is out of a er.
ACK/: (S6) Tells the CPU that the data has been correctly received.
BUSY: (S7) The printer sets this line when its buffer is full. The computer will stop sending
© Dr J.Iqbal
more data.
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 18/32
Addressing the port
Data Bits Table
BIT FUNCTION PIN
D0 data 0 2
Status Bits Table
BIT FUNCTION PIN
D0 not used
Control Bits Table
BIT FUNCTION PIN
D0 STROBE 1
D1 data 1 3
D2 data 2 4
D1 not used
D2 not used
D1 AUTO FD 14
D2 INIT/ 16
D4 data 4 6
D5 data 5 7
D4 SLCT/ 13
D5 PE 12
D4 Not used
D5 not used
D6 data 6 8D7 data 7 9
D6 ACK/ 10D7 BUSY/ 11
D6 not usedD7 not used
© Dr J.Iqbal(Note that the pins 1, 10, 14, 17 are inverted)
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 19/32
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 20/32
Functions used for Data Transfer
Data In:
inportb (PortAddress)
Data Out:outportb (Data , PortAddress)
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 21/32
#i ncl ude <st di o. h>#i ncl ude <dos. h>
.
/ *Thi s pr ogr am set t he
send a byte to the parallel port
output addresses. It's as easy
par a e por t
out put s*/
as you can see. e ou por ;
function sends a byte to aspecified I/O port. The first
voi d mai n ( voi d){cl r scr ( ) ;
function parameter is the
address of the port to write a
,get ch( ) ;
}
.
the value of the byte to send.
Both parameters can be defined
.
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 22/32
#i ncl ude <st di o. h>#i ncl ude <dos. h>
< .
/ *Thi s pr ogr am set t he par al l el
or t out ut s*/
voi d mai n ( voi d){unsi gned i nt BaseAddr ess=0x378;
cl r scr ( ) ;out por t b( BaseAddr ess+2, 0xf f ) ;
get ch( ) ;}
ove program s ows ow o sen a y e o e on ro por of parallel port. Control port is at Base+2 address. Remember
that bit 0,1,3 of control port was inverted by hardware. To get
© Dr J.Iqbal
correct result, we need to use exclusive OR with 0xb [1011],
which will give us correct result.
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 23/32
Problem
, , o con ro por was nver e y
hardware. To get correct result, we need to do
some man pu a on. a are ose
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 24/32
#i ncl ude <st di o. h>#i ncl ude <dos. h>
< .
/ *Thi s pr ogr am set t he par al l el
or t out ut s*/
voi d mai n ( voi d){unsi gned i nt BaseAddr ess=0x378;
cl r scr ( ) ;out por t b( BaseAddr ess+2, 0xf f 0̂xb) ;
get ch( ) ;}
ove program s ows ow o sen a y e o e on ro por of parallel port. Control port is at Base+2 address. Remember
that bit 0,1,3 of control port was inverted by hardware. To get
© Dr J.Iqbal
correct result, we need to use exclusive OR with 0xb [1011],
which will give us correct result.
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 25/32
#include <stdio.h>
#include <dos.h>
#include <conio.h>
/*This function read parallel
port inputs*/
to read a byte from
the arallel ort in ut
int Read_Input(){int Byte;
Byte=inportb(0x379);
address.The main function is only
return Byte;
}
void main void
used to show the
value of the byte on the
{int PP_Input;
clrscr();
PP In ut = Read In ut
.
The inportb(); function
read a b te from the _ _
printf("%d",PP_Input);getch();
}
specified I/O address of
the computer.
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 26/32
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 27/32
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 28/32
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 29/32
Pin SPP Signal EPP Signal IN/OUT Function
A low on this
1 Strobe Write Out
line indicates a
Write, High
indicates a
2-9 Data 0-7 Data 0-7 In-Out Data Bus. Bi-directional
10 Ack Interrupt In Interrupt Line.
11 Bus Wait In
Used for
handshaking.
A EPP cycle
can be started
when low, andfinished when
high.
© Dr J.Iqbal
12Paper Out /
EndSpare In
Spare - Not
Used in EPP
Handshake
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 30/32
Spare - Not
Pin SPP Signal EPP Signal IN/OUT Function
13 Select Spare In Used in EPP
Handshake
When Low,
transfer
15 Error / Fault Spare In
Spare - Note
used in EPP
an s a e
16 Initialize Reset OutReset - Active
Low
17 Select Printer Address Strobe Out
When low,
indicates
Address transfer
18-25 Ground Ground GND Ground
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 31/32
© Dr J.Iqbal
7/27/2019 C parallel port [Compatibility Mode].pdf
http://slidepdf.com/reader/full/c-parallel-port-compatibility-modepdf 32/32
© Dr J.Iqbal