Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 04-18-2004, 04:51 PM   #1
Registered: Mar 2004
Location: USA
Distribution: Redhat Linux 9
Posts: 98

Rep: Reputation: 15
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.
Old 04-19-2004, 09:58 AM   #2
Senior Member
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
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.
Old 04-19-2004, 10:24 AM   #3
Registered: Jan 2003
Posts: 48

Rep: Reputation: 1
I think the first parallel port is /dev/lp0 not /dev/lpt0
Old 04-19-2004, 04:46 PM   #4
Registered: Mar 2004
Location: USA
Distribution: Redhat Linux 9
Posts: 98

Original Poster
Rep: Reputation: 15
Thank you very much. Following the hint by kolargol and itsme86, the LEDs now work correctly! Both the changes were needed.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Gnome Terminal Backspace Screen flashing problem! e_liming Linux - Software 4 11-23-2009 09:21 AM
CD RW LED keeps flashing arubin Linux - Hardware 1 11-17-2005 04:54 PM
Flashing SL-5500 = LED lights flash endlessly Zeiph Linux - Laptop and Netbook 1 05-02-2005 07:15 AM
putc and fputc - and other confusion Linh Programming 8 07-21-2003 07:54 AM
putchar and putc are not working .... purpleburple Programming 4 07-04-2002 04:28 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:46 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration