How to use parallel port in C for control of external circuits

Hi All
I assume that some of the guys here have used laptops to control external circuits for roboticee type projects. I would like to control some motors
using my laptop as the programming/control environment would be alot better. I can handle the electronic side of things quite well but I fall down when it comes to C programming. I have been learning for a while now, on and off. I need to know how to read data and output data, basically control the parallel port using c code. The old laptop is running win95 if it helps.
I think I need to write data to certain addresses but am not sure. Can anyone help?
Thanks
Naveed
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
The parallel port is usually at 378 hex. If in doubt run debug at the DOS prompt, type d40:0 <enter> and look halfway along the top line for 78 03
q <enter> to exit debug
Anything you write to 378 shows on the pins
bit 0 on 3FA writes the strobe line inverted
bits 3-7 of 379 read as the status lines, b7 is inverted
The original PC would read back the data lines when you read 378, this is no longer the case, you just read back what you wrote.
It is possible to put the port into everal different and clever modes but hey, life's too short :o)
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Check the book "Parallel Port Complete." Discusses the modes, addresses, etc. that may be of help.
HTH Bill
message

better.
the
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
On Thu, 19 Aug 2004 12:53:15 +0100, "The Man With The Harmonica"

I can't speak to c programming, but the below links show how I use qbasic (should be included on your win95 machine) to send bytes to the parallel port to set the data pin values, and how to then read the resulting values on the status pins (in this case checking to see if contacts are open or closed). You probably could use the qbasic to test your hardware until the c code is worked out. The bottom links show other simple parallel port control setups.
http://www.geocities.com/zoomkat/status.htm http://zoomkat.d2g.com:88/cgi/status.bat
http://www.geocities.com/zoomkat/output.htm http://www.geocities.com/zoomkat/ppswitcher.htm
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
Like the others have said the Internet is full of examples on how to do this. Even if the example is written in Basic you ought to be able to readily convert it to C, as it only involves sending a byte to the proper physical memory address. I found a zillion (okay, only 421,000) links with the search phrase "parallel port programming" (no quotes).
However, I *strongly* advise you to either get a good book on the subject (I echo the recommendation for Jan Axelson's "Parallel Port Complete") as even with Win95 some BIOS settings and parallel port types can cause problems. The better how-to's discuss how to determine the type of parallel port you have, and how to change BIOS settings if need be.
There are also DLLs you can use with Windows to write and read with the parallel port. Again, do a Google search and you'll turn up many of them. (Also try Jan's Web site at www.lvr.com.) Most of these come with examples.
Be sure to use the proper interface, or else you'll blow the parallel port right up. You mention you got the electronics side handled, but this needs to be said anyway...
-- Gordon Author: Constructing Robot Bases, Robot Builder's Sourcebook, Robot Builder's Bonanza
The Man With The Harmonica wrote:

Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
message

better.
the
A google search should bring up lots of info on how to use the parallel, serial and game port. I have used the parallel port using DJGPP. I suggest you start by turning LEDs on and off (output) and reading simple on/off switches (input).
Warning: Get it wrong an you may destroy your parallel port! So I suggest plugging in a separate parallel port card to play with.
Each parallel port has three registers.
DATA 278h 378h 3BCh STATUS 279h 379h 3BDh CONTROL 27Ah 37Ah 3BEh
// PARALLEL PORT REGISTERS #define DATA_REG 0x378 #define STATUS_REG 0x379 #define CONTROL_REG 0x37A
If you wanted to set the CONTROL_REG to say 4,
outportb(CONTROL_REG,4);
If you wanted to monitor bit 3 of the STATUS_REG,
while ((inportb(STATUS_REG) & 8) == 0){}
You might be able to set the DATA_REG to input or output by setting a bit in the CONTROL_REG
//Port turn around set bi-directional control as input outportb(CONTROL_REG,46);
//Set output to uni direction outportb(CONTROL_REG,14); // clear bit 5
--
John





Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload
I just relised you can't plug in an extra parallel port into a laptop. You might want to use a safe interface before experimenting, the 8255 perhaps?
http://www.boondog.com /
Other useful sites might be,
http://www.beyondlogic.org /
http://www.doc.ic.ac.uk/~ih/doc/par /
As someone pointed out you can use QBasic,
DEFINT A-Z DataReg = &H378 StatusReg = &H379 ControlReg = &H37A
OUT DataReg, v v = INP(StatusReg)
You can read the game port using QBasics STICK() for the analog inputs and STRIG() for the buttons.
You can also access the serial port from QBasic

external
motors
when
helps.
Add pictures here
<% if( /^image/.test(type) ){ %>
<% } %>
<%-name%>
Add image file
Upload

Polytechforum.com is a website by engineers for engineers. It is not affiliated with any of manufacturers or vendors discussed here. All logos and trade names are the property of their respective owners.