TODOPIC

Microcontroladores PIC => Lenguaje C para microcontroladores PIC => Mensaje iniciado por: Medusa en 01 de Junio de 2009, 20:49:24

Título: Pic18F4550-LCD4x20 no funciona??
Publicado por: Medusa en 01 de Junio de 2009, 20:49:24
Hola a todos,

Estoy haciendo un  modulo de visualizacion usando un LCD de 20x4 que es controlado por el Pic18f4550, aparentemente todo esta bien pero no funciona.

Este es mi codigo,  :? Que es lo que estoy haciendo mal :shock:

Código: [Seleccionar]
#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV2,VREGEN
#use delay(clock=48MHZ)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#define use_portb_lcd TRUE

#include <LCD420.C>

void main(void)
{
  lcd_init();
  delay_us(50);

   while (TRUE)
   {
     lcd_gotoxy(1,1);
     lcd_putc("Hola Mundo");
     delay_ms(500);
   }
}
Título: Re: Pic18F4550-LCD4x20 no funciona??
Publicado por: PalitroqueZ en 01 de Junio de 2009, 22:03:20
una pregunta: ¿te aseguraste que el portb trabaje como entrada y/o salida digital?

Título: Re: Pic18F4550-LCD4x20 no funciona??
Publicado por: Medusa en 02 de Junio de 2009, 10:21:40
Si, pero igual no funciona  :x :x

Código: [Seleccionar]
#include <18F4550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL5,CPUDIV2,VREGEN
#use delay(clock=48MHZ)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#use fast_io(b)
#define use_portb_lcd TRUE
#include <LCD420.C>

void main(void)
{
  set_tris_b(0x00);
  setup_adc_ports(NO_ANALOGS);
  lcd_init();
  delay_us(50);

   while (TRUE)
   {
    lcd_gotoxy(1,1);
  lcd_putc("Hola Mundo");
  delay_ms(500);
   }
}
Título: Re: Pic18F4550-LCD4x20 no funciona??
Publicado por: ASTROCAR en 02 de Junio de 2009, 10:57:51
Hola buenos dias puede mostrar el esquematico porque al parecer todo esta bien solo resta ver el esquematico que puede tener un problema de todas maneras seria bueno simularlo en proteus.

Saludos y esperamos tu esquematico para ver si damos con la falla.
Atten.
Alexander Santana.
Barcelona-Venezuela.
Título: Re: Pic18F4550-LCD4x20 no funciona??
Publicado por: Medusa en 02 de Junio de 2009, 12:08:25
Hola, aqui esta la simulacion en proteus y el codigo, espero que me puedas ayudar  :mrgreen:
Título: Re: Pic18F4550-LCD4x20 no funciona??
Publicado por: ASTROCAR en 08 de Junio de 2009, 08:14:25
Hola no pude ver la simulacion no me abre en mi version de proteus, pero basicamente cual es el problema en la simulacion si te corre y en la realidad no explicame un poco mejor cual es tu problema para ver si te ayudamos.

Saludos y estamos en contacto.
Atten.
Alexander Santana.
Barcelona-Venezuela.
Título: Re: Pic18F4550-LCD4x20 no funciona??
Publicado por: MLO__ en 08 de Junio de 2009, 11:30:15
Hola.

Pruebalo primero a 4MHz con un XT .... creo haber visto que la libreria de la LCD trae unos delay_cycles(); .... y a esa velocidad creo que no seria suficiente ...
Título: Re: Pic18F4550-LCD4x20 no funciona??
Publicado por: pink_brenda en 07 de Julio de 2009, 01:08:53
Hola, creo saber cual es el problema, a mi me sucedía igual al usar esa librería para el pic18f4550, la solución es especificar la dirección del puerto donde va a imprimir la LCD, ya que al parecer no lo trae especificado para este pic, esta es una modificación a la librería original lcd420, a la cual llamamos lcd4x20, espero que te sirva.


