Autor Tema: LCD escribe lento pic16f819  (Leído 5819 veces)

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

Desconectado Rseliman

  • PIC16
  • ***
  • Mensajes: 239
LCD escribe lento pic16f819
« en: 15 de Mayo de 2013, 16:09:52 »
Hola a todos , estoy probando un LCD estandar 2x16 , use una libreria  que encontre aca en el foro y no puedo lograr que escriba rapido , lo hace en proteus , pero en el protoboard anda lento a tal punto de que se demora como 2 seg para escribir cada caracter ...alguien me da una mano o me recomienda que libreria usar para este pic ??

paso el main y demas


main
Código: [Seleccionar]


#include <xc.h>
#define _XTAL_FREQ 8000000
#include <stdio.h>
#include <stdlib.h>
#include "lcd_pic16.c"
#include "delay.h"

// PIC16F819 Configuration Bit Settings





//variables globales
unsigned char buffer [14];
// unsigned int contador=0;
//funciones prototipo
void init(void);


void main(void)
{

init();


           
SetDDRamAddr(0x00);
putrsXLCD("Ramiro Seliman");
                sprintf(buffer,"%s",1);
                putsXLCD(buffer);
                SetDDRamAddr(0x40+0);
putrsXLCD("Victoria E.R");

        }

void init(void)
{
    ADCON0bits.ADON = 0;

    TRISB=0;    //todo el PORTB como salidas digitales
    PORTB=0;
    OpenXLCD(FOUR_BIT & LINES_5X7 );


}



lcd_pic16.c
Código: [Seleccionar]
/*
 *
 *   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

/* When in 6-10-bit interface comment the #define BUSY_LCD and conected PIN
 * R/W to GND in LCD
 */
 //#define BUSY_LCD

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

/* CTRL_PORT defines the port where the control lines are connected.
 * These are just samples, change to match your application.
 */
 #define RW_PIN   PORTBbits.RB0    /* PORT for RW */
 #define TRIS_RW  TRISBbits.TRISB0    /* TRIS for RW */

 #define RS_PIN   PORTBbits.RB1    /* PORT for RS */
 #define TRIS_RS  TRISBbits.TRISB1    /* TRIS for RS */

 #define E_PIN    PORTBbits.RB2  /* PORT for D  */
 #define TRIS_E   TRISBbits.TRISB2    /* 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 */

#ifdef _OMNI_CODE_
#define PARAM_SCLASS
#else
#define PARAM_SCLASS auto
#endif

/* CLS_Line2
 * Clear Screen Line 2
 */
void CLS_Line2(void);

/* CLS_Line1
 * Clear Screen Line 1
 */
void CLS_Line1(void);
/* OpenXLCD
 * Configures I/O pins for external LCD
 */
void OpenXLCD(PARAM_SCLASS unsigned char);

/* SetCGRamAddr
 * Sets the character generator address
 */
void SetCGRamAddr(PARAM_SCLASS unsigned char);

/* SetDDRamAddr
 * Sets the display data address
 */
void SetDDRamAddr(PARAM_SCLASS unsigned char);

/* BusyXLCD
 * Returns the busy status of the LCD
 */
unsigned char BusyXLCD(void);

/* ReadAddrXLCD
 * Reads the current address
 */
unsigned char ReadAddrXLCD(void);

/* ReadDataXLCD
 * Reads a byte of data
 */
char ReadDataXLCD(void);

/* WriteCmdXLCD
 * Writes a command to the LCD
 */
void WriteCmdXLCD(PARAM_SCLASS unsigned char);

/* WriteDataXLCD
 * Writes a data byte to the LCD
 */
void WriteDataXLCD(PARAM_SCLASS char);

/* putcXLCD
 * A putc is a write
 */
#define putcXLCD WriteDataXLCD

/* putsXLCD
 * Writes a string of characters to the LCD
 */
void putsXLCD(PARAM_SCLASS char *);

/* putrsXLCD
 * Writes a string of characters in  to the LCD
 */
void putrsXLCD(const char *);

// Rutinas de tiempo auxiliares para la libreria XLCD
void DelayFor18TCY(void)
{
__delay_us(18);
}

void DelayPORXLCD(void)
{
__delay_ms(20); //Delay de 15 ms
}

