Autor Tema: Problema con el pic18F4620 y LCD en C18  (Leído 1979 veces)

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

Desconectado mariale440

  • PIC10
  • *
  • Mensajes: 1
Problema con el pic18F4620 y LCD en C18
« en: 02 de Agosto de 2006, 01:28:28 »
Hola a todos...

Estoy usando el pic18f4620 y un lcd de 16 caracteres y 4lineas... estoy desarrollando todo mi codigo usando el C18.

Cuando voy a simular el circuito del pic con el lcd, me encuentro con que solamente imprime la primera y tercera linea de la pantalla LCD.... que puedo hacer para poder escribir algo en la segunda y cuarta linea? como puedo solventar esta situacion?

 :( :( :(

Cualquier ayuda que me puedan prestar se los agradecere mucho  :-) :-) :-)

este es mi codigo:

----------------------------------------------------- lcd c18.c ---------------------------------------------------------------------------

#include "lcdconfig.h"
#include <p18f4620.h>

VOID lcd_wait (void);
VOID lcd_init (void);
VOID wrcmd (CHAR);

VOID pause(INT num)
 // Utility routine to pause for
 // a period of time.
  { while(num--)
     {/*do nothing */
     }
  }

VOID lcd_init(void)
// Initialise the LCD Display.
 { PORTA = TRISA = 0;
   TRISB = PORTB = 0xFF;
   ADCON1 = 0x0F;
   wrcmd(0x00 | 0x08 | 0x18);    // 8-bit mode - 4 lines.
   wrcmd(LCD_SETVISIBLE+0x04);   // Display only - no cursors.
   wrcmd(LCD_SETMODE+0x02);      // Automatic Increment - Display shift right.
   wrcmd(LCD_SETDDADDR+0x0F);    // Initial Position far left.
 }

VOID clearscreen (void)
// Clear the LCD Screen and reset
// initial position.
 { wrcmd(LCD_CLS);
   wrcmd(LCD_SETDDADDR+0x00);
 }

/***** Utility Functions *****/

// Write a command to the LCD display.
VOID wrcmd (CHAR cmdcode)
 { TRISB = 0;
   PORTB = cmdcode;

   // Write to PORTB to latch data into the display.
   // Toggle Pin 'E' to send the command.
   PORTA  = LCD_CMD_WR;
   PORTA |= E_PIN_MASK;
 
   Nop();
 PORTA &= ~E_PIN_MASK;
   
   lcd_wait();
 }
     
VOID wrdata (CHAR data)
// Write a Character to the LCD Display.
 { TRISB = 0;
   PORTB = data;
   
   PORTA = LCD_DATA_WR;
   PORTA |= E_PIN_MASK;
 
   Nop();

   PORTA &= ~E_PIN_MASK;
   
  // lcd_wait();
 }

// Wait for the LCD busy flag to clear.
VOID lcd_wait (void)
 { BYTE status;
   TRISB = 0xFF;
   
   PORTA = LCD_BUSY_RD;
   do
    { PORTA |= E_PIN_MASK;
    
      Nop();
   
      status = PORTB;
      PORTA &= ~E_PIN_MASK;
    } while (status & 0x80);
 }


---------------------------------------------------- lcd main.c -------------------------------------------------------------------

#include "stddef.h"
#include "math.h"
#include "stdlib.h"
#include "string.h"
#include "lcdConfig.h"
#include <p18f4620.h>
         

CHAR buf [64]="1. Consultar    2. Resetear            hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh";

// Initialise our variables and call the
// Assembly routine to initialise the LCD display.

VOID calc_display (CHAR buf[64])
// Use the Output and Clearscreen routines from the
// *LCD_Write* assembly file to output ASCII values to the LCD.
 { INT8 i;
   clearscreen();
   for (i=0 ; i<strlen(buf); i++)
   {
         /*
         if(i=16)
         {
            wrcmd(LCD_SETDDADDR+0x40);
         }
         if(i=32)
         {
            wrcmd(LCD_SETDDADDR+0x10);
         }
         if(i=48)
         {
            wrcmd(LCD_SETDDADDR+0x50);
         }
         */
         wrdata(buf);
         pause(5000);
   }
 
 }


VOID main (VOID)
 {
   TRISAbits.TRISA6=0;
    TRISAbits.TRISA7=0;

   lcd_init();
   pause(5000);
   calc_display(buf);
    pause(50000);
 }   

----------------------------------------- archivo de cabecera lcdconfig.h------------------------------------------

typedef void VOID;                                                                         
typedef int  INT;                                                                           
typedef signed char INT8;
typedef signed int  INT16;
typedef signed long INT32;
typedef unsigned short WORD;                                                               
typedef char CHAR;                                                                         
typedef unsigned char BYTE;                                                                 
typedef double FLOAT;                                                                                                                                             
typedef long LONG;                                                                         
typedef INT8 BOOL;

//LCD Config

#define MAX_DISPLAY_CHAR 16

//#define LINEA_1 0x00
//#define LINEA_2 0x40
//#define LINEA_3 0x10
//#define LINEA_4 0x50

//LCD Registers addresses (PORT B)
#define LCD_CMD_WR      0x00
#define LCD_DATA_WR      0x01
#define LCD_BUSY_RD      0x02
#define LCD_DATA_RD      0x03
                     
//LCD Commands       
#define LCD_CLS         0x01
#define LCD_HOME      0x02
#define LCD_SETMODE      0x04
#define LCD_SETVISIBLE      0x08
#define LCD_SHIFT      0x10
#define LCD_SETFUNCTION      0x20
#define LCD_SETCGADDR      0x40
#define LCD_SETDDADDR      0x80

#define E_PIN_MASK         0x04

#define FALSE 0
#define TRUE  1                                                       
                                                     

Espero una pronta respuesta para poder resolver mi problema  :( :( :(

Desconectado maunix

  • Moderadores
  • DsPIC33
  • *****
  • Mensajes: 4751
    • Mi Sitio Web Personal
Re: Problema con el pic18F4620 y LCD en C18
« Respuesta #1 en: 02 de Agosto de 2006, 08:31:33 »
Si el LCD imprime... entonces tu rutina funciona bien.

Si no imprime en las líneas que tu deseas... es porque estas mandando el dato a un address incorrecto.

Los LCD suelen tener los address separados en este orden.

Address Menor --> Address Mayor
1er línea, 3er línea, 2da línea, 4ta línea


No recuerdo cual es el addresss de la 2da línea y 4ta línea, pero si lees el datasheet o si haces prueba y error, de seguro lo encuentras.

Saludos

- La soberbia de un Einstein es entendible.. la de un salame es intolerable (A.Dolina)
- En teoría no hay diferencia entre la teoría y la práctica. En la práctica... si la hay.
- Lee, Lee, Lee y luego pregunta.(maunix)
- Las que conducen y arrastran al mundo no son las máquinas, sino las ideas (V. Hugo)
- Todos los hombres se parecen por sus palabras; solamente las obras evidencian que no son iguales.(Moliere)
- Todo debería ser hecho tan simple como sea posible pero no mas simple que eso.(A.Einstein)