gcc 编译器中的 outp() 对应项是什么?

发布于 2024-12-07 15:16:55 字数 235 浏览 9 评论 0原文

在我的学校,我的项目是制作一个简单的程序来控制 LED 灯,

我的教授说 outp() 位于 conio.h 中,而且我知道 conio.h 不是标准程序。

outp() 的示例

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

提前致谢

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

my professor 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

谎言 2024-12-14 15:16:55

只要您拥有 /dev/port 的写入权限(root 或某些具有写入权限的用户),您就可以从 Linux 中的用户空间写入 /dev/port 来执行此操作)。您可以在 shell 中使用以下命令执行此操作:(

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

请注意,十进制 888 是十六进制 378)。我曾经用这种方式完全用 shell 脚本编写了一个适用于 Linux 的并行端口驱动程序。 (不过,速度相当慢!)

您可以在 Linux 中用 C 语言执行此操作,如下所示:

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

显然,添加 #include 和错误处理。

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.

神回复 2024-12-14 15:16:55

如何写入并行端口取决于操作系统,而不是编译器。在 Linux 中,您需要为并行端口打开相应的设备文件,即 PC 硬件上端口 0x0378 的 /dev/lp1

然后,解释 MS 文档 _outp ,我猜您想将值为 1 的单个字节写入并行端口。那只是

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

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);
云归处 2024-12-14 15:16:55

你混淆了两件事。编译器为操作系统编写程序。你们学校的项目制作了一个 DOS 程序。 outp(0x378,1);本质上是一个DOS函数。它写入并行端口。其他操作系统使用其他命令。

GCC 是一个针对多个操作系统的编译器。在每个操作系统上,GCC 将能够使用该系统特定的头文件。

它通常会更复杂一些。 DOS 一次运行一个程序,因此不会争用端口 0x378。大约所有其他操作系统都同时运行更多的程序,因此您首先必须弄清楚谁获得了它。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文