void DelayXLCD(void)
{
__delay_ms(20); //Delay de 20 ms
}

void CLS_Line2(void)
{
    SetDDRamAddr(0x40);
    putrsXLCD("                ");
}

void CLS_Line1(void)
{
    SetDDRamAddr(0x00);
    putrsXLCD("                ");
}
/********************************************************************
*       Function Name:  OpenXLCD                                    *
*       Return Value:   void                                        *
*       Parameters:     lcdtype: sets the type of LCD (lines)       *
*       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(unsigned char lcdtype)
{
        // 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
#ifdef BIT8                             // 8-bit mode, use whole port
        DATA_PORT = 0;
        TRIS_DATA_PORT = 0x00;
#else                                   // 4-bit mode
#ifdef UPPER                            // Upper 4-bits of the port
        DATA_PORT &= 0x0f;
        TRIS_DATA_PORT &= 0x0F;
#else                                   // Lower 4-bits of the port
        DATA_PORT &= 0xf0;
        TRIS_DATA_PORT &= 0xF0;
#endif
#endif
        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
        DelayPORXLCD();
 //-------------------reset procedure through software----------------------       
WriteCmdXLCD(0x30);
__delay_ms(5);

WriteCmdXLCD(0x30);
__delay_ms(1);


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


        // Set data interface width, # lines, font
        while(BusyXLCD());              // Wait if LCD busy
        WriteCmdXLCD(lcdtype);          // Function set cmd

        // Turn the display on then off
        while(BusyXLCD());              // Wait if LCD busy
        WriteCmdXLCD(DOFF&CURSOR_OFF&BLINK_OFF);        // Display OFF/Blink OFF
        while(BusyXLCD());              // Wait if LCD busy
        WriteCmdXLCD(DON&CURSOR_ON&BLINK_ON);           // 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_CUR_RIGHT);   // Entry Mode
 
while(BusyXLCD());              // Wait if LCD busy
        WriteCmdXLCD(0x06);    // Incremente
 
        while(BusyXLCD());              // Wait if LCD busy
        SetDDRamAddr(0x80);             // Set Display data ram address to 0
       
        while(BusyXLCD());              // Wait if LCD busy
        WriteCmdXLCD(CURSOR_OFF);       // Cursor OFF
        return;
}


/********************************************************************
*       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)
{
#ifdef BIT8                             // 8-bit interface
        TRIS_DATA_PORT = 0;             // Make port output
        DATA_PORT = data;               // Write data to port
        RS_PIN = 1;                     // Set control bits
        RW_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock data into LCD
        DelayFor18TCY();
        E_PIN = 0;
        RS_PIN = 0;                     // Reset control bits
        TRIS_DATA_PORT = 0xff;          // Make port input
#else                                   // 4-bit interface
#ifdef UPPER                            // Upper nibble interface
        TRIS_DATA_PORT &= 0x0f;
        DATA_PORT &= 0x0f;
        DATA_PORT |= data&0xf0;
#else                                   // Lower nibble interface
        TRIS_DATA_PORT &= 0xf0;
        DATA_PORT &= 0xf0;
        DATA_PORT |= ((data>>4)&0x0f);
#endif
        RS_PIN = 1;                     // Set control bits
        RW_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock nibble into LCD
        DelayFor18TCY();
        E_PIN = 0;
#ifdef UPPER                            // Upper nibble interface
        DATA_PORT &= 0x0f;
        DATA_PORT |= ((data<<4)&0xf0);
#else                                   // Lower nibble interface
        DATA_PORT &= 0xf0;
        DATA_PORT |= (data&0x0f);
#endif
        DelayFor18TCY();
        E_PIN = 1;                      // Clock nibble into LCD
        DelayFor18TCY();
        E_PIN = 0;
#ifdef UPPER                            // Upper nibble interface
        TRIS_DATA_PORT |= 0xf0;
#else                                   // Lower nibble interface
        TRIS_DATA_PORT |= 0x0f;
#endif
#endif
        return;
}

/********************************************************************
*       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)
{
#ifdef BIT8                             // 8-bit interface
        TRIS_DATA_PORT = 0;             // Data port output
        DATA_PORT = cmd;                // Write command to data port
        RW_PIN = 0;                     // Set the control signals
        RS_PIN = 0;                     // for sending a command
        DelayFor18TCY();
        E_PIN = 1;                      // Clock the command in
        DelayFor18TCY();
        E_PIN = 0;
        DelayFor18TCY();
        TRIS_DATA_PORT = 0xff;          // Data port input
#else                                   // 4-bit interface
#ifdef UPPER                            // Upper nibble interface
        TRIS_DATA_PORT &= 0x0f;
        DATA_PORT &= 0x0f;
        DATA_PORT |= cmd&0xf0;
#else                                   // Lower nibble interface
        TRIS_DATA_PORT &= 0xf0;
        DATA_PORT &= 0xf0;
        DATA_PORT |= (cmd>>4)&0x0f;
#endif
        RW_PIN = 0;                     // Set control signals for command
        RS_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock command in
        DelayFor18TCY();
        E_PIN = 0;
#ifdef UPPER                            // Upper nibble interface
        DATA_PORT &= 0x0f;
        DATA_PORT |= (cmd<<4)&0xf0;
#else                                   // Lower nibble interface
        DATA_PORT &= 0xf0;
        DATA_PORT |= cmd&0x0f;
#endif
        DelayFor18TCY();
        E_PIN = 1;                      // Clock command in
        DelayFor18TCY();
        E_PIN = 0;
#ifdef UPPER                            // Make data nibble input
        TRIS_DATA_PORT |= 0xf0;
#else
        TRIS_DATA_PORT |= 0x0f;
#endif
#endif
        return;
}

/********************************************************************
*       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)
{
#ifdef BIT8                                     // 8-bit interface
        TRIS_DATA_PORT = 0;                     // Make port output
        DATA_PORT = DDaddr | 0b10000000;        // Write cmd and address to port
        RW_PIN = 0;                             // Set the control bits
        RS_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                              // Clock the cmd and address in
        DelayFor18TCY();
        E_PIN = 0;
        DelayFor18TCY();
        TRIS_DATA_PORT = 0xff;                  // Make port input
#else                                           // 4-bit interface
#ifdef UPPER                                    // Upper nibble  interface
        TRIS_DATA_PORT &= 0x0f;                 // Make port output
        DATA_PORT &= 0x0f;                      // and write upper nibble
        DATA_PORT |= ((DDaddr | 0b10000000) & 0xf0);
#else                                           // Lower nibble interface
        TRIS_DATA_PORT &= 0xf0;                 // Make port output
        DATA_PORT &= 0xf0;                      // and write upper nibble
        DATA_PORT |= (((DDaddr | 0b10000000)>>4) & 0x0f);
#endif
        RW_PIN = 0;                             // Set control bits
        RS_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                              // Clock the cmd and address in
        DelayFor18TCY();
        E_PIN = 0;
#ifdef UPPER                                    // Upper nibble interface
        DATA_PORT &= 0x0f;                      // Write lower nibble
        DATA_PORT |= ((DDaddr<<4)&0xf0);
#else                                           // Lower nibble interface
        DATA_PORT &= 0xf0;                      // Write lower nibble
        DATA_PORT |= (DDaddr&0x0f);
#endif
        DelayFor18TCY();
        E_PIN = 1;                              // Clock the cmd and address in
        DelayFor18TCY();
        E_PIN = 0;
#ifdef UPPER                                    // Upper nibble interface
        TRIS_DATA_PORT |= 0xf0;                 // Make port input
#else                                           // Lower nibble interface
        TRIS_DATA_PORT |= 0x0f;                 // Make port input
#endif
#endif
        return;
}

/********************************************************************
*       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)
{
#ifdef BIT8                                     // 8-bit interface
        TRIS_DATA_PORT = 0;                     // Make data port ouput
        DATA_PORT = CGaddr | 0b01000000;        // Write cmd and address to port
        RW_PIN = 0;                             // Set control signals
        RS_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                              // Clock cmd and address in
        DelayFor18TCY();
        E_PIN = 0;
        DelayFor18TCY();
        TRIS_DATA_PORT = 0xff;                  // Make data port inputs
#else                                           // 4-bit interface
#ifdef UPPER                                    // Upper nibble interface
        TRIS_DATA_PORT &= 0x0f;                 // Make nibble input
        DATA_PORT &= 0x0f;                      // and write upper nibble
        DATA_PORT |= ((CGaddr | 0b01000000) & 0xf0);
#else                                           // Lower nibble interface
        TRIS_DATA_PORT &= 0xf0;                 // Make nibble input
        DATA_PORT &= 0xf0;                      // and write upper nibble
        DATA_PORT |= (((CGaddr |0b01000000)>>4) & 0x0f);
#endif
        RW_PIN = 0;                             // Set control signals
        RS_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                              // Clock cmd and address in
        DelayFor18TCY();
        E_PIN = 0;
#ifdef UPPER                                    // Upper nibble interface
        DATA_PORT &= 0x0f;                      // Write lower nibble
        DATA_PORT |= ((CGaddr<<4)&0xf0);
#else                                           // Lower nibble interface
        DATA_PORT &= 0xf0;                      // Write lower nibble
        DATA_PORT |= (CGaddr&0x0f);
#endif
        DelayFor18TCY();
        E_PIN = 1;                              // Clock cmd and address in
        DelayFor18TCY();
        E_PIN = 0;
#ifdef UPPER                                    // Upper nibble interface
        TRIS_DATA_PORT |= 0xf0;                 // Make inputs
#else                                           // Lower nibble interface
        TRIS_DATA_PORT |= 0x0f;                 // Make inputs
#endif
#endif
        return;
}

/********************************************************************
*       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;

#ifdef BIT8                             // 8-bit interface
        RS_PIN = 1;                     // Set the control bits
        RW_PIN = 1;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock the data out of the LCD
        DelayFor18TCY();
        data = DATA_PORT;               // Read the data
        E_PIN = 0;
        RS_PIN = 0;                     // Reset the control bits
        RW_PIN = 0;
#else                                   // 4-bit interface
        RW_PIN = 1;
        RS_PIN = 1;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock the data out of the LCD
        DelayFor18TCY();
#ifdef UPPER                            // Upper nibble interface
        data = DATA_PORT&0xf0;          // Read the upper nibble of data
#else                                   // Lower nibble interface
        data = (DATA_PORT<<4)&0xf0;     // read the upper nibble of data
#endif
        E_PIN = 0;                      // Reset the clock line
        DelayFor18TCY();
        E_PIN = 1;                      // Clock the next nibble out of the LCD
        DelayFor18TCY();
#ifdef UPPER                            // Upper nibble interface
        data |= (DATA_PORT>>4)&0x0f;    // Read the lower nibble of data
#else                                   // Lower nibble interface
        data |= DATA_PORT&0x0f;         // Read the lower nibble of data
#endif
        E_PIN = 0;                                     
        RS_PIN = 0;                     // Reset the control bits
        RW_PIN = 0;
#endif
        return(data);                   // Return the data byte
}

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

#ifdef BIT8                             // 8-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();
        data = DATA_PORT;               // Save the data in the register
        E_PIN = 0;
        RW_PIN = 0;                     // Reset the control bits
#else                                   // 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();
#ifdef UPPER                            // Upper nibble interface
        data = DATA_PORT&0xf0;          // Read the nibble into the upper nibble of data
#else                                   // Lower nibble interface
        data = (DATA_PORT<<4)&0xf0;     // Read the nibble into the upper nibble of data
#endif
        E_PIN = 0;                      // Reset the clock
        DelayFor18TCY();
        E_PIN = 1;                      // Clock out the lower nibble
        DelayFor18TCY();
#ifdef UPPER                            // Upper nibble interface
        data |= (DATA_PORT>>4)&0x0f;    // Read the nibble into the lower nibble of data
#else                                   // Lower nibble interface
        data |= DATA_PORT&0x0f;         // Read the nibble into the lower nibble of data
#endif
        E_PIN = 0;
        RW_PIN = 0;                     // Reset the control lines
#endif
        return (data&0x7f);             // Return the address, Mask off the busy bit
}

/********************************************************************
*       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;
}

/********************************************************************
*       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  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;
}

/********************************************************************
*       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)
{
#ifdef BUSY_LCD
        RW_PIN = 1;                     // Set the control bits for read
        RS_PIN = 0;
        DelayFor18TCY();
        E_PIN = 1;                      // Clock in the command
        DelayFor18TCY();
#ifdef BIT8                             // 8-bit interface
        if(DATA_PORT&0x80)                      // Read bit 7 (busy bit)
        {                               // If high
                E_PIN = 0;              // Reset clock line
                RW_PIN = 0;             // Reset control line
                return 1;               // Return TRUE
        }
        else                            // Bit 7 low
        {
                E_PIN = 0;              // Reset clock line
                RW_PIN = 0;             // Reset control line
                return 0;               // Return FALSE
        }
#else                                   // 4-bit interface
#ifdef UPPER                            // Upper nibble interface
        if(DATA_PORT&0x80)
#else                                   // Lower nibble interface
        if(DATA_PORT&0x08)
#endif
        {
                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
        }
#endif
#else
        __delay_ms(5);
        return 0;
#endif

}



PIC16F819 Configuration Bit Settings
Código: [Seleccionar]
// PIC16F819 Configuration Bit Settings

#include <xc.h>

// CONFIG
#pragma config FOSC = INTOSCCLK // Oscillator Selection bits (INTRC oscillator; CLKO function on RA6/OSC2/CLKO pin and port I/O function on RA7/OSC1/CLKI pin)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = ON       // Power-up Timer Enable bit (PWRT enabled)
#pragma config MCLRE = OFF       // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is MCLR)
#pragma config BOREN = OFF       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF      // Low-Voltage Programming Enable bit (RB3/PGM pin has PGM function, Low-Voltage Programming enabled)
#pragma config CPD = OFF        // Data EE Memory Code Protection bit (Code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off)
#pragma config CCPMX = RB2      // CCP1 Pin Selection bit (CCP1 function on RB2)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

// CONFIG2
//#pragma config BOR4V = BOR40V   // Brown-out Reset Selection bit (Brown-out Reset set to 4.0V)
#pragma config WRT = OFF        // Flash Program Memory Self Write Enable
Las Grandes Obras las sueñan los grandes locos , mientras los inutiles las critican !!

Desconectado AleSergi

  • PIC16
  • ***
  • Mensajes: 214
Re: LCD escribe lento pic16f819
« Respuesta #1 en: 15 de Mayo de 2013, 16:17:37 »
eh!, y que compilador de C estas empleando? esa data es importante...

Desconectado Rseliman

  • PIC16
  • ***
  • Mensajes: 239
Re: LCD escribe lento pic16f819
« Respuesta #2 en: 15 de Mayo de 2013, 16:25:38 »
eh!, y que compilador de C estas empleando? esa data es importante...


Uhhhh mil perdones me lo comi !!!! estoy usando mplabx y xc8

Gracias
Las Grandes Obras las sueñan los grandes locos , mientras los inutiles las critican !!

Desconectado reiniertl

  • Moderadores
  • PIC24H
  • *****
  • Mensajes: 1187
Re: LCD escribe lento pic16f819
« Respuesta #3 en: 15 de Mayo de 2013, 16:36:45 »
Yo apuesto por una configuración incorrecta de los fuses de modo que el ciclo de máquina no va como se supone. Así cuando la rutina de la LCD hace llamadas a las funciones de demora se demoran mucho más porque parten de tener un reloj de 8MHz cuando en realidad el micro debe ir a algunos kHz.

Revisa cuando grabes el micro que en realidad se ha configurado correctamente el módulo de reloj y que además el micro está trabajando a la frecuencia especificada. Si la diferencia es muy alta bastará con poner a cambiar de estado un pin del micro y colocar un frecuencímetro u osciloscopio a ver si te da un tren de pulsos de la frecuencia especificada. Es la forma directa y simple que utilizo para detectar un fallo de temporización.

un saludo
Reinier

Desconectado jukinch

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 608
Re: LCD escribe lento pic16f819
« Respuesta #4 en: 15 de Mayo de 2013, 18:25:45 »
Hola a todos.

Rseliman:
Debés controlar como te ha dicho reiniertl cual es la verdadera frecuencia de trabajo que está funcionando tu pic. Y luego modificar con el valor correcto el valor de _XTAL_FREQ.

#define _XTAL_FREQ 8000000 // - CUIDADO - esta línea no configura la frecuencia de trabajo del cpu. Sólo es un dato para los cálculos en los retardos.-

la siguiente línea es la que hace la selección del modo de trabajo con oscilador interno.
#pragma config FOSC = INTOSCCLK // Oscillator Selection bits (INTRC oscillator; CLKO function on RA6/OSC2/CLKO pin and port I/O function on RA7/OSC1/CLKI pin)

luego dentro de main debes configurar los bits correspondientes para seleccionar la frecuencia de trabajo. Si no seteás los bits correspondientes el pic utiliza los bits con la configuración por defecto. Y en este caso si mi lectura del datasheet (http://ww1.microchip.com/downloads/en/DeviceDoc/39598F.pdf página 14) no ha fallado sería de 31.25 kHz.- (valor por defecto 000)
Debés cambiar los valores de los bits del registro OSCCON a 111 dentro de main. ((pág. 18).-


meté esto dentro de main antes de init().


// cambiamos la frecuencia del oscilador interno a 8mhz mediante los bits
// del registro OSCCON
    OSCCONbits.IRCF2 = 1;
    OSCCONbits.IRCF1 = 1;
    OSCCONbits.IRCF0 = 1;



       Saludos.
             Jukinch
"Divide las dificultades que examinas en tantas partes como sea posible para su mejor solución." -René Descartes

Desconectado Rseliman

  • PIC16
  • ***
  • Mensajes: 239
Re: LCD escribe lento pic16f819
« Respuesta #5 en: 15 de Mayo de 2013, 18:31:32 »
Hola a todos.

Rseliman:
Debés controlar como te ha dicho reiniertl cual es la verdadera frecuencia de trabajo que está funcionando tu pic. Y luego modificar con el valor correcto el valor de _XTAL_FREQ.

#define _XTAL_FREQ 8000000 // - CUIDADO - esta línea no configura la frecuencia de trabajo del cpu. Sólo es un dato para los cálculos en los retardos.-

la siguiente línea es la que hace la selección del modo de trabajo con oscilador interno.
#pragma config FOSC = INTOSCCLK // Oscillator Selection bits (INTRC oscillator; CLKO function on RA6/OSC2/CLKO pin and port I/O function on RA7/OSC1/CLKI pin)

luego dentro de main debes configurar los bits correspondientes para seleccionar la frecuencia de trabajo. Si no seteás los bits correspondientes el pic utiliza los bits con la configuración por defecto. Y en este caso si mi lectura del datasheet (http://ww1.microchip.com/downloads/en/DeviceDoc/39598F.pdf página 14) no ha fallado sería de 31.25 kHz.- (valor por defecto 000)
Debés cambiar los valores de los bits del registro OSCCON a 111 dentro de main. ((pág. 18).-


meté esto dentro de main antes de init().


// cambiamos la frecuencia del oscilador interno a 8mhz mediante los bits
// del registro OSCCON
    OSCCONbits.IRCF2 = 1;
    OSCCONbits.IRCF1 = 1;
    OSCCONbits.IRCF0 = 1;



       Saludos.
             Jukinch



Muchas gracias Jukinch ...desp de la respuesta anterior pense en meterle el frecuencimetro , pero se me dio por revisar mejor el datasheets ...y si tal cual es lo que vos decis ....es distinto este pic a otros ...ahora estoy en el trabajo , pero claro por default esta en 000 y claro eso es creo que 32 khz ....andaba a kerossene el pobre ...jajaja

Muchas gracias  al las dos respuestas

Un Abrazo
Las Grandes Obras las sueñan los grandes locos , mientras los inutiles las critican !!

Desconectado Rseliman

  • PIC16
  • ***
  • Mensajes: 239
Re: LCD escribe lento pic16f819
« Respuesta #6 en: 18 de Mayo de 2013, 16:52:14 »
Buenas !!! una pregunta mas ....en el mismo pic ...16f819 , puedo usar el PORTA en Lugar del B ...intento cambiar pero no me funciona y no me doy cuenta porque ...

en lcd_pic16.c cambio todo al port A ...es asi ??? y porsupuesto en el main tambien ..

Muchas gracias
Las Grandes Obras las sueñan los grandes locos , mientras los inutiles las critican !!

Desconectado AleSergi

  • PIC16
  • ***
  • Mensajes: 214
Re: LCD escribe lento pic16f819
« Respuesta #7 en: 18 de Mayo de 2013, 17:33:17 »
Supongo que lo queres hacer en el XC, pues no te podre ayudar porque o conozco ese compilador, (no me anda...ggrrrrrr), lo que si te recuerdo que el pin #5 PORTA del micro 16F819, cuando no es Master Clear (Reset dicen!), solo es un pin digital de ENTRADA.
Con el CCS, se lo puede mover entre PORTB y PORTD, y no creas que sale muy airoso.

Desconectado jukinch

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 608
Re: LCD escribe lento pic16f819
« Respuesta #8 en: 18 de Mayo de 2013, 20:43:23 »
Rseliman: Podrías subir el dsn de proteus?
"Divide las dificultades que examinas en tantas partes como sea posible para su mejor solución." -René Descartes

Desconectado Rseliman

  • PIC16
  • ***
  • Mensajes: 239
Re: LCD escribe lento pic16f819
« Respuesta #9 en: 18 de Mayo de 2013, 21:02:51 »
Rseliman: Podrías subir el dsn de proteus?

Si como no Muchas gracias ahi va
Las Grandes Obras las sueñan los grandes locos , mientras los inutiles las critican !!

Desconectado Rseliman

  • PIC16
  • ***
  • Mensajes: 239
Re: LCD escribe lento pic16f819
« Respuesta #10 en: 18 de Mayo de 2013, 21:06:45 »
Rseliman: Podrías subir el dsn de proteus?

Si como no Muchas gracias ahi va

El que subi esta en el PORTB ...y la idea es cambiar al A porque nesecito poner un I2C .....muchas gracias nuevamente ....probe pasar directamente , pero no me funciona ....la pregunta es , teniendo en cuenta el A5 que siempre es input ...se puede usar directamente el porta sin usar el a5 ?? que cambio ademas de portb por porta ?
Las Grandes Obras las sueñan los grandes locos , mientras los inutiles las critican !!

Desconectado Rseliman

  • PIC16
  • ***
  • Mensajes: 239
Re: LCD escribe lento pic16f819
« Respuesta #11 en: 18 de Mayo de 2013, 21:36:48 »
Cambie RW , E , RS al port A y funciona ....son los datos los que salen mal .....use RA2 RA4 Y RA6 .... Ahora intentare cambiar los 4 bits de datos
Las Grandes Obras las sueñan los grandes locos , mientras los inutiles las critican !!

Desconectado jukinch

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 608
Re: LCD escribe lento pic16f819
« Respuesta #12 en: 18 de Mayo de 2013, 21:54:01 »
Podrías economizar pines con un registro de desplazamiento

http://byborre.blogspot.com.ar/2011/01/lcd-con-3-pines.html?m=1
"Divide las dificultades que examinas en tantas partes como sea posible para su mejor solución." -René Descartes

Desconectado Rseliman

  • PIC16
  • ***
  • Mensajes: 239
Re: LCD escribe lento pic16f819
« Respuesta #13 en: 18 de Mayo de 2013, 21:57:48 »
Podrías economizar pines con un registro de desplazamiento

http://byborre.blogspot.com.ar/2011/01/lcd-con-3-pines.html?m=1

Si vi la subrutina esa ...pero ahora es una cuestion de honor ...jajajaja aparte economiza pines pero ocupa lugar ....tambien podria cambiar de pic ....pero bueno ...voy a seguir intentando ...no puedo creer que no se pueda

Gracias
Las Grandes Obras las sueñan los grandes locos , mientras los inutiles las critican !!

Desconectado jukinch

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 608
Re: LCD escribe lento pic16f819
« Respuesta #14 en: 20 de Mayo de 2013, 11:24:50 »
Rseliman:
            si podés subí el proyecto completo funcionando, incluído el dsn, al hilo http://www.todopic.com.ar/foros/index.php?topic=40649.0 "minicurso de programación en XC8" así vamos completando ejemplos y más ejemplos "funcionales" en XC8.
            Aún no hay nada hecho con LCD y sería bueno contar con ello.
             Saludos.
                Jukinch
"Divide las dificultades que examinas en tantas partes como sea posible para su mejor solución." -René Descartes