Computing.Net > Forums > Programming > Programming parallel port in C, linux

Programming parallel port in C, linux

Reply to Message Icon

Original Message
Name: Paul
Date: August 7, 2002 at 17:48:56 Pacific
Subject: Programming parallel port in C, linux
Comment:

I'm currently working on a personal project. I want to be able to send an MP3 file, which has been converted to binary form, via the parallel port to a microcontroller and then eventually transmit the data digitally via infrared. I've written code for the microcontroller in Assembly language, However, I'm not too sure how to transmmit the bytes to the parallel port 8 bits at a time, as I haven't had a great deal of experience in C. I was thinking of using handshaking between the microcontroller and the PC, for eg. when I send a byte to the micro, set one of it's interrupt pins high. Then once the byte has been outputted, send a high signal back to the PC via the parallel port telling the PC to send the next byte.
I found a site on Parapin, a parallel port pin programming library for Linux, which I'm going to use. There was some example code, however nothing in depth enough for my particular application.
If anyone has any ideas or suggestions, they would be much appreciated
Thanks


Report Offensive Message For Removal


Response Number 1
Name: Pete Zieba
Date: September 27, 2002 at 20:29:07 Pacific
Reply: (edit)

I too have just started to code in C for linux . . . I have some experience with uControllers & ASM for them (Pics in particular), but none / not much for pc . . . however, I have been able to get this to work.
**************Start Code**********
#include
#include /* needed for ioperm() */
#include /* for outb() and inb() */
#define DATA 0x378
int main(void)
{
ioperm(0x378,3,1);
outb(0x55, 0x378);
return (0);


}
**********End code*********
saving that to a text file called ex.c
you can compile using "gcc -O2 -o ex ex.c"
the -O2 is supposedly necessary because part or all of the asm/io lib is written in asm, and will not compile without optimizations (that is my probably incorrect interpretation)
The ioperm tells linux that access to 0x379, 380, 381 should be allowed. That's the function of the "3" in there, and the "1" simply means "allow". I believe you still have to do this as root however.
Anyway, this will throw 0x55 out on the parallel port, which should be at 0x378 . . . 0x379 and 0x380 are control and input pins, not necessarily in that order, and do not have to be touched at all for straight output. Simply writing to 379h will do the trick. As far as how to do anything cooler in C, I'm clueless, and and waiting for two books I ordered to come on. Good Luck !

- pete


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Programming parallel port in C, linux 

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge