Autor Tema: Visualizar voltaje en Lcd  (Leído 5859 veces)

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

Desconectado elgarbe

  • Moderadores
  • PIC24H
  • *****
  • Mensajes: 2178
Re:Visualizar voltaje en Lcd
« Respuesta #15 en: 04 de Febrero de 2016, 13:32:35 »
probá con:

Código: C
  1. char cadena_de_texto [6];

saludos
-
Leonardo Garberoglio

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re:Visualizar voltaje en Lcd
« Respuesta #16 en: 04 de Febrero de 2016, 13:33:03 »
El problema es que no se que es porque al usar itoa no falla.
¿Pudes decirme si el codigo esta bien y asi descartaria alguna cosa?

Gracias.
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re:Visualizar voltaje en Lcd
« Respuesta #17 en: 04 de Febrero de 2016, 13:42:21 »
Estoy con el mobil y os dais mas prisa vosotros en contestar que yo en escribir, :D
Seguire probando cosas.
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado AngelGris

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 2480
Re:Visualizar voltaje en Lcd
« Respuesta #18 en: 04 de Febrero de 2016, 14:32:24 »
  Creo que el problema podría venir por la longitud del bufer, como bien lo indica elgarbe
De vez en cuando la vida
nos besa en la boca
y a colores se despliega
como un atlas

Desconectado AngelGris

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 2480
Re:Visualizar voltaje en Lcd
« Respuesta #19 en: 04 de Febrero de 2016, 14:47:51 »
  Otro detalle es que si utilizas el ADC en 10 bits el mayor número será 1023 y no 1024. Son 1024 posibilidades ya que va des 0 a 1023
De vez en cuando la vida
nos besa en la boca
y a colores se despliega
como un atlas

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re:Visualizar voltaje en Lcd
« Respuesta #20 en: 04 de Febrero de 2016, 16:02:46 »
He dado con el problema aunque no se que delay modificar, cambiando el Lcd por uno que tengo bastante viejo he conseguido que me funcione, por eso entiendo que es problema de la inicialización del Lcd aunque tampoco lo tengo claro, porque si intento visualizar algún mensaje sin usar el ADC no tengo problemas de inicialización.  :5]
El Lcd que estoy usando y con el que tengo problemas es el QC1602A v2.0 y los delays que he modificado son:
Código: C
  1. void DelayFor18TCY(void)    //Delay 0,00002sec => 20us => 0,02ms
  2. {
  3.     Delay10TCYx(24);
  4. }
  5. void DelayPORXLCD(void)     //Delay 0,015sec => 15000us => 15ms
  6. {
  7.     Delay1KTCYx(180);
  8. }
  9. void DelayXLCD(void)        //Delay 0,002sec => 2000us => 2ms
  10. {
  11.     Delay1KTCYx(24);
  12. }
Estoy trabajando a 48MHz
« Última modificación: 04 de Febrero de 2016, 16:11:12 por Miquel_S »
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado elgarbe

  • Moderadores
  • PIC24H
  • *****
  • Mensajes: 2178
Re:Visualizar voltaje en Lcd
« Respuesta #21 en: 04 de Febrero de 2016, 16:18:53 »
probaste con ftoa?

saludos
-
Leonardo Garberoglio

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re:Visualizar voltaje en Lcd
« Respuesta #22 en: 04 de Febrero de 2016, 16:47:22 »
probaste con ftoa?
saludos

Nuevametne, el source provisto por MCHP de la funcion ftoa() utiliza un sprintf() como el lo uso.

Citar
He dado con el problema aunque no se que delay modificar, cambiando el Lcd por uno que tengo bastante viejo he conseguido que me funcione, por eso entiendo que es problema de la inicialización del Lcd aunque tampoco lo tengo claro, porque si intento visualizar algún mensaje sin usar el ADC no tengo problemas de inicialización

Pero por lo que comentas no ocurre al comienzo sino mientras esta funcionando, y ahi puede ser problema de las funciones que manejen el LCD.
De todas formas los tiempos incluso son gigantes. Creo que el maximo tiempo en la inicializacion es de 2ms de delay, y lo demas cambiando el pin E que es el unico que se cambia rapido son nanosegundos creo.

Desconectado AngelGris

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 2480
Re:Visualizar voltaje en Lcd
« Respuesta #23 en: 04 de Febrero de 2016, 17:23:11 »
  Es  como si alguna función quisiera escribir en el LCD mientras éste está ocupado. Habría que ver las implementaciones de las rutinas. Creo que putrsXLCD chequea primero el flag de busy por lo tanto no creo que sea. No sé gotoxyXLCD como estará implementado.
De vez en cuando la vida
nos besa en la boca
y a colores se despliega
como un atlas

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re:Visualizar voltaje en Lcd
« Respuesta #24 en: 04 de Febrero de 2016, 18:20:26 »
No se por que motivo, pero si elimino las dos ultimas lineas de código funciona sin problemas con el Lcd que antes no funcinaba:
Código: C
  1. while(1)
  2.     {
  3.         SetChanADC(0);  //Seleccionamos canal
  4.         ConvertADC();    //Iniciamos conversion
  5.        
  6.         while(BusyADC()){}    //Esperamos que termine la conversion
  7.         valor_adc = ReadADC();  //Leemos conversion y la guardamos en valor_adc
  8.         voltios = (valor_adc/1024.0)*5.0;   //Convertimos valor ADC
  9.         gotoxyXLCD(1,1);    //Nos posicionamos en el Lcd
  10.         putrsXLCD("Bateria: ");
  11.         sprintf(cadena_de_texto,"%.2f",voltios);    //Visualizamos voltaje en formato float
  12.         putrsXLCD(cadena_de_texto);
  13.         //gotoxyXLCD(1,2);
  14.         //putrsXLCD("Estado: ");
  15.     }
  16. }
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re:Visualizar voltaje en Lcd
« Respuesta #25 en: 04 de Febrero de 2016, 18:33:27 »
Podrias poner el archivo donde tenes todas las funciones del LCD definidas ?

Desconectado Miquel_S

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1251
Re:Visualizar voltaje en Lcd
« Respuesta #26 en: 04 de Febrero de 2016, 18:54:48 »
Código: C
  1. #include <p18cxxx.h>
  2. #include <xlcd.h>
  3.  
  4. /********************************************************************
  5. *       Function Name:  BusyXLCD                                    *
  6. *       Return Value:   char: busy status of LCD controller         *
  7. *       Parameters:     void                                        *
  8. *       Description:    This routine reads the busy status of the   *
  9. *                       Hitachi HD44780 LCD controller.             *
  10. ********************************************************************/
  11. unsigned char BusyXLCD(void)
  12. {
  13.         RW_PIN = 1;                     // Set the control bits for read
  14.         RS_PIN = 0;
  15.         DelayFor18TCY();
  16.         E_PIN = 1;                      // Clock in the command
  17.         DelayFor18TCY();
  18. #ifdef BIT8                             // 8-bit interface
  19.         if(DATA_PORT&0x80)                      // Read bit 7 (busy bit)
  20.         {                               // If high
  21.                 E_PIN = 0;              // Reset clock line
  22.                 RW_PIN = 0;             // Reset control line
  23.                 return 1;               // Return TRUE
  24.         }
  25.         else                            // Bit 7 low
  26.         {
  27.                 E_PIN = 0;              // Reset clock line
  28.                 RW_PIN = 0;             // Reset control line
  29.                 return 0;               // Return FALSE
  30.         }
  31. #else                                   // 4-bit interface
  32. #ifdef UPPER                            // Upper nibble interface
  33.         if(DATA_PORT&0x80)
  34. #else                                   // Lower nibble interface
  35.         if(DATA_PORT&0x08)
  36. #endif
  37.         {
  38.                 E_PIN = 0;              // Reset clock line
  39.                 DelayFor18TCY();
  40.                 E_PIN = 1;              // Clock out other nibble
  41.                 DelayFor18TCY();
  42.                 E_PIN = 0;
  43.                 RW_PIN = 0;             // Reset control line
  44.                 return 1;               // Return TRUE
  45.         }
  46.         else                            // Busy bit is low
  47.         {
  48.                 E_PIN = 0;              // Reset clock line
  49.                 DelayFor18TCY();
  50.                 E_PIN = 1;              // Clock out other nibble
  51.                 DelayFor18TCY();
  52.                 E_PIN = 0;
  53.                 RW_PIN = 0;             // Reset control line
  54.                 return 0;               // Return FALSE
  55.         }
  56. #endif
  57. }
Código: C
  1. #include <p18cxxx.h>
  2. #include "delays.h"
  3. #include <xlcd.h>
  4.  
  5. /********************************************************************
  6. *       Function Name:  OpenXLCD                                    *
  7. *       Return Value:   void                                        *
  8. *       Parameters:     lcdtype: sets the type of LCD (lines)       *
  9. *       Description:    This routine configures the LCD. Based on   *
  10. *                       the Hitachi HD44780 LCD controller. The     *
  11. *                       routine will configure the I/O pins of the  *
  12. *                       microcontroller, setup the LCD for 4- or    *
  13. *                       8-bit mode and clear the display. The user  *
  14. *                       must provide three delay routines:          *
  15. *                       DelayFor18TCY() provides a 18 Tcy delay     *
  16. *                       DelayPORXLCD() provides at least 15ms delay *
  17. *                       DelayXLCD() provides at least 5ms delay     *
  18. ********************************************************************/
  19. void OpenXLCD(unsigned char lcdtype)
  20. {
  21.         // The data bits must be either a 8-bit port or the upper or
  22.         // lower 4-bits of a port. These pins are made into inputs
  23. #ifdef BIT8                             // 8-bit mode, use whole port
  24.         DATA_PORT = 0;
  25.         TRIS_DATA_PORT = 0x00;
  26. #else                                   // 4-bit mode
  27. #ifdef UPPER                            // Upper 4-bits of the port
  28.         DATA_PORT &= 0x0f;
  29.         TRIS_DATA_PORT &= 0x0F;
  30. #else                                   // Lower 4-bits of the port
  31.         DATA_PORT &= 0xf0;
  32.         TRIS_DATA_PORT &= 0xF0;
  33. #endif
  34. #endif
  35.         TRIS_RW = 0;                    // All control signals made outputs
  36.         TRIS_RS = 0;
  37.         TRIS_E = 0;
  38.         RW_PIN = 0;                     // R/W pin made low
  39.         RS_PIN = 0;                     // Register select pin made low
  40.         E_PIN = 0;                      // Clock pin made low
  41.  
  42.         // Delay for 15ms to allow for LCD Power on reset
  43.         DelayPORXLCD();
  44.  //-------------------reset procedure through software----------------------      
  45.                  WriteCmdXLCD(0x30);
  46.                         Delay10KTCYx(0x05);
  47.  
  48.                  WriteCmdXLCD(0x30);
  49.                         Delay10KTCYx(0x01);
  50.  
  51.  
  52.                  WriteCmdXLCD(0x32);
  53.                 while( BusyXLCD() );
  54. //------------------------------------------------------------------------------------------
  55.  
  56.  
  57.         // Set data interface width, # lines, font
  58.         while(BusyXLCD());              // Wait if LCD busy
  59.         WriteCmdXLCD(lcdtype);          // Function set cmd
  60.  
  61.         // Turn the display on then off
  62.         while(BusyXLCD());              // Wait if LCD busy
  63.         WriteCmdXLCD(DOFF&CURSOR_OFF&BLINK_OFF);        // Display OFF/Blink OFF
  64.         while(BusyXLCD());              // Wait if LCD busy
  65.         WriteCmdXLCD(DON&CURSOR_ON&BLINK_ON);           // Display ON/Blink ON
  66.  
  67.         // Clear display
  68.         while(BusyXLCD());              // Wait if LCD busy
  69.         WriteCmdXLCD(0x01);             // Clear display
  70.  
  71.         // Set entry mode inc, no shift
  72.         while(BusyXLCD());              // Wait if LCD busy
  73.         WriteCmdXLCD(SHIFT_CUR_LEFT);   // Entry Mode
  74.  
  75.         // Set DD Ram address to 0
  76.         while(BusyXLCD());              // Wait if LCD busy
  77.         SetDDRamAddr(0x80);                // Set Display data ram address to 0
  78.  
  79.         return;
  80. }
Código: C
  1. #include <p18cxxx.h>
  2. #include <xlcd.h>
  3.  
  4. /********************************************************************
  5. *       Function Name:  putrsXLCD
  6. *       Return Value:   void
  7. *       Parameters:     buffer: pointer to string
  8. *       Description:    This routine writes a string of bytes to the
  9. *                       Hitachi HD44780 LCD controller. The user
  10. *                       must check to see if the LCD controller is
  11. *                       busy before calling this routine. The data
  12. *                       is written to the character generator RAM or
  13. *                       the display data RAM depending on what the
  14. *                       previous SetxxRamAddr routine was called.
  15. ********************************************************************/
  16. void putrsXLCD(const char *buffer)
  17. {
  18.         while(*buffer)                  // Write data to LCD up to null
  19.         {
  20.                 while(BusyXLCD());      // Wait while LCD is busy
  21.                 WriteDataXLCD(*buffer); // Write character to LCD
  22.                 buffer++;               // Increment buffer
  23.         }
  24.         return;
  25. }