Código: [Seleccionar]
////////////////////////////////////////////////////////////////////////////
////                             LCD4X20.C                               ////
////            Driver for common 4x20 LCD modules                      ////
////                                                                    ////
////  lcd_init()   Must be called before any other function.            ////
////                                                                    ////
////  lcd_putc(c)  Will display c on the next position of the LCD.      ////
////                     The following have special meaning:            ////
////                      \f  Clear display                             ////
////                      \n  Go to start of second line                ////
////                      \b  Move back one position                    ////
////                                                                    ////
////  lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1)     ////
////                                                                    ////
////  lcd_getc(x,y)   Returns character at position x,y on LCD          ////
////                                                                    ////
////////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,1997 Custom Computer Services            ////
//// This source code may only be used by licensed users of the CCS C   ////
//// compiler.  This source code may only be distributed to other       ////
//// licensed users of the CCS C compiler.  No other use, reproduction  ////
//// or distribution is permitted without written permission.           ////
//// Derivative programs created using this software in object code     ////
//// form are not restricted in any way.                                ////
////////////////////////////////////////////////////////////////////////////

// As defined in the following structure the pin connection is as follows:
//     B0  enable
//     B1  rs
//     B2  rw
//     B4  D4
//     B5  D5
//     B6  D6
//     B7  D7
//
//   LCD pins D0-D3 are not used and PIC B3 is not used.
#define use_portb_lcd TRUE


struct lcd_pin_map {                 // This structure is overlayed
           BOOLEAN enable;           // on to an I/O port to gain
           BOOLEAN rs;               // access to the LCD pins.
           BOOLEAN rw;               // The bits are allocated from
           BOOLEAN unused;           // low order up.  ENABLE will
           int     data : 4;         // be pin B0.
        } lcd;


#if defined use_portb_lcd
   //#locate lcd = getenv("sfr:PORTB")    // This puts the entire structure over the port
   #ifdef __pch__
    #locate lcd = 0xf81
   #else
    #locate lcd = 6
   #endif
   #define set_tris_lcd(x) set_tris_b(x)
#else
   //#locate lcd = getenv("sfr:PORTD")    // This puts the entire structure over the port
   #ifdef __pch__
    #locate lcd = 0xf83
   #else
    #locate lcd = 8
   #endif
   #define set_tris_lcd(x) set_tris_d(x)
#endif

#ifndef lcd_type
#define lcd_type 2           // 0=5x7, 1=5x10, 2=2 lines
#endif

#define lcd_line_two 0x40    // LCD RAM address for the second line

/*struct lcd_pin_map {                 // This structure is overlayed
           BOOLEAN enable;           // on to an I/O port to gain
           BOOLEAN rs;               // access to the LCD pins.
           BOOLEAN rw;               // The bits are allocated from
           BOOLEAN unused;           // low order up.  ENABLE will
           int     data : 4;         // be pin B0.
        } lcd;

#byte lcd = 6                        // This puts the entire structure
                                     // on to port B (at address 6)

#define lcd_type 2           // 0=5x7, 1=5x10, 2=2 lines*/


BYTE const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6};
                             // These bytes need to be sent to the LCD
                             // to start it up.


                             // The following are used for setting
                             // the I/O port direction register.

struct lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // For write mode all pins are out
struct lcd_pin_map const LCD_READ = {0,0,0,0,15}; // For read mode data pins are in


BYTE lcdline;

BYTE lcd_read_byte() {
      BYTE low,high;

      set_tris_b(LCD_READ);
      lcd.rw = 1;
      delay_cycles(1);
      lcd.enable = 1;
      delay_cycles(1);
      high = lcd.data;
      lcd.enable = 0;
      delay_cycles(1);
      lcd.enable = 1;
      delay_us(1);
      low = lcd.data;
      lcd.enable = 0;
      set_tris_b(LCD_WRITE);
      return( (high<<4) | low);
}


void lcd_send_nibble( BYTE n ) {
      lcd.data = n;
      delay_cycles(1);
      lcd.enable = 1;
      delay_us(2);
      lcd.enable = 0;
}


void lcd_send_byte( BYTE address, BYTE n ) {

      lcd.rs = 0;
      while ( bit_test(lcd_read_byte(),7) ) ;
      lcd.rs = address;
      delay_cycles(1);
      lcd.rw = 0;
      delay_cycles(1);
      lcd.enable = 0;
      lcd_send_nibble(n >> 4);
      lcd_send_nibble(n & 0xf);
}


