Autor Tema: Libreria LCD & MPLAB X  (Leído 6894 veces)

0 Usuarios y 2 Visitantes están viendo este tema.

Desconectado neptune

  • PIC10
  • *
  • Mensajes: 2
Libreria LCD & MPLAB X
« en: 08 de Mayo de 2012, 22:32:04 »
Aca me veo bajo la necesidad de modificar el mensaje. Hice compilar al programa pero no funcionar en conjuntamente con Proteus  :)
El error que tenia era el "path" de las librerias, por suerte MPLAB X me ayudo a solucionarlo  ;-)
Ahora el drama es que no logro hacer que se muestre el texto en la simulacion con Proteus. Se ve que los puertos cambian de high-to-low y viceversa pero no se muestra nada...
Aca les paso las librerias que estoy usando y mi programa. Es un poco extenso pero posteo todo asi despues no me retan que falta ago :P

Saludos!

Source Files:
main.c
Código: C
  1. #include <pic16f877a.h>
  2. #include <pic.h>
  3. #include <htc.h>
  4. #include "../libs/lcd_lib.h"
  5. #include "../libs/delay_lib.h"
  6.  
  7. //Watchdog Timer OFF, Oscilador a cristal, Power-on Timer OFF
  8. __CONFIG( WDTE_OFF & FOSC_XT & PWRTE_OFF);
  9.  
  10. void main()
  11. {
  12.     TRISA = 0;                  //Puerto A como salida
  13.     TRISB = 0;                  //Puerto B como salida
  14.     lcd_init();                 //Inicializo LCD
  15.     lcd_clear();                //Limpio el LCD
  16.     while(1)
  17.     lcd_write("Hola mundo!");
  18. }


Header Files:
delay_lib.h
Código: C
  1. #ifndef XTAL_FREQ
  2.  #define XTAL_FREQ 4MHZ /* Crystal frequency in MHz */
  3.  #endif
  4.  
  5. #define MHZ *1000L /* number of kHz in a MHz */
  6.  #define KHZ *1 /* number of kHz in a kHz */
  7.  
  8. #if XTAL_FREQ >= 12MHZ
  9.  
  10. #define DelayUs(x) { unsigned char _dcnt; \
  11.  _dcnt = (x)*((XTAL_FREQ)/(12MHZ)); \
  12.  while(--_dcnt != 0) \
  13.  continue; }
  14.  #else
  15.  
  16. #define DelayUs(x) { unsigned char _dcnt; \
  17.  _dcnt = (x)/((12MHZ)/(XTAL_FREQ))|1; \
  18.  while(--_dcnt != 0) \
  19.  continue; }
  20.  #endif
  21.  
  22. extern void DelayMs(unsigned char);

lcd_lib.h
Código: C
  1. extern void lcd_write(unsigned char);       //Write a byte to the LCD in 4 bit mode
  2. extern void lcd_clear(void);                //Clear and home the LCD
  3. extern void lcd_puts(const char * s);       //Write a string of chars to the LCD
  4. extern void lcd_goto(unsigned char pos);    //Go to the specified position
  5. extern void lcd_putch(char);                //Write one character to the LCD
  6. extern void lcd_init(void);                 //Initialise the LCD
  7.  
  8.  
  9. /*      Set the cursor position */
  10. /********************************/
  11. #define lcd_cursor(x)   lcd_write(((x)&0x7F)|0x80)
  12. #define LINE1           0x00    /* position of line1 */
  13. #define LINE2           0x40    /* position of line2 */


Important FIles:
delay_lib.c
Código: C
  1. #include "delay_lib.h"
  2.  
  3. void
  4.  DelayMs(unsigned char cnt)
  5.  {
  6.  #if XTAL_FREQ <= 2MHZ
  7.  do {
  8.  DelayUs(996);
  9.  } while(--cnt);
  10.  #endif
  11.  
  12. #if XTAL_FREQ > 2MHZ
  13. unsigned char i;
  14.  do {
  15.  i = 4;
  16.  do {
  17.  DelayUs(250);
  18.  } while(--i);
  19.  } while(--cnt);
  20.  #endif
  21.  }