Código: C
  1. #include <p18cxxx.h>
  2. #include <xlcd.h>
  3.  
  4. /********************************************************************
  5. *       Function Name:  putsXLCD
  6. *       Return Value:   void
  7. *       Parameters:     buffer: pointer to string
  8. *       Description:    This routine writes a string of bytes to the
  9. *                       Hitachi HD44780 LCD controller. The user
  10. *                       must check to see if the LCD controller is
  11. *                       busy before calling this routine. The data
  12. *                       is written to the character generator RAM or
  13. *                       the display data RAM depending on what the
  14. *                       previous SetxxRamAddr routine was called.
  15. ********************************************************************/
  16. void putsXLCD(char *buffer)
  17. {
  18.         while(*buffer)                  // Write data to LCD up to null
  19.         {
  20.                 while(BusyXLCD());      // Wait while LCD is busy
  21.                 WriteDataXLCD(*buffer); // Write character to LCD
  22.                 buffer++;               // Increment buffer
  23.         }
  24.         return;
  25. }
Código: C
  1. include <p18cxxx.h>
  2. #include <xlcd.h>
  3.  
  4. /*********************************************************************
  5. *       Function Name:  ReadAddrXLCD                                 *
  6. *       Return Value:   char: address from LCD controller            *
  7. *       Parameters:     void                                         *
  8. *       Description:    This routine reads an address byte from the  *
  9. *                       Hitachi HD44780 LCD controller. The user     *
  10. *                       must check to see if the LCD controller is   *
  11. *                       busy before calling this routine. The address*
  12. *                       is read from the character generator RAM or  *
  13. *                       the display data RAM depending on what the   *
  14. *                       previous SetxxRamAddr routine was called.    *
  15. *********************************************************************/
  16. unsigned char ReadAddrXLCD(void)
  17. {
  18.         char data;                      // Holds the data retrieved from the LCD
  19.  
  20. #ifdef BIT8                             // 8-bit interface
  21.         RW_PIN = 1;                     // Set control bits for the read
  22.         RS_PIN = 0;
  23.         DelayFor18TCY();
  24.         E_PIN = 1;                      // Clock data out of the LCD controller
  25.         DelayFor18TCY();
  26.         data = DATA_PORT;               // Save the data in the register
  27.         E_PIN = 0;
  28.         RW_PIN = 0;                     // Reset the control bits
  29. #else                                   // 4-bit interface
  30.         RW_PIN = 1;                     // Set control bits for the read
  31.         RS_PIN = 0;
  32.         DelayFor18TCY();
  33.         E_PIN = 1;                      // Clock data out of the LCD controller
  34.         DelayFor18TCY();
  35. #ifdef UPPER                            // Upper nibble interface
  36.         data = DATA_PORT&0xf0;          // Read the nibble into the upper nibble of data
  37. #else                                   // Lower nibble interface
  38.         data = (DATA_PORT<<4)&0xf0;     // Read the nibble into the upper nibble of data
  39. #endif
  40.         E_PIN = 0;                      // Reset the clock
  41.         DelayFor18TCY();
  42.         E_PIN = 1;                      // Clock out the lower nibble
  43.         DelayFor18TCY();
  44. #ifdef UPPER                            // Upper nibble interface
  45.         data |= (DATA_PORT>>4)&0x0f;    // Read the nibble into the lower nibble of data
  46. #else                                   // Lower nibble interface
  47.         data |= DATA_PORT&0x0f;         // Read the nibble into the lower nibble of data
  48. #endif
  49.         E_PIN = 0;
  50.         RW_PIN = 0;                     // Reset the control lines
  51. #endif
  52.         return (data&0x7f);             // Return the address, Mask off the busy bit
  53. }
