This 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.
Parallel Port Anatomy:
Following are the pinouts:
Picture Courtesy :: Ian Harries
- 8 Output pins [D0 to D7]
- 5 Status pins [S4 to S7 and S3]
- 4 Control pins [C0 to C3]
- 8 ground pins [18 to 25]
Parallel Port Female Connector
The Data PortSending 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” means 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.
Sending Commands to the Port:
This part is easy.Just a single line of code does the trick.
- C program for the motor
#include{stdio.h} //replace {} with <>
That’s it ,you just set all your data pins to 1.
#include{dos.h} //replace {} with <>
void main(void){
outportb(0×378,0xFF);
}
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 you will end up ruining your LED, or source too much current from the port pin].
If you wish to switch it off. Type this:
outportb(0×378,0×00); instead of the above line.
What did you do?:
0×378 is the parallel port address. Usually this is the default address.Sometimes it is 0×278 too
0×00 is the command appearing at the output pins. The Format is in Hexadecimal. So if u want to make pin no2 high, that’s the first pin you type.
0×01 which would mean 0000 0001 for the data port.
0x04 would mean 00000100
0x55 would mean 01010101
0x0A would mean 00001010
see the table below for reference
0000-0
That finishes your basics so that you can run your motor.
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
Material to control a Motor via a parallel port:
- 1 parallel port Male connector
- 1 DC Motor
- 1 Motor Driver [L293D]
- 1 5V regulator [7805]
Steps to Control a Motor:
- Use the Voltage regulator 7805,to get a constant DC 5V voltage from your
DC power supply.
Connect your motor to your Motor Driver L293D.- Connect your parallel port pins to your Female connector [on your PC],through the male connector as follows.
- Short all Ground pins i.e from 18 to 25.
- Commands for the motor
- outportb(0×378,0×00); ———STOP
MOTOR - outportb(0×378,0×03);———MOVE
MOTOR(Break!)) - outportb(0×378,0×01);———MOVE
MOTOR(CCW) - outportb(0×378,0×02);———MOVE
MOTOR(CW) .
- outportb(0×378,0×00); ———STOP
- C program for the motor
#include{stdio.h}
The Sleep(n) function tells the port to hold [Latch] the command for (n) seconds.
#include{conio.h}
#include{dos.h}
[Please replace the {} bracket to <>]
main()
{
outportb(0×378,0×00); ———STOP MOTOR
sleep(2);
outportb(0×378,0×01);———MOVE MOTOR(CCW)
sleep(2);
outportb(0×378,0×02);———MOVE MOTOR(CW)
sleep(2);
outportb(0×378,0×03);———MOVE MOTOR(Break!)
sleep(2);
return 0;
}
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. Hope you found this tutorial useful.
Disclaimer : The information provided here is correct to my best knowledge.You may use it at your own risk.
This is a followup of the first tutorial which described using the port as an output. This tutorial demonstrates how to use the parallel port as an input. This feature is a great help in robotics as it is used to collect data of what the robot really is encountering.
The INPUT PINS
Picture Courtesy :: Ian Harries
The 10,11,12,13,15 pins of the STATUS PORT are the basic input pins.
Though the CONTROL PORT pins can also be used as inputs,only accessing the status pins are described here.Follow these steps to read an input
Step1
Construct the following TEST circuit.
In this example I have taken pin 13 of the STATUS port as an input.
WARNING Please do not feed your port more than 5V.You’ll blow it up.
Check all the voltages with a Multimeter before proceeding
Step2
Fire up your C compiler and typre the following program:
The program scans the STATUS[0x379] port and give an appropriate integer number,depending on what combinations of pins have gone high or low.
In this example ,since I have used pin 13 and connected to a high value i.e a binary “1?, I get a value of “127? on my PC. Please note that this number will differ from PC to PC. Now we test for a Low value i.e a binary “0?. Modify the above circuit as shown below:
Short pin13 to GND.
When you do this and run the above program ,you get a different number.
On my PC ,i get a “230?
Step3
Now using a simple switch case statement you can monitor the input at pin13.
No comments:
Post a Comment
Leave your comment here