lcd_lib.c
Código: C
  1. #include    <pic.h>
  2. #include "lcd_lib.h"
  3. #include "delay_lib.h"
  4.  
  5. #define LCD_RS  RA2     // Register select
  6. #define LCD_EN  RA3     // Enable
  7. #define LCD_D4  RB0     // Data bits
  8. #define LCD_D5  RB1     // Data bits
  9. #define LCD_D6  RB2     // Data bits
  10. #define LCD_D7  RB3     // Data bits
  11.  
  12. #define LCD_STROBE      ((LCD_EN = 1),(LCD_EN=0))
  13.  
  14.  
  15. /* Write a byte to the LCD in 4 bit mode */
  16. /*****************************************/
  17. void
  18. lcd_write(unsigned char c)
  19. {
  20.         if(c & 0x80) LCD_D7=1; else LCD_D7=0;
  21.         if(c & 0x40) LCD_D6=1; else LCD_D6=0;
  22.         if(c & 0x20) LCD_D5=1; else LCD_D5=0;
  23.         if(c & 0x10) LCD_D4=1; else LCD_D4=0;
  24.         LCD_STROBE;
  25.         if(c & 0x08) LCD_D7=1; else LCD_D7=0;
  26.         if(c & 0x04) LCD_D6=1; else LCD_D6=0;
  27.         if(c & 0x02) LCD_D5=1; else LCD_D5=0;
  28.         if(c & 0x01) LCD_D4=1; else LCD_D4=0;
  29.         LCD_STROBE;    
  30.         DelayUs(40);
  31. }
  32.  
  33.  
  34.  
  35. /*      Clear and home the LCD           */
  36. /*****************************************/
  37. void
  38. lcd_clear(void)
  39. {
  40.         LCD_RS = 0;
  41.         lcd_write(0x1);
  42.         DelayMs(2);
  43. }
  44.  
  45.  
  46.  
  47. /* Write a string of chars to the LCD    */
  48. /*****************************************/
  49. void
  50. lcd_puts(const char * s)
  51. {
  52.         LCD_RS = 1;     // write characters
  53.         while(*s) lcd_write(*s++);
  54. }
  55.  
  56.  
  57.  
  58. /*    Write one character to the LCD     */
  59. /*****************************************/
  60. void
  61. lcd_putch(unsigned char c)
  62. {
  63.         LCD_RS = 1;     // write characters
  64.         lcd_write(c);
  65. }
  66.  
  67.  
  68.  
  69. /*    Go to the specified position       */
  70. /*****************************************/
  71. void
  72. lcd_goto(unsigned char pos)
  73. {
  74.         LCD_RS = 0;
  75.         lcd_write(0x80 + pos);
  76. }
  77.        
  78.  
  79.  
  80. /*        Initialise the LCD             */
  81. /*****************************************/
  82. void
  83. lcd_init(void)
  84. {
  85.         LCD_RS = 0;             // write control bytes
  86.         DelayMs(15);            // power on delay
  87.         LCD_D4 = 1;             // init!       
  88.         LCD_D5 = 1;             //
  89.         LCD_STROBE;    
  90.         DelayMs(5);
  91.         LCD_STROBE;             // init!       
  92.         DelayUs(100);
  93.         LCD_STROBE;             // init!       
  94.         DelayMs(5);
  95.         LCD_D4 = 0;             // set 4 bit mode
  96.         LCD_STROBE;    
  97.         DelayUs(40);
  98.         lcd_write(0x28);        //4 bit mode, 1/16 duty, 5x8 font, 2lines
  99.         lcd_write(0x0C);        //display on
  100.         lcd_write(0x06);        //entry mode advance cursor
  101.         lcd_write(0x01);        //clear display and reset cursor
  102. }


P.D: Les paso el .RAR con el proyecto en MPLAB X y la simulacion en Proteus al que le interese revisarla, le doy el ok ;)
« Última modificación: 09 de Mayo de 2012, 00:49:52 por neptune »

Desconectado AcoranTf

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 1093
Re: Libreria LDC & MPLAB X
« Respuesta #1 en: 08 de Mayo de 2012, 23:06:33 »
Pues creo que con lo que subiste poco se puede hacer, ya que tus errores los da el main.c y el que pusiste no contienen nada.
Revisalo y pon el main.c bueno.

Saludos.

Desconectado neptune

  • PIC10
  • *
  • Mensajes: 2
Re: Libreria LDC & MPLAB X
« Respuesta #2 en: 08 de Mayo de 2012, 23:08:39 »
Pues creo que con lo que subiste poco se puede hacer, ya que tus errores los da el main.c y el que pusiste no contienen nada.
Revisalo y pon el main.c bueno.

Saludos.


Ups, perdon, ahora corrijo!


 

anything