Código: C
  1. #include <p18cxxx.h>
  2. #include <xlcd.h>
  3.  
  4. /********************************************************************
  5. *       Function Name:  ReadDataXLCD                                *
  6. *       Return Value:   char: data byte from LCD controller         *
  7. *       Parameters:     void                                        *
  8. *       Description:    This routine reads a data byte from the     *
  9. *                       Hitachi HD44780 LCD controller. The user    *
  10. *                       must check to see if the LCD controller is  *
  11. *                       busy before calling this routine. The data  *
  12. *                       is read from the character generator RAM or *
  13. *                       the display data RAM depending on what the  *
  14. *                       previous SetxxRamAddr routine was called.   *
  15. ********************************************************************/
  16. char ReadDataXLCD(void)
  17. {
  18.         char data;
  19.  
  20. #ifdef BIT8                             // 8-bit interface
  21.         RS_PIN = 1;                     // Set the control bits
  22.         RW_PIN = 1;
  23.         DelayFor18TCY();
  24.         E_PIN = 1;                      // Clock the data out of the LCD
  25.         DelayFor18TCY();
  26.         data = DATA_PORT;               // Read the data
  27.         E_PIN = 0;
  28.         RS_PIN = 0;                     // Reset the control bits
  29.         RW_PIN = 0;
  30. #else                                   // 4-bit interface
  31.         RW_PIN = 1;
  32.         RS_PIN = 1;
  33.         DelayFor18TCY();
  34.         E_PIN = 1;                      // Clock the data out of the LCD
  35.         DelayFor18TCY();
  36. #ifdef UPPER                            // Upper nibble interface
  37.         data = DATA_PORT&0xf0;          // Read the upper nibble of data
  38. #else                                   // Lower nibble interface
  39.         data = (DATA_PORT<<4)&0xf0;     // read the upper nibble of data
  40. #endif
  41.         E_PIN = 0;                      // Reset the clock line
  42.         DelayFor18TCY();
  43.         E_PIN = 1;                      // Clock the next nibble out of the LCD
  44.         DelayFor18TCY();
  45. #ifdef UPPER                            // Upper nibble interface
  46.         data |= (DATA_PORT>>4)&0x0f;    // Read the lower nibble of data
  47. #else                                   // Lower nibble interface
  48.         data |= DATA_PORT&0x0f;         // Read the lower nibble of data
  49. #endif
  50.         E_PIN = 0;                                      
  51.         RS_PIN = 0;                     // Reset the control bits
  52.         RW_PIN = 0;
  53. #endif
  54.         return(data);                   // Return the data byte
  55. }
Código: C
  1. #include <p18cxxx.h>
  2. #include <xlcd.h>
  3.  
  4. /********************************************************************
  5. *       Function Name:  SetCGRamAddr                                *
  6. *       Return Value:   void                                        *
  7. *       Parameters:     CGaddr: character generator ram address     *
  8. *       Description:    This routine sets the character generator   *
  9. *                       address of the Hitachi HD44780 LCD          *
  10. *                       controller. The user must check to see if   *
  11. *                       the LCD controller is busy before calling   *
  12. *                       this routine.                               *
  13. ********************************************************************/
  14. void SetCGRamAddr(unsigned char CGaddr)
  15. {
  16. #ifdef BIT8                                     // 8-bit interface
  17.         TRIS_DATA_PORT = 0;                     // Make data port ouput
  18.         DATA_PORT = CGaddr | 0b01000000;        // Write cmd and address to port
  19.         RW_PIN = 0;                             // Set control signals
  20.         RS_PIN = 0;
  21.         DelayFor18TCY();
  22.         E_PIN = 1;                              // Clock cmd and address in
  23.         DelayFor18TCY();
  24.         E_PIN = 0;
  25.         DelayFor18TCY();
  26.         TRIS_DATA_PORT = 0xff;                  // Make data port inputs
  27. #else                                           // 4-bit interface
  28. #ifdef UPPER                                    // Upper nibble interface
  29.         TRIS_DATA_PORT &= 0x0f;                 // Make nibble input
  30.         DATA_PORT &= 0x0f;                      // and write upper nibble
  31.         DATA_PORT |= ((CGaddr | 0b01000000) & 0xf0);
  32. #else                                           // Lower nibble interface
  33.         TRIS_DATA_PORT &= 0xf0;                 // Make nibble input
  34.         DATA_PORT &= 0xf0;                      // and write upper nibble
  35.         DATA_PORT |= (((CGaddr |0b01000000)>>4) & 0x0f);
  36. #endif
  37.         RW_PIN = 0;                             // Set control signals
  38.         RS_PIN = 0;
  39.         DelayFor18TCY();
  40.         E_PIN = 1;                              // Clock cmd and address in
  41.         DelayFor18TCY();
  42.         E_PIN = 0;
  43. #ifdef UPPER                                    // Upper nibble interface
  44.         DATA_PORT &= 0x0f;                      // Write lower nibble
  45.         DATA_PORT |= ((CGaddr<<4)&0xf0);
  46. #else                                           // Lower nibble interface
  47.         DATA_PORT &= 0xf0;                      // Write lower nibble
  48.         DATA_PORT |= (CGaddr&0x0f);
  49. #endif
  50.         DelayFor18TCY();
  51.         E_PIN = 1;                              // Clock cmd and address in
  52.         DelayFor18TCY();
  53.         E_PIN = 0;
  54. #ifdef UPPER                                    // Upper nibble interface
  55.         TRIS_DATA_PORT |= 0xf0;                 // Make inputs
  56. #else                                           // Lower nibble interface
  57.         TRIS_DATA_PORT |= 0x0f;                 // Make inputs
  58. #endif
  59. #endif
  60.         return;
  61. }
