Microcontroladores PIC en Linux.
¿Quieres reaccionar a este mensaje? Regístrate en el foro con unos pocos clics o inicia sesión para continuar.

Ayuda con LCD LMG-162-STN

4 participantes

Ir abajo

Ayuda con LCD LMG-162-STN Empty Ayuda con LCD LMG-162-STN

Mensaje por Luffy-X- Miér 5 Oct 2011 - 17:42

Bueno pues me tienen aqui de nuevo Very Happy

Pues apenas me compre este display para poderlo manejar con
mi PIC18F4550 pero la verdad es que he buscado información de como
manejarlos, pero como que ya me revolvi mas Razz y espero que ustedes me
puedan sacar de mis dudas.

Lo que pasa es que no se si se le deba de meter un programa al display
para poderlo manejar con mi pic( lo que pasa es que he visto
diferentes códigos para lcd's, como un codigo especial aparte del que se le mete al pic para que despliegue la informacion) y pues el maestro solo nos
proporciono el archivo .HEX que se le mete a nuestro pic y la verdad
es que no puedo ver el código y todo eso para darme una idea(y pues
el maestro no nos explica mucho Sad ), alomejor y lo que esta mal es el codigo, ya que un amigo lo simulo en proteus y tampoco.

eh aqui una foto de mi display Surprised

Ayuda con LCD LMG-162-STN P1010134b

Y ahora otra duda cuando compre mi display me dieron la hoja de
especificaciones del lcd pero lo conecte todo bien y nada mas no, y
uno de mis compañeros compro la misma que yo pero a el le dieron
otra hoja de especificaciones, asi que mejor empece a buscar la hoja
adecuada pero no la encuentro, y lo que pasa es que en las hojas que
nos proporcionaron al comprar la lcd pues dice la matricula de
nuestra lcd que es LMG-162-STN, les pongo una foto de las dos hojas
que tengo(perdon por la imagen pero le sacamos copia y le saque foto XD, espero que se distinga):

Ayuda con LCD LMG-162-STN P1010135o
No se si alguien ya halla manejado este display y cual fue la
configuracion de las terminales para poder desplegar la informacion.

Les dejo como según debo de conectar mi pic al display(a lo mejor la imagen que nos proporciono
el maestro esta mal o falta algo)


Ayuda con LCD LMG-162-STN Conectarlcd


Les dejo toda la carpeta que nos proporciono el maestro.
http://www.megaupload.com/?d=0K8A33VJ

Espero que me pueda ayudar y si tienen alguna informacion sobre programar lcd's( de preferencia la que yo tengo y con el pic que manejo) se los agradeceria mucho Smile
Luffy-X-
Luffy-X-
Participante
Participante

Mensajes : 24
Fecha de inscripción : 09/09/2011
Edad : 33
Localización : Mexico

Volver arriba Ir abajo

Ayuda con LCD LMG-162-STN Empty Re: Ayuda con LCD LMG-162-STN

Mensaje por Pikitin Vie 7 Oct 2011 - 23:34

Ese LCD parece compatible con Hitachi 44780, tienes que buscar librerías para manejarlo, por ejemplo para programar con SDCC y pic18f, puedes probar esta:
http://www.warpedlogic.co.uk/node/10

Para programar en GcBasic ya trae librería, lo mismo con Jalv2.

En asm seguramente habrá librerías por la web.

Para saber cómo funciona bájate la hoja de datos del 44780 o busca info por la red, hay mucha.


Saludos.

Pikitin
veterano
veterano

Mensajes : 623
Fecha de inscripción : 26/11/2008

http://linuxmicros.blogspot.com/

Volver arriba Ir abajo

Ayuda con LCD LMG-162-STN Empty Re: Ayuda con LCD LMG-162-STN

Mensaje por Luffy-X- Miér 12 Oct 2011 - 17:53

Solo unas preguntas...

Pero que quiere decir eso de compatible con hitachi?

Y ademas trate de conectarlo pero no me da nada, ademas que tengo miedo ya que algunos de mis compañeros al tratar de armar un circuito quemaron su pic, asi que yo tampoco quiero cometer el mismo error(ellos sacaron el voltaje directo de su pic al igual que yo lo ando haciendo) y he probado varios programas para tratar de hacer funcionar mi lcd pero nada mas no logro encenderla con pic.

Y corriganme si estoy mal, pero la libreria solo es para añadirla al codigo y de ahi poder programar el pic, para que asi al conectarla a la LCD pueda aparecer para lo que se programo, no?

Alguna sugerencia para poder prender mi LCD con mi pic sin tenerlo que quemar?
Luffy-X-
Luffy-X-
Participante
Participante

Mensajes : 24
Fecha de inscripción : 09/09/2011
Edad : 33
Localización : Mexico

Volver arriba Ir abajo

Ayuda con LCD LMG-162-STN Empty Re: Ayuda con LCD LMG-162-STN

Mensaje por Pikitin Miér 12 Oct 2011 - 20:54

Pero que quiere decir eso de compatible con hitachi?
La mayoría de LCDs de ese tipo utilizan un controlador Hitachi 44780 o compatible, eso quiere decir que tienen los mismos pines y los mismos comandos, osea.. que funcionan igual.

El tuyo tiene los mismos pines y seguramente sea compatible, entonces seguramente puedes usar las librerías que ya están escritas para ese controlador.

Y corriganme si estoy mal, pero la libreria solo es para añadirla al
codigo y de ahi poder programar el pic, para que asi al conectarla a la
LCD pueda aparecer para lo que se programo, no?

Una librería no es más que una parte del programa que se guarda en otro archivo para poder ser reuitilizada.
Por ejemplo, suponte que en todos tus proyectos quieres utilizar una rutina que encienda y apague un led 3 veces (por decir algo)... la rutina podría ser esta (en basic):

Código:
Sub parpadea3
    for count = 1 to 3
        LED = 1
        wait 500 ms
        LED = 0
        wait 500 ms
    Next
End Sub

Podrías escribir esta rutina en cada uno de tus programas, pero ya que lo vas a usar muchas veces pues la puedes guardar en un archivo aparte, por ejemplo "led.h", y cada vez que la necesites pues la incluyes en tu programa, por ejemplo un programa que parpadea un led 3 veces cada vez que se pulsa un botón conectado a PORTA.1:

Código:
#include "led.h"

#define LED    PORTB.1
#define Boton  PORTA.1

Do
    if Boton = 1 then parapadea3
Loop

Si a ese archivo led.h le añades otras rutinas para hacer cosas con leds, entonces tienes una librería: una colección de rutinas que vas a reutilizar en varios programas y que otras personas puedes utilizar en los suyos.

Las librerías estás escritas en un lenguaje de programación, así que sólo se pueden usar en programas escritos en ese lenguaje, en nuestro ejemplo led.h está escrita en GcBasic y sólo se puede usar en programas escritos para ese compilador, así que no va a funcionar en SDDC o asm.

Una librería para LCD tiene funciones para manejar el LCD facilmente, sin tener que escribir todos los comandos que necesita el LCD.

Para usar tu LCD tendrás que escribir un programa, en un lenguaje, entonces tienes que buscarte una librería en ese lenguaje, ver que funciones tiene y cómo se utilizan, incluir la librería en tu programa y usar las funciones que necesites.

Para que veas cómo funciona el tema míra este tema:
https://pic-linux.forosactivos.net/t321-libreria-lcd-4bit-para-pic16f
Es una librería LCD para usar con el compilador SDCC, para Pic16f, así que quizás to te valga para pic18f, pero igual si que funciona.

Par no quemar el PIC lo mejor que puedes hacer es saber lo que estás haciendo, mucho cuidado con las polaridades ( + - ), no conectar salida con salida: en caso del lcd podrías ponerle resistencias de 1k en las lineas de datos, ya que estas pueden funcionar como entradas o salidas. Pero normalmente las cosas se queman por conexiones erroneas.

Lo principal es saber cómo funciona lo que tienes entre manos y comprobar varias veces las conexiones, cuando estés seguro de que todo está bien entonces lo vuelves a comprobar y aún así habrá fallos que no veas y alguna vez quemarás algo.

Suerte.

Pikitin
veterano
veterano

Mensajes : 623
Fecha de inscripción : 26/11/2008

http://linuxmicros.blogspot.com/

Volver arriba Ir abajo

Ayuda con LCD LMG-162-STN Empty Re: Ayuda con LCD LMG-162-STN

Mensaje por Luffy-X- Jue 13 Oct 2011 - 17:19

Pues con esa Libreria se ve facil programar el lcd, buscare uno para mi pic Very Happy

Otra pregunta, mi pic trae un cristal de 20MHz, para que sirve ese cristal y por lo tanto quiere decir que tambien puede funcionar para menores frecuencias que los 20Mhz o afuerzas se le deben de meter los 20Mhz para poder funcionar?

O tambien sera que todos los dispositivos que tengo alrededor de mi pic estan afectanfo para prender mi LCD?

Ayuda con LCD LMG-162-STN P1010020lc
Luffy-X-
Luffy-X-
Participante
Participante

Mensajes : 24
Fecha de inscripción : 09/09/2011
Edad : 33
Localización : Mexico

Volver arriba Ir abajo

Ayuda con LCD LMG-162-STN Empty Re: Ayuda con LCD LMG-162-STN

Mensaje por Luffy-X- Sáb 22 Oct 2011 - 18:34

Bueno pues en mi busqueda estuve checando codigos y pues con ninguno he logrado encender mi LCD

Encontre un codigo que es para encender la lcd con bootloader, ya que
asi ando programando mi PIC18F4550 y alomejor ese puede que sea el
problema, pero a la hora de tratarlo de compilar pues no me deja Sad y me marca errores.

En esta me marca error de device no se que quiera decir y por que me lo
marca(asi que estaba haciendo pruebas para ver si se quitaba ese error
poniendo el device asi solo)xD


Ayuda con LCD LMG-162-STN Lcderror


Despues coloque el #device PIC18F4550 y me salieron estos errores de las bibliotecas Shocked Shocked

Ayuda con LCD LMG-162-STN Lcderror2

Si alguien me pudiera ayudar a compilar este codigo para ver si asi puede encender mi LCD Sad Sad

Les dejo aqui el codigo...
Código:

/*  SOURCE : WWW.ROMUX.COM
    AUTHOR : romux team    */
   
   
#include < p18F4550.h>
#include < delays.h>                      ;Delay Header file
#include "bootlcd.h"                        ;Lcd Header file

void low_isr(void);
void high_isr(void);

#pragma code low_vector=0x2018
void interrupt_at_low_vector(void)
{
  _asm GOTO low_isr _endasm
}
#pragma code

#pragma code high_vector=0x2008
void interrupt_at_high_vector(void)
{
  _asm GOTO high_isr _endasm
}
#pragma code

#pragma interruptlow low_isr
void low_isr (void)
{
 
 return;
}

#pragma interrupt high_isr
void high_isr (void)
{
 return;
}


void DelayFor18TCY( void )
{
 Delay10TCYx(2);        // 5us delay
 return;
}
void DelayPORXLCD (void)
{
  Delay1KTCYx(75); // Delay of 15ms
                  // Cycles = (TimeDelay * Fosc) / 4
                  // Cycles = (15ms * 20MHz) / 4
                  // Cycles = 75,000
  return;
}
void DelayXLCD (void)
{
  Delay1KTCYx(25); // Delay of 5ms
                  // Cycles = (TimeDelay * Fosc) / 4
                  // Cycles = (5ms * 20MHz) / 4
                  // Cycles = 25,000
  return;
}
void main( void )
{
 
  OpenXLCD();    // configure external LCD

  putrsXLCD("Hello world !");

  while(1)
  {
    ;
  }

}

Y aqui la biblioteca

Código:

/*source : www.romux.com  */
#ifndef __bootlcd_H
#define __bootlcd_H
#include "p18cxxx.h"

/* PIC18 BOOTLCD peripheral routines.
 *
 *  Notes:
 *      - These libraries routines are written to support the
 *        Hitachi HD44780 LCD controller.
 *      - The user must define the following items:
 *          - The LCD interface type (4- or 8-bits)
 *          - If 4-bit mode
 *              - whether using the upper or lower nibble
 *          - The data port
 *              - The tris register for data port
 *              - The control signal ports and pins
 *              - The control signal port tris and pins
 *          - The user must provide three delay routines:
 *              - DelayFor18TCY() provides a 18 Tcy delay
 *              - DelayPORXLCD() provides at least 15ms delay
 *              - DelayXLCD() provides at least 5ms delay
 */

/* Interface type 8-bit or 4-bit
 * For 8-bit operation uncomment the #define BIT8
 */
/* #define BIT8 */

/* When in 4-bit interface define if the data is in the upper
 * or lower nibble.  For lower nibble, comment the #define UPPER
 */
 #define UPPER 1

/* DATA_PORT defines the port to which the LCD data lines are connected */
 #define DATA_PORT              PORTD
 #define TRIS_DATA_PORT        TRISD

/* CTRL_PORT defines the port where the control lines are connected.
 * These are just samples, change to match your application.
 */
 #define RW_PIN  LATCbits.LATC1          /* PORT for RW */
 #define TRIS_RW  TRISCbits.TRISC1        /* TRIS for RW */

 #define RS_PIN  LATCbits.LATC0          /* PORT for RS */
 #define TRIS_RS  TRISCbits.TRISC0        /* TRIS for RS */

 #define E_PIN    LATCbits.LATC2          /* PORT for D  */
 #define TRIS_E  TRISCbits.TRISC2        /* TRIS for E  */

/* Display ON/OFF Control defines */
#define DON        0b00001111  /* Display on      */
#define DOFF        0b00001011  /* Display off    */
#define CURSOR_ON  0b00001111  /* Cursor on      */
#define CURSOR_OFF  0b00001101  /* Cursor off      */
#define BLINK_ON    0b00001111  /* Cursor Blink    */
#define BLINK_OFF  0b00001110  /* Cursor No Blink */

/* Cursor or Display Shift defines */
#define SHIFT_CUR_LEFT    0b00000100  /* Cursor shifts to the left  */
#define SHIFT_CUR_RIGHT  0b00000101  /* Cursor shifts to the right  */
#define SHIFT_DISP_LEFT  0b00000110  /* Display shifts to the left  */
#define SHIFT_DISP_RIGHT  0b00000111  /* Display shifts to the right */

/* Function Set defines */
#define FOUR_BIT  0b00101100  /* 4-bit Interface              */
#define EIGHT_BIT  0b00111100  /* 8-bit Interface              */
#define LINE_5X7  0b00110000  /* 5x7 characters, single line  */
#define LINE_5X10  0b00110100  /* 5x10 characters              */
#define LINES_5X7  0b00111000  /* 5x7 characters, multiple line */

void OpenXLCD(void);
void SetCGRamAddr(PARAM_SCLASS unsigned char);
void SetDDRamAddr(PARAM_SCLASS unsigned char);
unsigned char BusyXLCD(void);
unsigned char ReadAddrXLCD(void);
char ReadDataXLCD(void);
void WriteCmdXLCD(PARAM_SCLASS unsigned char);
void WriteCmd8bit(PARAM_SCLASS unsigned char);
void WriteDataXLCD(PARAM_SCLASS char);
#define putcXLCD WriteDataXLCD
void putsXLCD(PARAM_SCLASS char *);
void putrsXLCD(const rom char *);

extern void DelayFor18TCY(void);
extern void DelayPORXLCD(void);
extern void DelayXLCD(void);


/* OpenXLCD
 * Configures I/O pins for external LCD
 */
/********************************************************************
*      Function Name:  OpenXLCD                                    *
*      Return Value:  void                                        *
*      Description:    This routine configures the LCD. Based on  *
*                      the Hitachi HD44780 LCD controller. The    *
*                      routine will configure the I/O pins of the  *
*                      microcontroller, setup the LCD for 4- or    *
*                      8-bit mode and clear the display. The user  *
*                      must provide three delay routines:          *
*                      DelayFor18TCY() provides a 18 Tcy delay    *
*                      DelayPORXLCD() provides at least 15ms delay *
*                      DelayXLCD() provides at least 5ms delay    *
********************************************************************/
void OpenXLCD()
{
        // The data bits must be either a 8-bit port or the upper or
        // lower 4-bits of a port. These pins are made into inputs
                          // Upper 4-bits of the port
        DATA_PORT &= 0x0f;
        TRIS_DATA_PORT &= 0x0F;

        TRIS_RW = 0;                    // All control signals made outputs
        TRIS_RS = 0;
        TRIS_E = 0;
        RW_PIN = 0;                    // R/W pin made low
        RS_PIN = 0;                    // Register select pin made low
        E_PIN = 0;                      // Clock pin made low

        // Delay for 15ms to allow for LCD Power on reset
        Delay1KTCYx(75); // Delay of 15ms
 //-------------------reset procedure through software----------------------     
        WriteCmdXLCD(0x30);
            Delay10KTCYx(0x05);

        WriteCmdXLCD(0x30);
            Delay10KTCYx(0x01);


        WriteCmdXLCD(0x32);
        while( BusyXLCD() );
//------------------------------------------------------------------------------------------


        // Set data interface width, # lines, font
        while(BusyXLCD());              // Wait if LCD busy
        WriteCmd8bit(FOUR_BIT & LINES_5X7);          // Function set cmd
        while(BusyXLCD());
        //WriteCmdXLCD(LINES_5X7);
        // Turn the display on then off
        Delay10KTCYx(0x05);              // Wait if LCD busy
        WriteCmdXLCD(DOFF&CURSOR_OFF&BLINK_OFF);        // Display OFF/Blink OFF
        while(BusyXLCD());              // Wait if LCD busy
        WriteCmdXLCD(DON&CURSOR_OFF&BLINK_OFF);          // Display ON/Blink ON

        // Clear display
        while(BusyXLCD());              // Wait if LCD busy
        WriteCmdXLCD(0x01);            // Clear display

        // Set entry mode inc, no shift
        while(BusyXLCD());              // Wait if LCD busy
        WriteCmdXLCD(SHIFT_DISP_LEFT);  // Entry Mode

        // Set DD Ram address to 0
        while(BusyXLCD());              // Wait if LCD busy
        SetDDRamAddr(0x80);                // Set Display data ram address to 0

        return;
}

/* SetCGRamAddr
 * Sets the character generator address
 */
/********************************************************************
*      Function Name:  SetCGRamAddr                                *
*      Return Value:  void                                        *
*      Parameters:    CGaddr: character generator ram address    *
*      Description:    This routine sets the character generator  *
*                      address of the Hitachi HD44780 LCD          *
*                      controller. The user must check to see if  *
*                      the LCD controller is busy before calling  *
*                      this routine.                              *
********************************************************************/
void SetCGRamAddr(unsigned char CGaddr)
{
                                  // Upper nibble interface
        TRIS_DATA_PORT &= 0x0f;                // Make nibble input
        DATA_PORT &= 0x0f;                      // and write upper nibble
        DATA_PORT |= ((CGaddr | 0b01000000) & 0xf0);

        RW_PIN = 0;                            // Set control signals
        RS_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                              // Clock cmd and address in
        DelayFor18TCY();
        E_PIN = 0;

        DATA_PORT &= 0x0f;                      // Write lower nibble
        DATA_PORT |= ((CGaddr<<4)&0xf0);

        DelayFor18TCY();
        E_PIN = 1;                              // Clock cmd and address in
        DelayFor18TCY();
        E_PIN = 0;
                                       
        TRIS_DATA_PORT |= 0xf0;                // Make inputs

        return;
}

/* SetDDRamAddr
 * Sets the display data address
 */
/********************************************************************
*      Function Name:  SetDDRamAddr                                *
*      Return Value:  void                                        *
*      Parameters:    CGaddr: display data address                *
*      Description:    This routine sets the display data address  *
*                      of the Hitachi HD44780 LCD controller. The  *
*                      user must check to see if the LCD controller*
*                      is busy before calling this routine.        *
********************************************************************/
void SetDDRamAddr(unsigned char DDaddr)
{
                                        // 4-bit interface
                                  // Upper nibble  interface
        TRIS_DATA_PORT &= 0x0f;                // Make port output
        DATA_PORT &= 0x0f;                      // and write upper nibble
        DATA_PORT |= ((DDaddr | 0b10000000) & 0xf0);

        RW_PIN = 0;                            // Set control bits
        RS_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                              // Clock the cmd and address in
        DelayFor18TCY();
        E_PIN = 0;
                                // Upper nibble interface
        DATA_PORT &= 0x0f;                      // Write lower nibble
        DATA_PORT |= ((DDaddr<<4)&0xf0);

        DelayFor18TCY();
        E_PIN = 1;                              // Clock the cmd and address in
        DelayFor18TCY();
        E_PIN = 0;
                                // Upper nibble interface
        TRIS_DATA_PORT |= 0xf0;                // Make port input

        return;
}

/* BusyXLCD
 * Returns the busy status of the LCD
 */
/********************************************************************
*      Function Name:  BusyXLCD                                    *
*      Return Value:  char: busy status of LCD controller        *
*      Parameters:    void                                        *
*      Description:    This routine reads the busy status of the  *
*                      Hitachi HD44780 LCD controller.            *
********************************************************************/
unsigned char BusyXLCD(void)
{
        RW_PIN = 1;                    // Set the control bits for read
        RS_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock in the command
        DelayFor18TCY();
                          // Upper nibble interface
        if(DATA_PORT&0x80)

        {
                E_PIN = 0;              // Reset clock line
                DelayFor18TCY();
                E_PIN = 1;              // Clock out other nibble
                DelayFor18TCY();
                E_PIN = 0;
                RW_PIN = 0;            // Reset control line
                return 1;              // Return TRUE
        }
        else                            // Busy bit is low
        {
                E_PIN = 0;              // Reset clock line
                DelayFor18TCY();
                E_PIN = 1;              // Clock out other nibble
                DelayFor18TCY();
                E_PIN = 0;
                RW_PIN = 0;            // Reset control line
                return 0;              // Return FALSE
        }

}

/* ReadAddrXLCD
 * Reads the current address
 */

/*********************************************************************
*      Function Name:  ReadAddrXLCD                                *
*      Return Value:  char: address from LCD controller            *
*      Parameters:    void                                        *
*      Description:    This routine reads an address byte from the  *
*                      Hitachi HD44780 LCD controller. The user    *
*                      must check to see if the LCD controller is  *
*                      busy before calling this routine. The address*
*                      is read from the character generator RAM or  *
*                      the display data RAM depending on what the  *
*                      previous SetxxRamAddr routine was called.    *
*********************************************************************/
unsigned char ReadAddrXLCD(void)
{
        char data;                      // Holds the data retrieved from the LCD

                                // 4-bit interface
        RW_PIN = 1;                    // Set control bits for the read
        RS_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock data out of the LCD controller
        DelayFor18TCY();
                          // Upper nibble interface
        data = DATA_PORT&0xf0;          // Read the nibble into the upper nibble of data

        E_PIN = 0;                      // Reset the clock
        DelayFor18TCY();
        E_PIN = 1;                      // Clock out the lower nibble
        DelayFor18TCY();
                          // Upper nibble interface
        data |= (DATA_PORT>>4)&0x0f;    // Read the nibble into the lower nibble of data

        E_PIN = 0;
        RW_PIN = 0;                    // Reset the control lines

        return (data&0x7f);            // Return the address, Mask off the busy bit
}


/* ReadDataXLCD
 * Reads a byte of data
 */
/********************************************************************
*      Function Name:  ReadDataXLCD                                *
*      Return Value:  char: data byte from LCD controller        *
*      Parameters:    void                                        *
*      Description:    This routine reads a data byte from the    *
*                      Hitachi HD44780 LCD controller. The user    *
*                      must check to see if the LCD controller is  *
*                      busy before calling this routine. The data  *
*                      is read from the character generator RAM or *
*                      the display data RAM depending on what the  *
*                      previous SetxxRamAddr routine was called.  *
********************************************************************/
char ReadDataXLCD(void)
{
        char data;

                                  // 4-bit interface
        RW_PIN = 1;
        RS_PIN = 1;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock the data out of the LCD
        DelayFor18TCY();
                          // Upper nibble interface
        data = DATA_PORT&0xf0;          // Read the upper nibble of data

        E_PIN = 0;                      // Reset the clock line
        DelayFor18TCY();
        E_PIN = 1;                      // Clock the next nibble out of the LCD
        DelayFor18TCY();
                          // Upper nibble interface
        data |= (DATA_PORT>>4)&0x0f;    // Read the lower nibble of data

        E_PIN = 0;                                     
        RS_PIN = 0;                    // Reset the control bits
        RW_PIN = 0;

        return(data);                  // Return the data byte
}


/* WriteCmdXLCD
 * Writes a command to the LCD
 */
/********************************************************************
*      Function Name:  WriteCmdXLCD                                *
*      Return Value:  void                                        *
*      Parameters:    cmd: command to send to LCD                *
*      Description:    This routine writes a command to the Hitachi*
*                      HD44780 LCD controller. The user must check *
*                      to see if the LCD controller is busy before *
*                      calling this routine.                      *
********************************************************************/
void WriteCmdXLCD(unsigned char cmd)
{
                                // 4-bit interface
                          // Upper nibble interface
        TRIS_DATA_PORT &= 0x0f;
        DATA_PORT &= 0x0f;
        DATA_PORT |= cmd&0xf0;

        RW_PIN = 0;                    // Set control signals for command
        RS_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock command in
        DelayFor18TCY();
        E_PIN = 0;
                          // Upper nibble interface
        DATA_PORT &= 0x0f;
        DATA_PORT |= (cmd<<4)&0xf0;

        DelayFor18TCY();
        E_PIN = 1;                      // Clock command in
        DelayFor18TCY();
        E_PIN = 0;
                        // Make data nibble input
        TRIS_DATA_PORT |= 0xf0;

        return;
}

void WriteCmd8bit(unsigned char cmd)
{
                                // 4-bit interface
                          // Upper nibble interface
        TRIS_DATA_PORT &= 0x0f;
        DATA_PORT &= 0x0f;
        DATA_PORT |= cmd&0xf0;

        RW_PIN = 0;                    // Set control signals for command
        RS_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock command in
        DelayFor18TCY();
        E_PIN = 0;

        TRIS_DATA_PORT |= 0xf0;

        return;
}

/* WriteDataXLCD
 * Writes a data byte to the LCD
 */
/********************************************************************
*      Function Name:  WriteDataXLCD                              *
*      Return Value:  void                                        *
*      Parameters:    data: data byte to be written to LCD        *
*      Description:    This routine writes a data byte to the      *
*                      Hitachi HD44780 LCD controller. The user    *
*                      must check to see if the LCD controller is  *
*                      busy before calling this routine. The data  *
*                      is written to the character generator RAM or*
*                      the display data RAM depending on what the  *
*                      previous SetxxRamAddr routine was called.  *
********************************************************************/
void WriteDataXLCD(char data)
{
                          // Upper nibble interface
        TRIS_DATA_PORT &= 0x0f;
        DATA_PORT &= 0x0f;
        DATA_PORT |= data&0xf0;

        RS_PIN = 1;                    // Set control bits
        RW_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock nibble into LCD
        DelayFor18TCY();
        E_PIN = 0;
                        // Upper nibble interface
        DATA_PORT &= 0x0f;
        DATA_PORT |= ((data<<4)&0xf0);

        DelayFor18TCY();
        E_PIN = 1;                      // Clock nibble into LCD
        DelayFor18TCY();
        E_PIN = 0;
                          // Upper nibble interface
        TRIS_DATA_PORT |= 0xf0;

        return;
}



/* putsXLCD
 * Writes a string of characters to the LCD
 */
/********************************************************************
*      Function Name:  putsXLCD
*      Return Value:  void
*      Parameters:    buffer: pointer to string
*      Description:    This routine writes a string of bytes to the
*                      Hitachi HD44780 LCD controller. The user
*                      must check to see if the LCD controller is
*                      busy before calling this routine. The data
*                      is written to the character generator RAM or
*                      the display data RAM depending on what the
*                      previous SetxxRamAddr routine was called.
********************************************************************/
void putsXLCD(char *buffer)
{
        while(*buffer)                  // Write data to LCD up to null
        {
                while(BusyXLCD());      // Wait while LCD is busy
                WriteDataXLCD(*buffer); // Write character to LCD
                buffer++;              // Increment buffer
        }
        return;
}

/* putrsXLCD
 * Writes a string of characters in ROM to the LCD
 */
/********************************************************************
*      Function Name:  putrsXLCD
*      Return Value:  void
*      Parameters:    buffer: pointer to string
*      Description:    This routine writes a string of bytes to the
*                      Hitachi HD44780 LCD controller. The user
*                      must check to see if the LCD controller is
*                      busy before calling this routine. The data
*                      is written to the character generator RAM or
*                      the display data RAM depending on what the
*                      previous SetxxRamAddr routine was called.
********************************************************************/
void putrsXLCD(const rom char *buffer)
{
        while(*buffer)                  // Write data to LCD up to null
        {
                while(BusyXLCD());      // Wait while LCD is busy
                WriteDataXLCD(*buffer); // Write character to LCD
                buffer++;              // Increment buffer
        }
        return;
}

/* User defines these routines according to the oscillator frequency */


#endif

Ya cheque todo y si me detecta el CCS y las librerias de pic18f4550.h tambien estan en su lugar

Todo esto pues lo trato de compilar con CCS
Luffy-X-
Luffy-X-
Participante
Participante

Mensajes : 24
Fecha de inscripción : 09/09/2011
Edad : 33
Localización : Mexico

Volver arriba Ir abajo

Ayuda con LCD LMG-162-STN Empty Re: Ayuda con LCD LMG-162-STN

Mensaje por Pikitin Lun 24 Oct 2011 - 1:10

Creo que esa biblioteca y programa son para el compilador C18 de Microchip:

http://www.romux.com/bootloader/usb-pic18f4550/lcd-hello-world

Pikitin
veterano
veterano

Mensajes : 623
Fecha de inscripción : 26/11/2008

http://linuxmicros.blogspot.com/

Volver arriba Ir abajo

Ayuda con LCD LMG-162-STN Empty Re: Ayuda con LCD LMG-162-STN

Mensaje por Luffy-X- Jue 27 Oct 2011 - 16:58

Osea que no se puede con el CCS y ni el SDCC? Razz
Luffy-X-
Luffy-X-
Participante
Participante

Mensajes : 24
Fecha de inscripción : 09/09/2011
Edad : 33
Localización : Mexico

Volver arriba Ir abajo

Ayuda con LCD LMG-162-STN Empty Re: Ayuda con LCD LMG-162-STN

Mensaje por WaRaW Miér 16 Nov 2011 - 5:55

saludos luffy-X-, comentaré en este post antes que se haga mas vieja la entrada, hace poco un amigo igual tenia problemas con un LCD nuevo, y al conectarlo al pic no mostraba nada, total que resulto que el lcd que el adquirio era de 3.3V de alimentacion y los pines de datos no eran tolerantes a TTL por lo que habia que representar un 1 logico con 3.3V, eso lo menciono para que tengan cuidado de revisar esa parte.......pero lo importante que queria compartir es un pequeño programa que hice en CCS para poder probar una LCD 2x16 en este caso con un pic16f84a a 4Mhz.......no es nada del otro mundo pero te podria servir para probar tu LCD.codigo y simulacion

WaRaW
Participante
Participante

Mensajes : 27
Fecha de inscripción : 18/04/2010

Volver arriba Ir abajo

Ayuda con LCD LMG-162-STN Empty Re: Ayuda con LCD LMG-162-STN

Mensaje por maigke Lun 7 Mayo 2012 - 6:27

Saludos!! compañero Luffy, espero que no sea muy tarde, y esto te aun te sea de utilidad

Pues de igual forma adquierí unos display de este tipo, pero para programarlos con un micro de gama media como el pic16f876a en SDCC te dejo el codigo que a mi me está trabajando, naturalmente usando la libreria de felixls
y la libreria de retardos del foro.

Revisa con cuidado en las definiciones de linea del lcd, ya que este display inicia en
#define LCD_LINE1 0x84 // Linea 1 posicion 1 1000 0000
#define LCD_LINE2 0xC4 // Linea 2 posicion 1 1010 0000

Otra ventaja es que si devuelves los valores a
#define LCD_LINE1 0x80 // Linea 1 posicion 1 1000 0000

#define LCD_LINE2 0xC0 // Linea 2 posicion 1 1010 0000

no solo te sirve para dos lineas, sino al igual para un lcd 20 x 4

Los pines vienen identicos al de un compatible hitachi, así que ahi no hay pierde, una cosa mas
cuando alimentas este display, a diferencia de los que son mas caritos, este inicia apagado totalmente
solo aparecen los caracteres despues de que se hace una adecuada configuracion de ellos.
Código:

/*-------------------------------------------------------------------------------------------------
  LCD Library (44780 compatible).

  No usa el pin R/W, ya que normalmente se lo conecta a la masa del circuito.
  Fecha de creación: 8/04/2009
  Autor: Felixls
  Web: http://sergiols.blogspot.com

  Changelog:
  Fecha  Versión    Observaciones
  8/4/09  1.00        Versión inicial
  19/05/11 1.01          Version adaptada para lcd 20 x 4 lineas y funcionando con Xt de 20MHz con PLL a 48MHz
 * 19/04/12 1.02      Version adaptada para lcd 16 x 2 lineas con XT = 4MHz compilador 3.0.0


  Frecuencia de reloj: 48MHZ
  Compilador: SDCC 2.9.1

  Actualizacion: Esta actualizacion es
  19 de mayo de 2011, modifico la libreria para poder usarla con la de hunif
  simple_delay.h
  * Se agregan #define LCD_LINEA 3 y LCD_LINEA_4 para usar una lcd de 4 lineas
  * Se agrega la funcion lcd_gotoxy, adaptada de la version de CCS
  * El encabezado de tu archivo main debe ser el siguiente

  code char at __CONFIG1L CONFIG1L = _PLLDIV_DIVIDE_BY_5__20MHZ_INPUT__1L & _CPUDIV__OSC1_OSC2_SRC___1__96MHZ_PLL_SRC___2__1L & _USBPLL_CLOCK_SRC_FROM_96MHZ_PLL_2_1L;
code char at __CONFIG1H CONFIG1H = _OSC_HS__HS_PLL__USB_HS_1H & _FCMEN_ON_1H & _IESO_ON_1H;
code char at __CONFIG2L CONFIG2L = _PUT_ON_2L & _BODEN_ON_2L & _BODENV_4_2V_2L & _VREGEN_ON_2L;
code char at __CONFIG2H CONFIG2H = _WDT_DISABLED_CONTROLLED_2H & _WDTPS_1_32768_2H;
code char at __CONFIG3H CONFIG3H = _CCP2MUX_RC1_3H & _PBADEN_PORTB_4_0__CONFIGURED_AS_DIGITAL_I_O_ON_RESET_3H & _LPT1OSC_ON_3H & _MCLRE_MCLR_OFF_RE3_ON_3H;
code char at __CONFIG4L CONFIG4L = _STVR_ON_4L & _LVP_OFF_4L & _ENHCPU_OFF_4L & _BACKBUG_OFF_4L;
code char at __CONFIG5L CONFIG5L = _CP_0_OFF_5L & _CP_1_OFF_5L & _CP_2_OFF_5L & _CP_3_OFF_5L;
code char at __CONFIG5H CONFIG5H = _CPB_OFF_5H;
code char at __CONFIG6L CONFIG6L = _WRT_0_OFF_6L & _WRT_1_OFF_6L & _WRT_2_OFF_6L & _WRT_3_OFF_6L;
code char at __CONFIG6H CONFIG6H = _WRTC_OFF_6H & _WRTB_OFF_6H;
code char at __CONFIG7L CONFIG7L = _EBTR_0_OFF_7L & _EBTR_1_OFF_7L & _EBTR_2_OFF_7L & _EBTR_3_OFF_7L;
code char at __CONFIG7H CONFIG7H = _EBTRB_OFF_7H;


  --Autor: Miguel Montiel Martinez
  -------------------------------------------------------------------------------------------------*/



/*  PORTB:4  ----->  LCD bit 4          */
/*  PORTB:5  ----->  LCD bit 5          */
/*  PORTB:6  ----->  LCD bit 6          */
/*  PORTB:7  ----->  LCD bit 7          */
/*  PORTB:2  ----->  LCD RS              */
/*  PORTB:3  ----->  LCD E              */


#define LCD_DATA                PORTB // Puerto de datos
#define LCD_DATA_TRIS          TRISB // Control del puerto de datos
#define LCD_RS                  RB2  // Modo
#define LCD_ENABLE              RB3  // Habilitación/deshab. en envíos de datos al lcd.
#define LCD_CLEAR                0x01 // Clear Display
#define LCD_HOME                0x02 // Cursor a Home
#define LCD_NORMAL              0x06 // Cursor en modo incrementar.
#define LCD_REV                  0x04 // Normal-reverse
#define LCD_SCROLL              0x07 // Usa scroll
#define LCD_SCROLL_REV          0x05 // Reverse
#define LCD_D8_BIT              0x38 // 8 bit 2 lineas ( 5x7 font )
#define LCD_D4_BIT_CONF          0x20 // 4 bit
#define LCD_D4_BIT              0x28 // 4 bit 2 lineas ( 5x7 font )
#define LCD_RESET                0x30 // Reset
#define LCD_DIS_ON              0x0C // Display on modo 2 lineas
#define LCD_DIS_OFF              0x08 // Display off
#define LCD_LINE1                0x84 // Linea 1 posicion 1 1000 0000
#define LCD_LINE2                0xC4 // Linea 2 posicion 1 1010 0000
#define LCD_LINE3        0x94 //Linea 3 posicion  1
#define LCD_LINE4        0xD4 //Linea 4 posicion  1
#define LCD_CURSOR_ON            0x0E // Cursor on
#define LCD_CURSOR_OFF          0x0C // Cursor off
#define LCD_BLINK_ON            0x0F // Cursor blink
#define LCD_CURSOR_DER          0x14 // Mover cursor derecha
#define LCD_CURSOR_IZQ          0x10 // Mover cursor izquierda
#define LCD_DISPLAY__DER        0x1C // Scroll display derecha
#define LCD_DISPLAY__IZQ        0x18 // Scroll display izquierda
#define LCD_CHARMODE            0x01
#define LCD_COMMANDMODE          0x00
#define LCD_CGRAM1        0x40 //primera direccion para CGRAM
#define LCD_CGRAM2        0x48 //segunda direccion para CGRAM#define FOSC 48000000




void lcd_init (void);
void lcd_send( char mode, char dato );
void lcd_message ( char * mess );
void lcd_send_quartet( char mode, char dato );
char lcd_hexa(char a);
void lcd_showint(unsigned int value);
void lcd_showintright(unsigned int value, int index);
void lcd_gotoxy(char x, char y);


void lcd_send_quartet( char mode, char dato )
{
    LCD_RS = mode;
    PORTB = dato  | (PORTB & 0x0f) ;
    LCD_ENABLE = 1;
    delay_ms(1);
    LCD_ENABLE = 0;
}

void lcd_send( char mode, char dato )
{
    //unsigned int j;
    char dat = dato;
    LCD_RS = mode;
    dat = dato & 0xf0;
    PORTB = dat | (PORTB & 0x0f) ;
    LCD_ENABLE = 1;
    delay_ms(5);
    LCD_ENABLE = 0;
    dat = ((dato<<4)& 0xf0);
    PORTB = dat | (PORTB & 0x0f) ;
    LCD_ENABLE = 1;
    delay_ms(5);
    LCD_ENABLE = 0;
    delay_ms(30);
}





void lcd_init (void)

{
  LCD_DATA_TRIS &= 0x03;
  delay_ms(15);
  lcd_send_quartet(LCD_COMMANDMODE, LCD_RESET);
  delay_ms(5);
  lcd_send_quartet(LCD_COMMANDMODE, LCD_RESET);
  delay_ms(1);
  lcd_send_quartet(LCD_COMMANDMODE, LCD_RESET);
  delay_ms(1);
  lcd_send_quartet(LCD_COMMANDMODE, LCD_D4_BIT_CONF);
  delay_ms(1);
  lcd_send(LCD_COMMANDMODE, LCD_D4_BIT);
  delay_ms(1);
  lcd_send(LCD_COMMANDMODE, LCD_CLEAR);
  delay_ms(2);
  lcd_send(LCD_COMMANDMODE, LCD_CURSOR_OFF);
  delay_ms(2);
  lcd_send(LCD_COMMANDMODE, LCD_NORMAL);
  delay_ms(1);
  lcd_send(LCD_COMMANDMODE, LCD_DIS_ON);
  delay_ms(1);
}



void lcd_message ( char * mess )

{
  while ( *mess )
  {
    lcd_send(LCD_CHARMODE, *mess ) ;
    mess++ ;
  }
}



char lcd_hexa(char a)
{
    if (a >9)
        a+=55;
    else
        a+=48;
  return a;
}

void lcd_gotoxy(char x, char y)
{
char ADDRESS=0X00;

    switch(y)
    {
    case 1: ADDRESS=LCD_LINE1;
        break;
    case 2: ADDRESS=LCD_LINE2;
        break;
    case 3: ADDRESS=LCD_LINE3;
        break;
    case 4: ADDRESS=LCD_LINE4;
        break;
    default:
                ADDRESS=LCD_LINE1;
        break;
    }

    ADDRESS= (ADDRESS + x) -1;
    lcd_send(LCD_COMMANDMODE,ADDRESS);
}



Código:


#define coms FREQ/4000

void pausa(unsigned char ciclos);
void delay_ms(unsigned int ms);

/** Funcion de pausa
 */
void pausa(unsigned char ciclos)
{
    ciclos;  //tiempo = (4*ciclos+1)us, para 4MHz
    __asm
            sublw 1
    bucle:
            addlw 1
            btfss STATUS, 0
            goto bucle
    __endasm;
}

void delay_ms(unsigned int ms)
{
    ms *=coms;
    while(ms >0)
    {
        pausa(200);
        ms--;
    }
}

Código:

/* ----------------------------------------------------------------------- */
/* Plantilla generada por Piklab */
#include <pic16f876a.h>


#define FREQ 4000
#include "simple_delay.h"
#include "lcd.h"
/* ----------------------------------------------------------------------- */
/* Bits de configuración: adapte los parámetros a su necesidad */
typedef unsigned int word;
word __at 0x2007 CONFIG = _XT_OSC & _WDT_OFF & _PWRTE_OFF & _BODEN_ON & _LVP_OFF & _CPD_OFF & _WRT_OFF & _DEBUG_OFF & _CP_OFF;


void isr() __interrupt 0 {                                                                                                                                      /* rutina de servicio de interrupciones */
    /* << agregue el código de interrupción >> */
}

void main() {
    unsigned char i;
    ADCON1 = 0x06;  //Solo E/S digitales
    TRISB=0;  //Todo el puerto B es salida
    TRISA0=0;  //pin A0 salida
    lcd_init();  //Se inicializa la LCD
    RA0^=1;
    delay_ms(4000);
    RA0^=1;
   
 
    while(1)
    {
        lcd_gotoxy(1,1);
        lcd_message("ITST-MECA-!6to¡ ");
        delay_ms(5000);
        RA0^=1;
        lcd_send(LCD_COMMANDMODE, LCD_CLEAR);
        delay_ms(5000);
        RA0^=1;
        lcd_gotoxy(1,2);
        lcd_message("Microcontrolador");
        delay_ms(5000);
        RA0^=1;
        delay_ms(5000);
        lcd_send(LCD_COMMANDMODE,LCD_CURSOR_ON);
        delay_ms(5000);
        RA0^=1;
        lcd_send(LCD_COMMANDMODE, LCD_BLINK_ON);
        delay_ms(5000);
        RA0^=1;
        lcd_send(LCD_COMMANDMODE, LCD_CURSOR_OFF);
        delay_ms(5000);
        RA0^=1;
        lcd_send(LCD_COMMANDMODE, LCD_CLEAR);
        delay_ms(1000);
        lcd_send(LCD_COMMANDMODE, LCD_CURSOR_ON);
        delay_ms(1000);
        lcd_gotoxy(2,2);
        lcd_message("MAPACHES");

        for(i=0;i<22;i++)
        {
            lcd_send(LCD_COMMANDMODE,LCD_DISPLAY__DER); //scroll a la derecha
            delay_ms(1000);
        }
    }

}

Imagen de la LCD chambeando

Ayuda con LCD LMG-162-STN Image2993n

maigke
maigke
Asiduo del Foro
Asiduo del Foro

Mensajes : 210
Fecha de inscripción : 12/04/2009
Edad : 46
Localización : Mexico

Volver arriba Ir abajo

Ayuda con LCD LMG-162-STN Empty Re: Ayuda con LCD LMG-162-STN

Mensaje por maigke Lun 7 Mayo 2012 - 6:44

Aqui te dejo el enlance del proyecto en mi dropbox, es para MPLABX el proyecto

http://dl.dropbox.com/u/77925362/lcdPICtest.X.rar

saludos
maigke
maigke
Asiduo del Foro
Asiduo del Foro

Mensajes : 210
Fecha de inscripción : 12/04/2009
Edad : 46
Localización : Mexico

Volver arriba Ir abajo

Ayuda con LCD LMG-162-STN Empty Re: Ayuda con LCD LMG-162-STN

Mensaje por Contenido patrocinado


Contenido patrocinado


Volver arriba Ir abajo

Volver arriba

- Temas similares

 
Permisos de este foro:
No puedes responder a temas en este foro.