void lcd_init() {
    BYTE i;

    set_tris_b(LCD_WRITE);
    lcd.rs = 0;
    lcd.rw = 0;
    lcd.enable = 0;
    delay_ms(15);
    for(i=1;i<=3;++i) {
       lcd_send_nibble(3);
       delay_ms(5);
    }
    lcd_send_nibble(2);
    for(i=0;i<=3;++i)
       lcd_send_byte(0, LCD_INIT_STRING[i]);
}


void lcd_gotoxy( BYTE x, BYTE y) {
   BYTE address;

   switch(y) {
     case 1 : address=0x80;break;
     case 2 : address=0xc0;break;
     case 3 : address=0x94;break;
     case 4 : address=0xd4;break;
   }
   address+=x-1;
   lcd_send_byte(0,address);
}

void lcd_putc( char c) {
   switch (c) {
     case '\f'   : lcd_send_byte(0,1);
                   lcdline=1;
                   delay_ms(2);
                                           break;
     case '\n'   : lcd_gotoxy(1,++lcdline);        break;
     case '\b'   : lcd_send_byte(0,0x10);  break;
     default     : lcd_send_byte(1,c);     break;
   }
}

char lcd_getc( BYTE x, BYTE y) {
   char value;

    lcd_gotoxy(x,y);
    lcd.rs=1;
    value = lcd_read_byte();
    lcd.rs=0;
    return(value);
}
//Modificado por Danial Rodríguez
Título: Re: Pic18F4550-LCD4x20 no funciona??
Publicado por: canival35 en 31 de Agosto de 2009, 01:19:58
Hola, creo saber cual es el problema, a mi me sucedía igual al usar esa librería para el pic18f4550, la solución es especificar la dirección del puerto donde va a imprimir la LCD, ya que al parecer no lo trae especificado para este pic, esta es una modificación a la librería original lcd420, a la cual llamamos lcd4x20, espero que te sirva.


Hola pink_brenda muchas gracias por el aporte te sacaste un 10 maestra, eres grande  :-/ :D
Título: Re: Pic18F4550-LCD4x20 no funciona??
Publicado por: alluzin en 27 de Octubre de 2011, 13:56:25
Hola a mi tambien  me han  surgido problemas con el display LCD 4X20 y el 18F4550, por que  yo quiero manejar el LCD con el puerto D, ya que el puerto B lo tengo  en uso total para interrupciones y otras entradas importantes para mi proyecto. y mi duda es que si es posible  cambiar  el codigo  LCD420.C para q trabaje con el puerto D. Muchas gracias
Título: Re: Pic18F4550-LCD4x20 no funciona??
Publicado por: jasotronik en 13 de Noviembre de 2011, 18:47:35
hola amigos soy nuevo en el foro yo también quiero saber si se puede poner la lcd4x20 en el puerto D modificando el driver
Título: Re: Pic18F4550-LCD4x20 no funciona??
Publicado por: jasotronik en 14 de Noviembre de 2011, 22:37:37
listo compañeros aquí esta el driver para la lcd4x20 por el puerto d

creen un .c nuevo o lo pegan sobre el lcd420.c

ya lo verifique y funciona correctamente


////////////////////////////////////////////////////////////////////////////
////                             LCD420.C                               ////
////            Driver for common 4x20 LCD modules                      ////
////                                                                    ////
////  lcd_init()   Must be called before any other function.            ////
////                                                                    ////
////  lcd_putc(c)  Will display c on the next position of the LCD.      ////
////                     The following have special meaning:            ////
////                      \f  Clear display                             ////
////                      \n  Go to start of second line                ////
////                      \b  Move back one position                    ////
////                                                                    ////
////  lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1)     ////
////                                                                    ////
////  lcd_getc(x,y)   Returns character at position x,y on LCD          ////
////                                                                    ////
////////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,1997 Custom Computer Services            ////
//// This source code may only be used by licensed users of the CCS C   ////
//// compiler.  This source code may only be distributed to other       ////
//// licensed users of the CCS C compiler.  No other use, reproduction  ////
//// or distribution is permitted without written permission.           ////
//// Derivative programs created using this software in object code     ////
//// form are not restricted in any way.                                ////
////////////////////////////////////////////////////////////////////////////

