Coder's Guild Mailing List

Port IO in C/C++

Posted by jjwood@xxxxxxx.xxxxxxxxx.xx on 2000-11-09

>Hello -

>I am trying to control a homemade electrical device using a port on my
>computer.  I would like to be able to control the value of the bits
attached to
>each pin in the port.  (I am running Win98, and compiling with MSVC 5.0 or
Borland 3.1)
>1) My port addresses are 0x378(parallel) and 0x3F8(serial).  As I
understand
>it, the pins are represented by 0x378+n, where n is the pin number.  Does
this
>mean that each pin is represented by a BYTE, and not a BIT of memory?  If
so,
what constitutes a 1(high) or a 0(low)?
>2) What is horribly wrong with this bit of code?

>#include <stdio.h>
>void main(void)
>{
>   int *ptrPort = (*int) 0x378;
>
>   *(ptrPort) = 255; //Should this be 32 bit binary instead of >8?
>}

>I am trying to do this at a very low level.  I don't want any >of the
overhead
>of the pre-built functions because I would like to use all of >my pins as
>individual controls.

>Thanks!
>Jason.

If you want to run the signal pretty much right out of a port, I would say
go with your parallel port.  You should then be able to send ASCII
characters to the port to change the status of the lines.  I don't know
individual ASCII codes or their binary equivilants, but you can find that
out on the web.. Then, you should be able to run 8 (maybe its 7, can't
remember) lines to your board, controlling each one.  Say the binary
equivilant of the letter "A" is 00010010, that would make your number one
and four lines go high (or low, whatever is opposite of norm).  If letter
"Z" is 00001000, then your number three line would go high (or low,
whichever)...  If you want to run it off of serial, there should be a clock
line and a data line you can use, then throw it through a multiplexer (or
demultiplexer).

Trying to draw off my of my previous electronics education is killer :-) .. 
Make sure you account for your board failing and possibly feeding current
back into the computer.

As a last ditch effort, probably what you should have done first, is
construct a simple cable for your serial port, and run the signals through a
multimeter or o-scope and see what your voltage levels are, their normal
states, and probably get the frequency as well... Then you can see what the
computer is normally throwing out, and can adapt your circuit to work with
it.  There was a book I saw once on programming the serial/parallel ports,
but can't remember its name.  It came with a disk with all the necessary
code on it, but it was floppy, so the book may have been relatively old.  Do
a search on Amazon for parallel port or serial port, or something similar...

Good luck, let us know how it works out.

Mike


______________________________________________
FREE Personalized Email at Mail.com
Sign up at http://www.mail.com/?sr=signup