Código: C
  1. #include <p18cxxx.h>
  2. #include <xlcd.h>
  3.  
  4. /********************************************************************
  5. *       Function Name:  SetDDRamAddr                                *
  6. *       Return Value:   void                                        *
  7. *       Parameters:     CGaddr: display data address                *
  8. *       Description:    This routine sets the display data address  *
  9. *                       of the Hitachi HD44780 LCD controller. The  *
  10. *                       user must check to see if the LCD controller*
  11. *                       is busy before calling this routine.        *
  12. ********************************************************************/
  13. void SetDDRamAddr(unsigned char DDaddr)
  14. {
  15. #ifdef BIT8                                     // 8-bit interface
  16.         TRIS_DATA_PORT = 0;                     // Make port output
  17.         DATA_PORT = DDaddr | 0b10000000;        // Write cmd and address to port
  18.         RW_PIN = 0;                             // Set the control bits
  19.         RS_PIN = 0;
  20.         DelayFor18TCY();
  21.         E_PIN = 1;                              // Clock the cmd and address in
  22.         DelayFor18TCY();
  23.         E_PIN = 0;
  24.         DelayFor18TCY();
  25.         TRIS_DATA_PORT = 0xff;                  // Make port input
  26. #else                                           // 4-bit interface
  27. #ifdef UPPER                                    // Upper nibble  interface
  28.         TRIS_DATA_PORT &= 0x0f;                 // Make port output
  29.         DATA_PORT &= 0x0f;                      // and write upper nibble
  30.         DATA_PORT |= ((DDaddr | 0b10000000) & 0xf0);
  31. #else                                           // Lower nibble interface
  32.         TRIS_DATA_PORT &= 0xf0;                 // Make port output
  33.         DATA_PORT &= 0xf0;                      // and write upper nibble
  34.         DATA_PORT |= (((DDaddr | 0b10000000)>>4) & 0x0f);
  35. #endif
  36.         RW_PIN = 0;                             // Set control bits
  37.         RS_PIN = 0;
  38.         DelayFor18TCY();
  39.         E_PIN = 1;                              // Clock the cmd and address in
  40.         DelayFor18TCY();
  41.         E_PIN = 0;
  42. #ifdef UPPER                                    // Upper nibble interface
  43.         DATA_PORT &= 0x0f;                      // Write lower nibble
  44.         DATA_PORT |= ((DDaddr<<4)&0xf0);
  45. #else                                           // Lower nibble interface
  46.         DATA_PORT &= 0xf0;                      // Write lower nibble
  47.         DATA_PORT |= (DDaddr&0x0f);
  48. #endif
  49.         DelayFor18TCY();
  50.         E_PIN = 1;                              // Clock the cmd and address in
  51.         DelayFor18TCY();
  52.         E_PIN = 0;
  53. #ifdef UPPER                                    // Upper nibble interface
  54.         TRIS_DATA_PORT |= 0xf0;                 // Make port input
  55. #else                                           // Lower nibble interface
  56.         TRIS_DATA_PORT |= 0x0f;                 // Make port input
  57. #endif
  58. #endif
  59.         return;
  60. }
