Parallel Port Tutorial
Parallel Port Tutorial
his tutorial will help you get a taste of controlling your machine using the printer
port. Though the parallel port isn't being used for many applications ,it is a boon
for us hobbyists. This tutorial's main aim is to get you working ,so that you can
send signals from the port like control a motor. Taking inputs from the port will be
covered in a subsequent tutorial.
The Pins having a bar over them ,means that the signal is inverted by the parallel
port's hardware.If a 1 were to appear on the 11 pin [S7], the PC would see a 0.
The Status pins are mainly used by the PC to know the status of the printer ,like
if there is paper in the printer, end of paper etc.
Sending commands involves only the data pins [D0 to D7].Though it is possible
to use the some other pins as input, we'll stick to the basics.
Please remember that the Data pins are from pin 2 to pin 9 and not from pin 1.
If you have a good eyesight, check your parallel port connectors. Both the
connectors [male/female], have numbers etched next to their pins, so people like
us don't screw up our ports, connecting them the wrong way.The word "Parallel"
denotes sending an entire set of 8 bits at once to the PC [That's why term
Parallel Port].However we can use the individual pins of the port ; sending either
a 1 or a 0 to a peripheral like a motor or LED.
#include{stdio.h}
#include {dos.h}
[Please replace the {} bracket to <>]
void main(void)
If you take an LED and put one terminal at pin2 and the other to pin 18,it would
glow.[Use a 2K resistor in series with the LED, otherwise u'll end up ruining your
LED, or source too much current from the port pin]
outportb(0x378,0x00);
So if u want to make pin no2 high, that's the first pin you type
0x01 which would mean 0000 0001 for the data port.
0000-0
0001-1
0010-2
0011-3
0100-4
0101-5
0110-6
0111-7
1000-8
1001-9
1010-A
1011-B
1100-C
1101-D
1110-E
1111-F
That finishes your basics so that you can run your motor.
Before trying out anything ,please remember that your parallel port is not meant
or designed to handle more than 5Volts.If possible , trying accessing your parallel
port using Windows 98.Windows XP does not allow access to the parallel port.
You'll need special drivers for that.
Use the Voltage regulator 7805,to get a constant DC 5V voltage from your
DC power supply.
Connect your parallel port pins to your Female connector [on your PC],through
#include{stdio.h}
#include{conio.h}
#include{dos.h}
[Please replace the {} bracket to <>]
main()
{
outportb(0x378,0x00); ---------STOP MOTOR
sleep(2);
outportb(0x378,0x01);---------MOVE MOTOR(CCW)
sleep(2);
outportb(0x378,0x02);---------MOVE MOTOR(CW)
sleep(2);
outportb(0x378,0x03);---------MOVE MOTOR(Break!)
sleep(2);
return 0;
}
The Sleep(n) function tells the port to hold [Latch] the command for (n) seconds.
eg: sleep(2)------------------delay or sleep for 2 seconds
If you want to work in milliseconds ,use the delay(n) command
eg: delay(500) --------------delay for 500 milliseconds
That's it, you can now control a motor using the parallel port.
Use 2 motors and you have a moving machine.
You can actually control the motors using the arrow keys using the Bioskey()
function. Check "C" help for this.