ich hätte eine Bitte. Da ich zwei LCDs (also nicht gleichzeitig ;-) einfach
nicht zum laufen kriege, möchte ich nun gerne wissen ob es an
meinem Programm liegt oder ob beide LCDs defekt sind.
Da ich sowas schon im Forum gelesen habe: Mein Kabel zum LCD
ist ca 25 cm lang, daran kanns also wohl nicht liegen - ich hab auch
schon alle Pins durchgemessen ob diese wirklich Kontakt haben.
Könnte mal jemand (wayoda ?) das Programm bitte testen und mir
sagen ob es funktioniert ?
Bei mir zeigt die obere Zeile des LCD alle Pixel schwarz, die untere
Zeile alle Pixel hell; sofort nach Anschliessen des IOW und völlig
unbeeindruckt von aufrufen des Programms (halt immer gleich).
Code: Select all
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "iowarrior.h"
int read_w_timeout(int fd, char *data, int size, int sec)
{
int ret;
fd_set fds;
struct timeval timeout;
timeout.tv_sec = sec;
timeout.tv_usec = 0;
FD_ZERO(&fds);
FD_SET(fd, &fds);
if((ret=select(fd+1, &fds, NULL, NULL, &timeout)) == 0) {
return(0); /* timeout */
} else if(ret > 0) {
return(read(fd, data, size));
}
return(-1);
}
int main (int argc, char **argv)
{
int fd, i;
unsigned char data[9];
if((fd = open("/dev/usb/iowarrior1", O_RDWR)) < 0) {
perror("iowarrior if1 open");
return(1);
}
data[0]=0x04; /* special mode: LCD */
data[1]=0x01; /* enable */
if(ioctl(fd, IOW_WRITE, &data) != 0) {
printf("error in write ioctl\n");
}
data[0]=0x05; /* command: lcd write */
data[1]=0x03; /* r0000nnn => 3 bytes to register 0 */
data[2]=0x38; /* 8 bit data, 2 lines display */
data[3]=0x0f; /* cursor on and blink */
data[4]=0x01; /* clear display and put cursor home */
if(ioctl(fd, IOW_WRITE, &data)) {
printf("error in write ioctl\n");
} else {
printf("LCD should be on now\n");
}
if(read_w_timeout(fd, (char *)&data, sizeof(data), 2) != 0) {
printf("packet #%02x : ", data[8]);
for(i=0; i<8; i++) {
printf("%02x ", data[i]);
}
printf("\n");
} else {
printf("read timeout ?!\n");
}
data[0]=0x04;
data[1]=0x00;
if(ioctl(fd, IOW_WRITE, &data) != 0) {
printf("error in write ioctl\n");
}
printf("Disabled LCD mode\n");
close(fd);
return(0);
}