开发者

What is the outp() counterpart in gcc compiler?

In my School my project is to make a simple program that controls the LED lights

my profes开发者_如何转开发sor said that outp() is in the conio.h, and I know that conio.h is not a standard one.

example of outp()

//assume that port to be used is 0x378
outp(0x378,1); //making the first LED light

thanks in advance


You can do this from user space in Linux by writing to /dev/port as long as you have write permissions to /dev/port (root or some user with write permissions). You can do it in the shell with:

echo -en '\001' | dd of=/dev/port bs=1 count=1 skip=888

(note that 888 decimal is 378 hex). I once wrote a working parallel port driver for Linux entirely in shell script this way. (It was rather slow, though!)

You can do this in C in Linux like so:

f = open("/dev/port", O_WRONLY);
lseek(f, 0x378, SEEK_SET);
write(f, "\01", 1);

Obviously, add #include and error handling.


How to write to a parallel port depends on the OS, not the compiler. In Linux, you'd open the appropriate device file for your parallel port, which is /dev/lp1 on PC hardware for port 0x0378.

Then, interpreting the MS docs for _outp, I guess you want to write a single byte with the value 1 to the parallel port. That's just

FILE *fp = fopen("/dev/lp1", "wb");
// check for errors, including permission denied
putc(1, fp);


You're mixing up two things. A compiler makes programs for an OS. Your school project made a program for DOS. outp(0x378,1); is essentially a DOS function. It writes to the parallel port. Other operating systems use other commands.

GCC is a compiler which targets multiple Operating Systems. On each OS, GCC will be able to use header files particular top that system.

It's usually going to be a bit more complex. DOS runs one program at a time, so there's no contention for port 0x378. About every other OS runs far more programs concurrently, so you first have to figure out who gets it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