我正在使用通过以下方案直接连接到PC并行端口的pc1602f PowerTip:
http://www.beyondlogic.org/parlcd/parlcd.htm
一切都很好,LCD通电,并向我显示了带有黑色块的第一行,直到那还好,但现在我想通过并行端口发送信息。
如果您查看该页面,将会看到有将信息发送到LCD的源,但是使用Windows库:
我离开我的代码尝试成为Linux。
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <termios.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/io.h>
#define PORTADDRESS 0x3f8
#define DATA PORTADDRESS+0
#define STATUS PORTADDRESS+1
#define CONTROL PORTADDRESS+2
main(int argc, char **argv)
{char string[] = {"Testing 1,2,3"};
int count;
int len;
char init[10];
init[0] = 0x0F; /* Init Display */
init[1] = 0x01; /* Clear Display */
init[2] = 0x38; /* Dual Line / 8 Bits */
if (ioperm(PORTADDRESS,1,1))
fprintf(stderr, "No se puede acceder al: %x\n", PORTADDRESS), exit(1);
outb(CONTROL, inb(CONTROL) & 0xDF);
outb(CONTROL, inb(CONTROL) & 0x08);
for (count = 0; count <= 2; count++)
{
outb(DATA, init[count]);
outb(CONTROL,inb(CONTROL) | 0x01);
sleep(20);
outb(CONTROL,inb(CONTROL) & 0xFE);
sleep(20);
}
outb(CONTROL, inb(CONTROL) & 0xF7);
len = strlen(string);
for (count = 0; count < len; count++)
{
outb(DATA, string[count]);
outb(CONTROL,inb(CONTROL) | 0x01);
sleep(2);
outb(CONTROL,inb(CONTROL) & 0xFE);
sleep(2);
}
}
完美地编译,但是当我想以root身份尝试并运行时,它抛出了我
root @ ubuntu:/
媒体/ E80C-30D5 / LCD /内部版本#。/ lcd
分段错误(生成“核心”)
root @ ubuntu:/ media / E80C-30D5 / LCD / build#
看着dmesg我发现了这一点。
[3176.691837]液晶显示器[3867]通用
保护ip:400cb4 sp:7fff887ad290错误:0 in LCD [+2000 400 000] root @ ubuntu:/ media / E80C-30D5 / LCD / build#
我放入ttyS的dmesg日志*
root @ ubuntu: / media/E80C-30D5/LCD/build # dmesg | grep ttyS
[2.335717] serial8250: ttyS0 at I / O 0x3f8 (irq = 4) is a 16550A
[2.335817] serial8250: ttyS1 at I / O 0x2f8 (irq = 3) is a 16550A
[2.336100] 00:0 b: ttyS1 at I / O 0x2f8 (irq = 3) is a 16550A
[2.336207] 00:0 c: ttyS0 at I / O 0x3f8 (irq = 4) is a 16550A
root @ ubuntu: / media/E80C-30D5/LCD/build #
不要运行它,您可以帮助我吗?
最佳答案
我同意其他人的看法,如果可能的话,您应该写入适当的设备文件,而不是直接执行I / O。
但是,出于完整性考虑:
ioperm(PORTADDRESS,1,1)
应该
ioperm(PORTADDRESS,4,1)
另外,使用括号可以避免由于错误的宏扩展而导致的错误,如下所示:
#define PORTADDRESS (0x3f8)
#define DATA (PORTADDRESS+0)
#define STATUS (PORTADDRESS+1)
#define CONTROL (PORTADDRESS+2)
关于c - 将rs232编程为LCD(Linux),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3246279/