Código: C
  1. #include <p18cxxx.h>
  2. #include <xlcd.h>
  3.  
  4. /********************************************************************
  5. *       Function Name:  WriteCmdXLCD                                *
  6. *       Return Value:   void                                        *
  7. *       Parameters:     cmd: command to send to LCD                 *
  8. *       Description:    This routine writes a command to the Hitachi*
  9. *                       HD44780 LCD controller. The user must check *
  10. *                       to see if the LCD controller is busy before *
  11. *                       calling this routine.                       *
  12. ********************************************************************/
  13. void WriteCmdXLCD(unsigned char cmd)
  14. {
  15. #ifdef BIT8                             // 8-bit interface
  16.         TRIS_DATA_PORT = 0;             // Data port output
  17.         DATA_PORT = cmd;                // Write command to data port
  18.         RW_PIN = 0;                     // Set the control signals
  19.         RS_PIN = 0;                     // for sending a command
  20.         DelayFor18TCY();
  21.         E_PIN = 1;                      // Clock the command in
  22.         DelayFor18TCY();
  23.         E_PIN = 0;
  24.         DelayFor18TCY();
  25.         TRIS_DATA_PORT = 0xff;          // Data port input
  26. #else                                   // 4-bit interface
  27. #ifdef UPPER                            // Upper nibble interface
  28.         TRIS_DATA_PORT &= 0x0f;
  29.         DATA_PORT &= 0x0f;
  30.         DATA_PORT |= cmd&0xf0;
  31. #else                                   // Lower nibble interface
  32.         TRIS_DATA_PORT &= 0xf0;
  33.         DATA_PORT &= 0xf0;
  34.         DATA_PORT |= (cmd>>4)&0x0f;
  35. #endif
  36.         RW_PIN = 0;                     // Set control signals for command
  37.         RS_PIN = 0;
  38.         DelayFor18TCY();
  39.         E_PIN = 1;                      // Clock command in
  40.         DelayFor18TCY();
  41.         E_PIN = 0;
  42. #ifdef UPPER                            // Upper nibble interface
  43.         DATA_PORT &= 0x0f;
  44.         DATA_PORT |= (cmd<<4)&0xf0;
  45. #else                                   // Lower nibble interface
  46.         DATA_PORT &= 0xf0;
  47.         DATA_PORT |= cmd&0x0f;
  48. #endif
  49.         DelayFor18TCY();
  50.         E_PIN = 1;                      // Clock command in
  51.         DelayFor18TCY();
  52.         E_PIN = 0;
  53. #ifdef UPPER                            // Make data nibble input
  54.         TRIS_DATA_PORT |= 0xf0;
  55. #else
  56.         TRIS_DATA_PORT |= 0x0f;
  57. #endif
  58. #endif
  59.         return;
  60. }
Código: C
  1. #include <p18cxxx.h>
  2. #include <xlcd.h>
  3.  
  4. /********************************************************************
  5. *       Function Name:  WriteDataXLCD                               *
  6. *       Return Value:   void                                        *
  7. *       Parameters:     data: data byte to be written to LCD        *
  8. *       Description:    This routine writes a data byte to the      *
  9. *                       Hitachi HD44780 LCD controller. The user    *
  10. *                       must check to see if the LCD controller is  *
  11. *                       busy before calling this routine. The data  *
  12. *                       is written to the character generator RAM or*
  13. *                       the display data RAM depending on what the  *
  14. *                       previous SetxxRamAddr routine was called.   *
  15. ********************************************************************/
  16. void WriteDataXLCD(char data)
  17. {
  18. #ifdef BIT8                             // 8-bit interface
  19.         TRIS_DATA_PORT = 0;             // Make port output
  20.         DATA_PORT = data;               // Write data to port
  21.         RS_PIN = 1;                     // Set control bits
  22.         RW_PIN = 0;
  23.         DelayFor18TCY();
  24.         E_PIN = 1;                      // Clock data into LCD
  25.         DelayFor18TCY();
  26.         E_PIN = 0;
  27.         RS_PIN = 0;                     // Reset control bits
  28.         TRIS_DATA_PORT = 0xff;          // Make port input
  29. #else                                   // 4-bit interface
  30. #ifdef UPPER                            // Upper nibble interface
  31.         TRIS_DATA_PORT &= 0x0f;
  32.         DATA_PORT &= 0x0f;
  33.         DATA_PORT |= data&0xf0;
  34. #else                                   // Lower nibble interface
  35.         TRIS_DATA_PORT &= 0xf0;
  36.         DATA_PORT &= 0xf0;
  37.         DATA_PORT |= ((data>>4)&0x0f);
  38. #endif
  39.         RS_PIN = 1;                     // Set control bits
  40.         RW_PIN = 0;
  41.         DelayFor18TCY();
  42.         E_PIN = 1;                      // Clock nibble into LCD
  43.         DelayFor18TCY();
  44.         E_PIN = 0;
  45. #ifdef UPPER                            // Upper nibble interface
  46.         DATA_PORT &= 0x0f;
  47.         DATA_PORT |= ((data<<4)&0xf0);
  48. #else                                   // Lower nibble interface
  49.         DATA_PORT &= 0xf0;
  50.         DATA_PORT |= (data&0x0f);
  51. #endif
  52.         DelayFor18TCY();
  53.         E_PIN = 1;                      // Clock nibble into LCD
  54.         DelayFor18TCY();
  55.         E_PIN = 0;
  56. #ifdef UPPER                            // Upper nibble interface
  57.         TRIS_DATA_PORT |= 0xf0;
  58. #else                                   // Lower nibble interface
  59.         TRIS_DATA_PORT |= 0x0f;
  60. #endif
  61. #endif
  62.         return;
  63. }
