Foro de elhacker.net

Informática => Electrónica => Mensaje iniciado por: ¨°o.O (ßa¢Kg|姧) O.o° en 14 Julio 2010, 13:26 pm



Título: Inicializar LCD (Linux)
Publicado por: ¨°o.O (ßa¢Kg|姧) O.o° en 14 Julio 2010, 13:26 pm
Hola a todos,

Estoy usando un powertip pc1602f directamente conectado al puerto paralelo del pc utilizando el esquema este:
http://www.beyondlogic.org/parlcd/parlcd.htm

Todo bien lo energizo el lcd y me muestra la primera fila con bloques negros, hasta ahí bien pero ahora quiero mandar información por el puerto paralelo.

Si mirais la página vereis que hay un código fuente para mandar información al lcd, pero usa librerias de windows  :huh:

Dejo mi código intentado convertido en linux.

Código
  1. #include <stdio.h>  
  2. #include <string.h>  
  3. #include <unistd.h>  
  4. #include <fcntl.h>  
  5. #include <errno.h>  
  6. #include <termios.h>
  7. #include <stdlib.h>
  8. #include <unistd.h>
  9. #include <sys/io.h>
  10. #define PORTADDRESS 0x3f8
  11. #define DATA PORTADDRESS+0
  12. #define STATUS PORTADDRESS+1
  13. #define CONTROL PORTADDRESS+2
  14.  
  15. main(int argc, char **argv)
  16. {char string[] = {"Testing 1,2,3"};
  17.  
  18.    int count;
  19.    int len;
  20.  
  21.    char init[10];
  22.    init[0] = 0x0F; /* Init Display */
  23.    init[1] = 0x01; /* Clear Display */
  24.    init[2] = 0x38; /* Dual Line / 8 Bits */
  25.  
  26.    if (ioperm(PORTADDRESS,1,1))
  27.        fprintf(stderr, "No se puede acceder al: %x\n", PORTADDRESS), exit(1);
  28.  
  29.    outb(CONTROL, inb(CONTROL) & 0xDF);
  30.    outb(CONTROL, inb(CONTROL) & 0x08);
  31.  
  32.  
  33.    for (count = 0; count <= 2; count++)
  34.    {
  35.  
  36.        outb(DATA, init[count]);
  37.        outb(CONTROL,inb(CONTROL) | 0x01);
  38.        sleep(20);                                
  39.        outb(CONTROL,inb(CONTROL) & 0xFE);
  40.        sleep(20);                                  
  41.    }
  42.    outb(CONTROL, inb(CONTROL) & 0xF7);  
  43.  
  44.    len = strlen(string);
  45.  
  46.    for (count = 0; count < len; count++)
  47.    {
  48.        outb(DATA, string[count]);
  49.        outb(CONTROL,inb(CONTROL) | 0x01);
  50.        sleep(2);
  51.        outb(CONTROL,inb(CONTROL) & 0xFE);
  52.        sleep(2);
  53.    }
  54.  
  55. }


Compila perfectamente pero cuando lo quiero provar lo ejecuto como root y me arroja esto

Código
  1. root@ubuntu:/media/E80C-30D5/LCD/build# ./lcd
  2. Fallo de segmentación (`core' generado)
  3. root@ubuntu:/media/E80C-30D5/LCD/build#

Mirando el dmesg me encuentro con esto.

Código
  1. [ 3176.691837] lcd[3867] general protection ip:400cb4 sp:7fff887ad290 error:0 in lcd[400000+2000]
  2. root@ubuntu:/media/E80C-30D5/LCD/build#

Dejo el dmesg del ttyS*
Código
  1. root@ubuntu:/media/E80C-30D5/LCD/build# dmesg |grep ttyS
  2. [    2.335717] serial8250: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
  3. [    2.335817] serial8250: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A
  4. [    2.336100] 00:0b: ttyS1 at I/O 0x2f8 (irq = 3) is a 16550A
  5. [    2.336207] 00:0c: ttyS0 at I/O 0x3f8 (irq = 4) is a 16550A
  6. root@ubuntu:/media/E80C-30D5/LCD/build#





Título: Re: Inicializar LCD (Linux)
Publicado por: JCCC en 15 Julio 2010, 23:51 pm
el programa es interesante...
yo estoy en pañales en linux.... XD...
haber si alguien te ayuda, depaso me enseñan a controlar perifericos en LINUX
 :P


Título: Re: Inicializar LCD (Linux)
Publicado por: Mr.Blue en 15 Julio 2010, 23:58 pm
si pedis que te muevan el post a programacion c++,  por ahi lo ve mas gente.

Manda mp a algun mod o global para avisarle, con el link del post.