Autor Tema: LCD 16x2 XC8  (Leído 7090 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado pic16f88A

  • PIC10
  • *
  • Mensajes: 21
LCD 16x2 XC8
« en: 14 de Diciembre de 2013, 19:07:27 »
HOLA A TODOS
PROBLEMA: NO MUESTRA EL MENSAJE CORRESPONDIENTE. ERROR AL COMPILAR VISIBLE EN FOTO
CONEXIONES EN FOTO.
LIBRERIA LCD EN FOTO.
CODIGO:
#include <stdio.h>
#include <stdlib.h>
#include<pic18f4520.h>
#include<stdlib.h>
#include<plib/xlcd2.h>
#include<plib/delays.h>

void DelayFor18TCY( void )
{
  Nop();
  Nop();
  Nop();
  Nop();
  Nop();
  Nop();
  Nop();
  Nop();
  Nop();
  Nop();
  Nop();
  Nop();
}

void DelayPORXLCD (void)
{
  Delay1KTCYx(15); // Delay of 15ms
                   // Cycles = (TimeDelay * Fosc) / 4
                   // Cycles = (15ms * 4MHz) / 4
                   // Cycles = 15000
  return;
}
void DelayXLCD (void)
{
  Delay1KTCYx(5); // Delay of 5ms
                   // Cycles = (TimeDelay * Fosc) / 4
                   // Cycles = (5ms * 4MHz) / 4
                   // Cycles = 5,000
  return;
}

int main(int argc, char** argv) {
TRISD=0;
OpenXLCD( FOUR_BIT & LINES_5X7 );
putrsXLCD( "MUCHAS GRACIAS" );
while(1);
    return (EXIT_SUCCESS);
}

Desconectado AngelGris

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 2480
Re: LCD 16x2 XC8
« Respuesta #1 en: 14 de Diciembre de 2013, 22:39:12 »
No veo que esté alimentado el LCD en proteus.
De vez en cuando la vida
nos besa en la boca
y a colores se despliega
como un atlas

Desconectado pic16f88A

  • PIC10
  • *
  • Mensajes: 21
Re: LCD 16x2 XC8
« Respuesta #2 en: 15 de Diciembre de 2013, 04:07:24 »
EN PROTEUS NUNCA SE HA PRECISADO DE ALIMENTACION EN LCD
PERO MUCHAS GRACIAS POR APORTAR
UN SALUDO

Desconectado pic16f88A

  • PIC10
  • *
  • Mensajes: 21
Re: LCD 16x2 XC8
« Respuesta #3 en: 15 de Diciembre de 2013, 04:12:15 »
E AQUI EL CAMBIO

Desconectado AngelGris

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 2480
Re: LCD 16x2 XC8
« Respuesta #4 en: 15 de Diciembre de 2013, 09:40:33 »
EN PROTEUS NUNCA SE HA PRECISADO DE ALIMENTACION EN LCD
PERO MUCHAS GRACIAS POR APORTAR
UN SALUDO

  No lo sabía, gracias por la info.

  Podrías incluir como tienes configurado el pic (los bit de configuración) tal vez por ahí venga el error... No se, se me ocurre que el pic podría estar trabajando a más de 4MHz y por ello no se configura bien el LCD.
De vez en cuando la vida
nos besa en la boca
y a colores se despliega
como un atlas

Desconectado pic16f88A

  • PIC10
  • *
  • Mensajes: 21
Re: LCD 16x2 XC8
« Respuesta #5 en: 15 de Diciembre de 2013, 11:59:05 »
EL ENCABEZADO ES EL QUE VES EN LA FOTO.
EL PIC TRABAJA A 4mhz

Desconectado AngelGris

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 2480
Re: LCD 16x2 XC8
« Respuesta #6 en: 15 de Diciembre de 2013, 12:07:40 »
EL ENCABEZADO ES EL QUE VES EN LA FOTO.
EL PIC TRABAJA A 4mhz

  No me refiero al encabezado de la librería sino a los bits de configuración del PIC, tales como tipo de oscilador, MasterClear, LowVoltagePrograming, WatchDogTimer, CodeProtec... en fin... todo lo que hace a su configuración.

  Porque por ejemplo el 18F2550 puedes colocar un cristal de 4MHz y sin embargo con la configuración del PLL interno estar trabajando a 48MHz.

  En varios PIC si usas cristal de hasta 4MHz el oscilador es XT, pero para cristales de mayor velocidad es HS.

  ¿Has colocado 4MHz en la opción de proteus?

  Puede estar ocurriendo que el LCD se encuentre ocupado y tú estés queriendo escribir el mensaje. Checkea el busy antes de escribir el mensaje, o dale una espera larga... no sé.. unos 5ms para probar.

  Agrego... estoy viendo el fuente de la función puts y sí ckequea el busy.
Veo que tú llamas a una función putrsXLCD() para escribir el mensaje pero en la carpeta de mi instalación sólo encuentro putsXLCD() o putrXLCD()... tal vez allí esté el error.
« Última modificación: 15 de Diciembre de 2013, 12:23:15 por AngelGris »
De vez en cuando la vida
nos besa en la boca
y a colores se despliega
como un atlas

Desconectado pic16f88A

  • PIC10
  • *
  • Mensajes: 21
Re: LCD 16x2 XC8
« Respuesta #7 en: 15 de Diciembre de 2013, 15:20:34 »
ENCABEZADO:
#pragma config WDT = OFF, OSC = EC, LVP = OFF, PBADEN = OFF //Parámetros para grabar
EN EL PROTEUS ESTA PUESTO 4MHZ TAMBIEN
« Última modificación: 15 de Diciembre de 2013, 15:23:32 por pic16f88A »

Desconectado rotting79

  • PIC12
  • **
  • Mensajes: 91
Re: LCD 16x2 XC8
« Respuesta #8 en: 17 de Diciembre de 2013, 02:38:52 »
Try this one....



LCD.c
Código: C
  1. /************ LCD.c *********/
  2.  
  3. #include "LCD.h"
  4. #include "stdio.h"
  5.  
  6. /*******************************************************************/
  7. /*      -SetUpLCD ( )
  8. /*              configures the LCD pins (described in LCD.h), and initialize  
  9. /*              the HD44780 Hitachi compatible module.
  10. /*
  11. /*      -LCDSendNibble ( n )
  12. /*              -n
  13. /*              pasees the high and low nibble to be writen on Data Port,
  14. /*              mainly from the LCDSendByte ( Address, Data ) function.
  15. /*
  16. /*      -LCDSendByte ( Address, Data )
  17. /*              -Address
  18. /*              -Data
  19. /*              pasees a Byte to be writen on Data Port.
  20. /*
  21. /*      -LCDPutCh ( *buffer )
  22. /*              -*Buffer
  23. /*              displays the Character (as pointer) on the Display, using the .
  24. /*              LCDSendByte ( ) function.
  25. /*
  26. /*      -LCDGotoXY ( x, y )
  27. /*              -x
  28. /*              -y
  29. /*              sets the x axis and y axis on the 2x16 HD44780 Hitachi
  30. /*              compatible module.
  31. /*
  32. /*      -ClearLCD ( )
  33. /*              clears up the display.
  34. /*
  35. /*      Note1: this library will SetUp the 2x16 HD44780 Hitachi
  36. /*      compatible module as 2 lines, 5x7 dots, auto increment, cursor off
  37. /*      as default.
  38. /*      Note2: this library is intended to work with a 2x16 HD44780 Hitachi
  39. /*      compatible module, even with the COG LCDs.
  40. /*      The functions were taken from the CCS library and make them
  41. /*      compatible with the XC8 Compiler.
  42. /*                                              Fabian H Rodriguez */
  43. /******************************************************************/
  44.  
  45. /******* Set ups a HD44780 Hitachi compatible module **************/
  46. void SetUpLCD( void )
  47. {
  48.         unsigned char i;
  49.  
  50.         TRIS_DATA_PORT &= 0x80;                 // Sets the PortData and RS, Enable
  51.         DATA_PORT &= 0x80;                              // and LCD BK pins as outputs,
  52.                                                                         // Command Mode (RS = 0).
  53.                                                                         // it impedes operation of the LCD (E = 0).
  54.         __delay_ms ( 15 );
  55.         BL_PIN = HIGH;                                  // Turn On the LCD's Back Light.
  56.        
  57.         for ( i = 0; i <= 2; i ++ )
  58.         {
  59.                 LCDSendNibble ( 0x03 );         // Send three time the same code ( 0011 )
  60.                 __delay_ms ( 5 );                       // to the data port, first delayed > 4.1 ms,
  61.                 }                                                       // the second one of 100 us, third one don't matter.
  62.                        
  63.         LCDSendNibble ( 0x02 );                 // Send 0010 code to data port.
  64.  
  65.         for ( i = 0; i <= 3; ++i )              // 4bits data, 5x7 dots, display on, cursor off, autoincrement.
  66.                 LCDSendByte ( COMMAND, LCD_SET_UP [ i ] );
  67.  
  68.         }
  69.  
  70.        
  71. /***** Pasees a Nibble to be writen on Data Port **************/
  72. void LCDSendNibble ( unsigned char n )
  73. {
  74.         unsigned char temp;
  75.        
  76.         temp = ( n | ( 0xF0 & DATA_PORT ) );// Passing the nibble "n"
  77.                                                                                 // without affecting the MSB on PORTx.
  78. //      DATA_PORT = n;
  79.         DATA_PORT = temp;                                       // Pass the "temp" value to the
  80.                                                                                 // DATA_PORT.
  81.         __delay_us ( 1 );                                       // Generate a pulse on Enable pin
  82.         E_PIN = HIGH;                                           // to let know the LCD an action
  83.         __delay_us ( 2 );                                       // has been done.
  84.         E_PIN = LOW;
  85.         }
  86.  
  87.  
  88. /********* Pasees a Byte to be writen on Data Port **************/
  89. void LCDSendByte ( unsigned char address, char data )
  90. {
  91.         unsigned char temp;
  92.  
  93. //      DATA_PORT = 0x00;                       // clear data_port.
  94.         DATA_PORT &= 0xF0;                      // clear DATA_PORT without affecting MSB on PORTx.
  95.         RS_PIN = address;                       // write command.
  96.  
  97.         if ( address )                          // Here is the trick: to avoid read the LCD's status
  98.                 __delay_us ( 50 );              // most know which action was performed (Command or
  99.                                                                 // Write) to do a delay as long as the action were
  100.         else                                            // performed.
  101.                 __delay_ms ( 2 );
  102.                
  103.         E_PIN = LOW;
  104.  
  105.         temp = DATA_PORT & 0xF0;        // Save the PORT_DATA status to a "temp" var.
  106.  
  107.         if ( data == '°' )                     // "°" symbol if need it.
  108.                 data = 0xDF;
  109.        
  110.         temp |= ( ( data >> 4 ) & 0x0F );       // pass first nibble to data_port.
  111.         LCDSendNibble ( temp );
  112.  
  113.         temp &= 0xF0;                           // clear data_port.
  114.         temp |= (data&0x0f);            // pass first nibble to data_port.
  115.         LCDSendNibble ( temp );
  116.         }
  117.  
  118.        
  119. /********* Puts a Character as a pointer on the Display **************/
  120. void LCDPutCh ( const char *buffer )
  121. {
  122.         while ( *buffer )                                       // Write data to LCD up to null found.
  123.         {
  124.                 LCDSendByte ( WRITE, *buffer ); // Write character to LCD.
  125.                 buffer ++;                                              // Increment buffer.
  126.                 }
  127.        
  128.         return;
  129.         }
  130.        
  131.        
  132. /********* Set coordinates for the 2 x 16 Display **************/
  133. void LCDGotoXY ( char x, char y )
  134. {
  135.         char Address;
  136.  
  137.         if ( y != 1 )                   // If 'y' axie different of line one go to
  138.                 Address = 0x40;         // LCD's line two.
  139.         else
  140.                 Address = 0x00;         // If not, go to first memory address.
  141.  
  142.         Address += x-1;                 // On axie 'x' add an address as need it.
  143.         LCDSendByte ( COMMAND, 0x80 | Address );
  144.         }
  145.  
  146.  
  147. /********* Clears Up the Display **************/
  148. void ClearLCD ( void )
  149. {
  150.         LCDSendByte ( COMMAND, CLEAR_DISPLAY );
  151.        
  152.         }


LCD.h
Código: C
  1. #include        <xc.h>
  2. /************ LCD.h *********/
  3.  
  4. /********* LCD Port Configuration Control bits ********/
  5. /*                                                                                             
  6. /*     D0  DATA4                                                                                                                                                                       
  7. /*     D1  DATA5                                                                                               
  8. /*     D2  DATA6                                                                               
  9. /*     D3  DATA7                                                                               
  10. /*     D4  PIN RS                                                                              
  11. /*     D5  PIN ENABLE                                                          
  12. /*     D6  PIN LCD_BK (back light)                                                                                                                                                                                                      */
  13. /*     D7  PIN is not used.
  14.  
  15. /* DATA_PORT defines the port to which the LCD data lines are connected */
  16. #if defined ( _PIC18F45K22_H_ )
  17.         #define DATA_PORT               LATD
  18.         #define TRIS_DATA_PORT          TRISD
  19.        
  20.         // #define RW_PIN   PORTDbits.RD4               // rw pin.
  21.         #define RS_PIN  LATDbits . LATD4                // rs pin.
  22.         #define E_PIN   LATDbits . LATD5                // enable pin.
  23.         #define BL_PIN  LATDbits . LATD6                // back light.
  24. #elif defined ( _PIC16F887_H_ )
  25.         #define DATA_PORT               PORTD
  26.         #define TRIS_DATA_PORT          TRISD
  27.        
  28. //      #define BL_PIN  PORTDbits . RD4                 // rw pin.
  29.         #define RS_PIN  PORTDbits . RD4                 // rs pin.
  30.         #define E_PIN   PORTDbits . RD5                 // enable pin.
  31.         #define BL_PIN  PORTDbits . RD6                 // back light.
  32. #endif
  33.  
  34.  
  35. void SetUpLCD( void );
  36. void LCDSendNibble ( unsigned char n );
  37. void LCDSendByte ( unsigned char address, unsigned char n );
  38. void LCDPutCh ( const  char *buffer );
  39. void LCDGotoXY ( char x, char y );
  40.  
  41.  
  42. /******* CONSTANTS FOR PINS ****************/
  43. #define HIGH    0x01
  44. #define LOW             0x00
  45.  
  46. /******* CONSTANTS FOR SET UP ****************/
  47. #define FOUR_BITS_5X7_DOTS              0x28
  48. #define CLEAR_DISPLAY                   0x01
  49. #define CURSOR_OFF                              0x0C
  50. #define AUTO_INCREMENT                  0x06
  51.  
  52. /******* LCD SET UP *******************************/
  53. unsigned char const LCD_SET_UP [ 4 ] = { FOUR_BITS_5X7_DOTS,
  54.                                                                                 CLEAR_DISPLAY,
  55.                                                                                 CURSOR_OFF,
  56.                                                                                 AUTO_INCREMENT };      
  57.  
  58. /******* WRITE / COMMAND OPERATION ****************/
  59. #define WRITE                   0x01
  60. #define COMMAND                 0x00
  61.  
  62. /******* LCD LINES ( Y axi ) ****************/
  63. #define LINE_ONE                0x01
  64. #define LINE_TWO                0x02
  65.  
  66. /******* LCD ROWS ( X axi ) ****************/
  67. #define ROW_ONE                 0x01
  68. #define ROW_TWO                 0x02
  69. #define ROW_THREE               0x03
  70. #define ROW_FOUR                0x04
  71. #define ROW_FIVE                0x05
  72. #define ROW_SIX                 0x06
  73. #define ROW_SEVEN               0x07
  74. #define ROW_EIGHT               0x08
  75. #define ROW_NINE                0x09
  76. #define ROW_TEN                 0x0A
  77. #define ROW_ELEVEN              0x0B
  78. #define ROW_TWELVE              0x0C
  79. #define ROW_THIRTEEN    0x0D
  80. #define ROW_FOURTEEN    0x0E
  81. #define ROW_FIFTEEN             0x0F
  82. #define ROW_SIXTEEN             0X10







« Última modificación: 26 de Febrero de 2014, 01:38:02 por rotting79 »
...On November 2nd, a PIC10 became self-aware and decided our fate in __delay_us ( 1 ); ...

Desconectado rotting79

  • PIC12
  • **
  • Mensajes: 91
Re: LCD 16x2 XC8
« Respuesta #9 en: 17 de Diciembre de 2013, 02:49:40 »
Here is the example...

Código: C
  1. #include <xc.h>
  2.  
  3. #define _XTAL_FREQ      FREQ_8MHz
  4.  
  5. #include "SetUp.c"
  6.  
  7.  
  8.  
  9. int main ( string [ ], args )   // @ 0x10
  10. {
  11.         SetUp ( );
  12.  
  13. /* SetUp the LCD. */
  14.         SetUpLCD ( );
  15.  
  16.         printf ( "Application Ready...\n" );
  17.         __delay_ms ( 50 );
  18.  
  19. //      WelcomeDisplay ( );
  20.  
  21.         ClearLCD ( );
  22.         LCDGotoXY ( ROW_ONE, LINE_ONE );
  23.         LCDPutCh ( "Hey You!!" );
  24.  
  25.         LCDGotoXY ( ROW_FOUR, LINE_TWO );
  26.         LCDPutCh ( ".....me??" );
  27.        
  28.  
  29.  
  30.         while ( TRUE )
  31.         {
  32.                 }              
  33.  
  34.         return 0x00;
  35.         }

« Última modificación: 17 de Diciembre de 2013, 02:59:29 por rotting79 »
...On November 2nd, a PIC10 became self-aware and decided our fate in __delay_us ( 1 ); ...

Desconectado marcoj2560456*

  • PIC10
  • *
  • Mensajes: 20
Re: LCD 16x2 XC8
« Respuesta #10 en: 29 de Septiembre de 2015, 17:07:58 »

rotting79 yo estoy programando en xc16 un 24fj64gb002 y estoy intentando aplicar tu libreria de lcd al pic pero surgen errores y no si si es el setup.c q incluyes en esa libreria si pudieras ayudarme para utilizar una lcd 2x16 con este pic seria
Here is the example...

Código: C
  1. #include <xc.h>
  2.  
  3. #define _XTAL_FREQ      FREQ_8MHz
  4.  
  5. #include "SetUp.c"
  6.  
  7.  
  8.  
  9. int main ( string [ ], args )   // @ 0x10
  10. {
  11.         SetUp ( );
  12.  
  13. /* SetUp the LCD. */
  14.         SetUpLCD ( );
  15.  
  16.         printf ( "Application Ready...\n" );
  17.         __delay_ms ( 50 );
  18.  
  19. //      WelcomeDisplay ( );
  20.  
  21.         ClearLCD ( );
  22.         LCDGotoXY ( ROW_ONE, LINE_ONE );
  23.         LCDPutCh ( "Hey You!!" );
  24.  
  25.         LCDGotoXY ( ROW_FOUR, LINE_TWO );
  26.         LCDPutCh ( ".....me??" );
  27.        
  28.  
  29.  
  30.         while ( TRUE )
  31.         {
  32.                 }              
  33.  
  34.         return 0x00;
  35.         }


buenisimo
Romanos 10:9-10

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re: LCD 16x2 XC8
« Respuesta #11 en: 29 de Septiembre de 2015, 18:13:09 »
Si le pones los errores que te da va a ser mas facil saber tanto para el, como para cualquier otra persona ayudarte.

la ultima ves que entro al foro rotting fue el 3 de septiembre de este año.

Desconectado marcoj2560456*

  • PIC10
  • *
  • Mensajes: 20
Re: LCD 16x2 XC8
« Respuesta #12 en: 30 de Septiembre de 2015, 12:14:33 »
he estado utilizando otras librerias de angel gris y me compila bien pero al probarlo en fisico no muestra nada en la lcd el programa lo puse en mini curso de xc8 lo acabo de poner si tienes alguna idea agredeceria tu ayuda  KILLERJC
Romanos 10:9-10

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re: LCD 16x2 XC8
« Respuesta #13 en: 30 de Septiembre de 2015, 13:32:25 »
Intenta seguir en un hilo el problema, por 2 cosas

- Va en contra de las reglas del foro
- Se vuelve muy complicado tener abierto 2 pestañas buscando cada cosa en cada lugar.

Sigo en el otro


 

anything