// As defined in the following structure the pin connection is as follows:
//     B0  enable
//     B1  rs
//     B2  rw
//     B4  D4
//     B5  D5
//     B6  D6
//     B7  D7
//
//   LCD pins D0-D3 are not used and PIC B3 is not used.

struct lcd_pin_map {                 // This structure is overlayed
           BOOLEAN enable;           // on to an I/O port to gain
           BOOLEAN rs;               // access to the LCD pins.
           BOOLEAN rw;               // The bits are allocated from
           BOOLEAN unused;           // low order up.  ENABLE will
           int     data : 4;         // be pin B0.
        } lcd;
     
       
       

//#define use_portd_lcd TRUE

#locate lcd = getenv("SFR:PORTd")                        // This puts the entire structure
                                     // on to port B

#define lcd_type 2           // 0=5x7, 1=5x10, 2=2 lines


BYTE const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6};
                             // These bytes need to be sent to the LCD
                             // to start it up.


                             // The following are used for setting
                             // the I/O port direction register.

struct lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // For write mode all pins are out
struct lcd_pin_map const LCD_READ = {0,0,0,0,15}; // For read mode data pins are in


BYTE lcdline;

BYTE lcd_read_byte() {
      BYTE low,high;

      set_tris_d(LCD_READ);
      lcd.rw = 1;
      delay_cycles(1);
      lcd.enable = 1;
      delay_cycles(1);
      high = lcd.data;
      lcd.enable = 0;
      delay_cycles(1);
      lcd.enable = 1;
      delay_us(1);
      low = lcd.data;
      lcd.enable = 0;
      set_tris_d(LCD_WRITE);
      return( (high<<4) | low);
}


void lcd_send_nibble( BYTE n ) {
      lcd.data = n;
      delay_cycles(1);
      lcd.enable = 1;
      delay_us(2);
      lcd.enable = 0;
}


void lcd_send_byte( BYTE address, BYTE n ) {

      lcd.rs = 0;
      while ( bit_test(lcd_read_byte(),7) ) ;
      lcd.rs = address;
      delay_cycles(1);
      lcd.rw = 0;
      delay_cycles(1);
      lcd.enable = 0;
      lcd_send_nibble(n >> 4);
      lcd_send_nibble(n & 0xf);
}


void lcd_init() {
    BYTE i;

    set_tris_d(LCD_WRITE);
    lcd.rs = 0;
    lcd.rw = 0;
    lcd.enable = 0;
    delay_ms(15);
    for(i=1;i<=3;++i) {
       lcd_send_nibble(3);
       delay_ms(5);
    }
    lcd_send_nibble(2);
    for(i=0;i<=3;++i)
       lcd_send_byte(0, LCD_INIT_STRING);
}


void lcd_gotoxy( BYTE x, BYTE y) {
   BYTE address;

   switch(y) {
     case 1 : address=0x80;break;
     case 2 : address=0xc0;break;
     case 3 : address=0x94;break;
     case 4 : address=0xd4;break;
   }
   address+=x-1;
   lcd_send_byte(0,address);
}

void lcd_putc( char c) {
   switch (c) {
     case '\f'   : lcd_send_byte(0,1);
                   lcdline=1;
                   delay_ms(2);
                                           break;
     case '\n'   : lcd_gotoxy(1,++lcdline);        break;
     case '\b'   : lcd_send_byte(0,0x10);  break;
     default     : lcd_send_byte(1,c);     break;
   }
}

char lcd_getc( BYTE x, BYTE y) {
   char value;

    lcd_gotoxy(x,y);
    lcd.rs=1;
    value = lcd_read_byte();
    lcd.rs=0;
    return(value);
}
Título: Re:Pic18F4550-LCD4x20 no funciona??
Publicado por: Nipoanz en 21 de Diciembre de 2017, 00:01:47
Hola, estoy usando  el mismo pic, pero una lcd 16x2 con comunicación I2C, ya que voy a utilizar los demás puertos, estoy programando en mikroC ya que posee más herramientas, estoy usando una libreria de la comunidad que he encontrado por internet, cuando realizo la simulación todo funciona perfectamente, pero cuando lo monto en físico, no me aparece nada, ni un led intermitente para ver que el programa esta corriendo. estaria agradecido por la ayuda.
Adjunto el programa y la simulacion en proteus
Muchas gracias.