Todos somos muy ignorantes. Lo que ocurre es que no todos ignoramos las mismas cosas.

Desconectado elgarbe

  • Moderadores
  • PIC24H
  • *****
  • Mensajes: 2178
Re:Visualizar voltaje en Lcd
« Respuesta #27 en: 04 de Febrero de 2016, 20:11:29 »
Mi primerera duda era que si en 5 caracteres entran lodos los datos más el '\0' y si la funcion sprinf pone ese caracter 'null', porque la funcion lo necesita:

Código: C
  1. void putrsXLCD(const char *buffer)
  2. {
  3.         while(*buffer)                  // Write data to LCD up to null
  4.         {
  5.                 while(BusyXLCD());      // Wait while LCD is busy
  6.                 WriteDataXLCD(*buffer); // Write character to LCD
  7.                 buffer++;               // Increment buffer
  8.         }
  9.         return;
  10. }

Quizá si la tension es 9.10 entra el \0, pero si la tension es 10.23 no entra en el buffer. Por eso sugería aumentarlo a 6.

Saludos!
-
Leonardo Garberoglio

Desconectado KILLERJC

  • Colaborador
  • DsPIC33
  • *****
  • Mensajes: 8242
Re:Visualizar voltaje en Lcd
« Respuesta #28 en: 04 de Febrero de 2016, 20:24:53 »
Citar
sprintf
int sprintf ( char * str, const char * format, ... );
Write formatted data to string
Composes a string with the same text that would be printed if format was used on printf, but instead of being printed, the content is stored as a C string in the buffer pointed by str.

The size of the buffer should be large enough to contain the entire resulting string (see snprintf for a safer version).

A terminating null character is automatically appended after the content.

Mirando el codigo parece todo correcto. Si

DelayFor18TCY();

es exactamente 18 TCY, a 48Mhz son 1.5us, suficiente como el enable que solo pide un ciclo completo 1us a 3.3V o 500ns a 5V

Lo unico que me llama la atencion es esto:

Citar
*       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

Y las rutinas de demora:

Código: C
  1. void DelayFor18TCY(void)    // Delay MAL lo anterior
  2. {
  3.     Delay10TCYx(2); // 20 TCY = 1.66us , 1TCY = 83.3ns
  4. }
  5. void DelayPORXLCD(void)     //Delay 0,015sec => 15000us => 15ms
  6. {
  7.     Delay1KTCYx(180); //Bien
  8. }
  9. void DelayXLCD(void)        //Delay MAL lo anterior pide 5ms no 2ms
  10. {
  11.     Delay1KTCYx(60);         // 5ms = 60000 TCY
  12. }

Desconectado AngelGris

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 2480
Re:Visualizar voltaje en Lcd
« Respuesta #29 en: 04 de Febrero de 2016, 20:49:56 »
  Por lo visto hay rutinas que sí chequean si está ocupado el LCD mientras que otras no chequean. Seguramente por allí vendrá el problema
De vez en cuando la vida
nos besa en la boca
y a colores se despliega
como un atlas


 

anything