-   Programming (
-   -   putc problem - LED flashing (

vasanthraghavan 04-18-2004 04:51 PM

putc problem - LED flashing
My attempt at interfacing LEDs to parallel port:
Hooked up the parallel port to a bunch of LEDs.
Wrote a driver to flash the LEDs.
Compilation went fine.

The following piece of code works:

if (ioperm(base,1,1))
printf("Error: Couldn't get the port at %x\n", base);

for (i = 0; i <= 7; i++)
value = pow(2, i);
outb((unsigned char)value, base);
Result: LEDs work as expected.

However if you replace the code with the following piece of code, it does not work:

FILE *stdprn;
stdprn = fopen("/dev/lpt0", "w"); /*My parallel port is port number 0 */

for (i = 0; i <= 7; i++)
value = pow(2, i);
putc(value, stdprn);
LEDs don't flash at all for this piece of code.
Is there something wrong in calling putc or does it have anything to do with changing
the terminal to buffered/unbuffered i/o?
Any suggestion or direction would be great.

Thank you.

itsme86 04-19-2004 09:58 AM

I really have no idea, but there haven't been any replies so I thought I'd give you something! :)

Have you tried to fflush(stdprn); after putc(value, stdprn);?

I don't know. Would be interesting to hear how/if you get it to work.

kolargol 04-19-2004 10:24 AM

I think the first parallel port is /dev/lp0 not /dev/lpt0

vasanthraghavan 04-19-2004 04:46 PM

Thank you very much. Following the hint by kolargol and itsme86, the LEDs now work correctly! Both the changes were needed.

All times are GMT -5. The time now is 06:01 PM.