Sunteți pe pagina 1din 13

Parallel Port

Interface
Pin Numbers and Functions
Pin Directions and Associated Registers
Db25 (parallel port)

Positive 5V
D0 to D7

LED +

ground

LED -

Resistor 330 ohms


-Control the current
How to calculate your own values to send to program
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 table describes the relation of the
bits, parallel port output pins and the value of those bits.

Pin 2 3 4 5 6 7 8 9
Bit D0 D1 D2 D3 D4 D5 D6 D7
Value 1 2 4 8 16 32 64 128
Example how to use the program
LPTOUT 0
Set all datapins to low level.

LPTOUT 255
Set all datapins to high level.

LPTOUT 1
Set datapin D0 to high level and all
other datapins to low level.
Assembler

MOV DX,0378H
MOV AL,n
OUT DX,AL
Where n is the data you want to output.

BASIC
OUT &H378, N
Where N is the number you want to output.

C
outp(0x378,n);
or outportb(0x378,n);

Where N is the data you want to output. The actual I/O port
controlling command varies from compiler to compiler because it is
not part of standardized C libraries.
Here is an example source code for Borland
C++ 3.1 compiler:
#include <stdio.h>
#include <dos.h>
#include <conio.h>

/********************************************/
/*This program set the parallel port outputs*/
/********************************************/

void main (void)

{ clrscr(); /* clear screen */


outportb(0x378,0xff); /* output the data to parallel port */
getch(); /* wait for keypress before exiting */

}
How to program using Visual Basic

In Visual Basic, it is not possible to access hardware directly. But


there is a method. To control the parallel port using a VB
program, a file called ‘Inpout32.dll’ is needed. It can be simply
downloaded from the internet and has to be copied to system
directory (c: \Windows \System32).

In any VB program a module has to be included and the


following code must be written on it.

Public Declare Function Inp Lib “inpout32.dll” _


Alias “Inp32″ (ByVal PortAddress As Integer) As Integer
Public Declare Sub Out Lib “inpout32.dll” _
Alias “Out32″ (ByVal PortAddress As Integer, ByVal Value As
Integer)
How to Output data

We can output an 8 bit number using data port. There is a function


called ‘out’ to output data. This function takes two parameters, Port
address and Data. Out Address, data
E.g.:- Consider that we want output 15 using the data port. For that it
can be written the function like below

Out 888, 15

Or the address can be written as a hexadecimal number

Out &h378, 15

The data on the data port will be 00001111 from binary. From D0 to
D3 pins will be on high state and from D4 to D7 will be on low state.
How to light a LED using a parallel port

To light a LED using a parallel port, only a LED and a


resistor are needed. Just 270 or 330 ohms resistor is
sufficient. Connect the resistor and the LED in series and
connect the plus terminal of the LED to any of the data
port from D0 to D7 and the minus terminal to any of the
ground pins.

Let’s think that the LED is connected to the D0.

Out &h378, 1 - LED will be ON

Out &h378, 0 - LED will be OFF


How to Read data

We can read data in the data in any port by ‘Inp’


function and it takes only one parameter.

Variable = Inp (address)

This variable gives the integer value of the


corresponding address.

e.g.:- Suppose that the data on the data port is


15.
X = Inp (&h378) Then variable x will be equal to
15.

S-ar putea să vă placă și