LCD 20x4 controlado por PIC18F2550

Hola:

He hecho un circuito con Proteus, 18F2550, USB, LCD Hitachi 44780 20x4. Me gustaría hacer es controlar desde el PC con cualquier programa Visual C#, Visual Basic, C++, Delphi con el que sea controlar el LCD. Es decir, que muestre información.

Más bien, necesito con el CCS hacer el programa para ello y necesito ejemplos hasta el driver, cosas así. De momento he encontrado esto.

http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2619
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1409
http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1410

No se si necesito más información.

Un cordial saludos.

Edit:

Este es el código de momento, pero no escribe en el LCD. ¿El error está en el código o en el diseño del simulador?
Código:
#include <18F2550.h>
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL3,CPUDIV1,VREGEN
#use delay(clock=48000000)

#define USB_HID_DEVICE FALSE
#define USB_EP1_TX_ENABLE USB_ENABLE_BULK
#define USB_EP1_RX_ENABLE USB_ENABLE_BULK
#define USB_EP1_TX_SIZE 1
#define USB_EP1_RX_SIZE 3
#include <LCD420.C>
#include <pic18_usb.h>
#include "PicUSB.h" //Configuración del dispositivo USB
#include <usb.c> 

void main()
{
   usb_init(); //inicializamos el USB

   usb_task(); //habilita periferico usb e interrupciones
   usb_wait_for_enumeration(); //esperamos hasta que el PicUSB sea configurado por el host

   lcd_init();

   while (TRUE)
   {
      /*if(usb_enumerated()) //si el PicUSB está configurado
      {
      }*/
         delay_ms(20);
         lcd_gotoxy(1,1);
         printf(lcd_putc,"Hola Mundo");
   }
}
 

Adjuntos

  • picdem_fs_usb_523.zip
    19.5 KB · Visitas: 268
De momento el tema del usb lo estoy dejando de lado hasta que solucione lo del LCD. Por ahora he conseguido hacerlo funcionar pero solo con el lcd.c Por alguna razón que desconozco no va el LCD420.c.

Te pego el código que estoy usando para ver si encuentras el error. ¿Podría ser que me falta algo en el #fuse?

Código:
#include <18F2550.h>
//configure a 20MHz crystal to operate at 48MHz
#fuses HSPLL,NOWDT,NOPROTECT,NOLVP,NODEBUG,USBDIV,PLL3,CPUDIV1,VREGEN
#use delay(clock=48000000)

//#include <LCD420.c>

void main()
{
   lcd_init();
   
   while (TRUE)
   {
         //delay_ms(20);
         lcd_gotoxy(1, 1);
         printf(lcd_putc,"123");
         
         lcd_gotoxy(7, 1);
         printf(lcd_putc,"ABC");

         lcd_gotoxy(1, 2);
         printf(lcd_putc,"456");
         lcd_gotoxy(7, 2);
         printf(lcd_putc,"DEF");
         
         lcd_gotoxy(1, 3);
         printf(lcd_putc,"789");
         lcd_gotoxy(8, 3);
         printf(lcd_putc,"GHI");
         
         lcd_gotoxy(1, 4);
         printf(lcd_putc,"101112");
         lcd_gotoxy(8, 4);
         printf(lcd_putc,"JKL");
   }
}
 
Aunque algo tarde, por si alguien sigue teniendo el problema de la librería lcd420 no funciona en el pic 18f...

en la librería del lcd hay que especificar la dirección del puerto b en el procesador, ya que tiene por defecto 6 de los 16f... y en el 18f. es 3969
Código:
// As defined in the following structure the pin connection is as follows:
//     B0  enable
//     B1  rs
//     B2  rw
//     B4  D4
//     B5  D5
//     B6  D6
//     B7  D7
//
//   LCD pins D0-D3 are not used and PIC B3 is not used.

struct lcd_pin_map {                 // This structure is overlayed
           BOOLEAN enable;           // on to an I/O port to gain
           BOOLEAN rs;               // access to the LCD pins.
           BOOLEAN rw;               // The bits are allocated from
           BOOLEAN unused;           // low order up.  ENABLE will
           int     data : 4;         // be pin B0.
        } lcd;



#byte lcd = 6 //ESTA LINEA ES LA QUE HAY QUE MODIFICAR  
                   //ASI #byte lcd = 3969

Un saludo
 
joder que hijos de la mala vida por que nos hacen eso...arme toda mi tarjeta ya que antes habia trabajado con la serie 16 pero ahora con un poderosisimo serie 18(por lo del USB). con el LDC de 4x20 y no funciono...la destripe y ahora que tengo solo partes de mi diseño encuentro que el error no era yo. sino la libreria...menuda jalada... genial aporte eres lo maximo :)
 
Si yo tambien tenia ese problema, no me funcionaba la pantalla en la simulacion, empeze a creer que estaba dañado el archivo lcd420.c y que habia perdido la compra de la LDC. :LOL:.... muchas gracias @inoxsteel.
 
Hola. Mi librería sale de forma distinta. ¿Cómo puedo modificarla?
PHP:
////////////////////////////////////////////////////////////////////////////
////                             LCD420.C                               ////
////            Driver for common 4x20 LCD modules                      ////
////                                                                    ////
////  lcd_init()   Must be called before any other function.            ////
////                                                                    ////
////  lcd_putc(c)  Will display c on the next position of the LCD.      ////
////                     The following have special meaning:            ////
////                      \f  Clear display                             ////
////                      \n  Go to start of second line                ////
////                      \b  Move back one position                    ////
////                                                                    ////
////  lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1)     ////
////                                                                    ////
////  lcd_getc(x,y)   Returns character at position x,y on LCD          ////
////                                                                    ////
////////////////////////////////////////////////////////////////////////////
////        (C) Copyright 1996,1997 Custom Computer Services            ////
//// This source code may only be used by licensed users of the CCS C   ////
//// compiler.  This source code may only be distributed to other       ////
//// licensed users of the CCS C compiler.  No other use, reproduction  ////
//// or distribution is permitted without written permission.           ////
//// Derivative programs created using this software in object code     ////
//// form are not restricted in any way.                                ////
////////////////////////////////////////////////////////////////////////////

// As defined in the following structure the pin connection is as follows:
//     B0  enable
//     B1  rs
//     B2  rw
//     B4  D4
//     B5  D5
//     B6  D6
//     B7  D7
//
//   LCD pins D0-D3 are not used and PIC B3 is not used.

struct lcd_pin_map {                 // This structure is overlayed
           BOOLEAN enable;           // on to an I/O port to gain
           BOOLEAN rs;               // access to the LCD pins.
           BOOLEAN rw;               // The bits are allocated from
           BOOLEAN unused;           // low order up.  ENABLE will
           int     data : 4;         // be pin B0.
        } lcd;

#locate lcd = getenv("SFR:PORTB")                        // This puts the entire structure
                                     // on to port B 

#define lcd_type 2           // 0=5x7, 1=5x10, 2=2 lines


BYTE const LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6};
                             // These bytes need to be sent to the LCD
                             // to start it up.


                             // The following are used for setting
                             // the I/O port direction register.

struct lcd_pin_map const LCD_WRITE = {0,0,0,0,0}; // For write mode all pins are out
struct lcd_pin_map const LCD_READ = {0,0,0,0,15}; // For read mode data pins are in


BYTE lcdline;

BYTE lcd_read_byte() {
      BYTE low,high;

      set_tris_b(LCD_READ);
      lcd.rw = 1;
      delay_cycles(1);
      lcd.enable = 1;
      delay_cycles(1);
      high = lcd.data;
      lcd.enable = 0;
      delay_cycles(1);
      lcd.enable = 1;
      delay_us(1);
      low = lcd.data;
      lcd.enable = 0;
      set_tris_b(LCD_WRITE);
      return( (high<<4) | low);
}


void lcd_send_nibble( BYTE n ) {
      lcd.data = n;
      delay_cycles(1);
      lcd.enable = 1;
      delay_us(2);
      lcd.enable = 0;
}


void lcd_send_byte( BYTE address, BYTE n ) {

      lcd.rs = 0;
      while ( bit_test(lcd_read_byte(),7) ) ;
      lcd.rs = address;
      delay_cycles(1);
      lcd.rw = 0;
      delay_cycles(1);
      lcd.enable = 0;
      lcd_send_nibble(n >> 4);
      lcd_send_nibble(n & 0xf);
}


void lcd_init() {
    BYTE i;

    set_tris_b(LCD_WRITE);
    lcd.rs = 0;
    lcd.rw = 0;
    lcd.enable = 0;
    delay_ms(15);
    for(i=1;i<=3;++i) {
       lcd_send_nibble(3);
       delay_ms(5);
    }
    lcd_send_nibble(2);
    for(i=0;i<=3;++i)
       lcd_send_byte(0, LCD_INIT_STRING[i]);
}


void lcd_gotoxy( BYTE x, BYTE y) {
   BYTE address;

   switch(y) {
     case 1 : address=0x80;break;
     case 2 : address=0xc0;break;
     case 3 : address=0x94;break;
     case 4 : address=0xd4;break;
   }
   address+=x-1;
   lcd_send_byte(0,address);
}

void lcd_putc( char c) {
   switch (c) {
     case '\f'   : lcd_send_byte(0,1);
                   lcdline=1;
                   delay_ms(2);
                                           break;
     case '\n'   : lcd_gotoxy(1,++lcdline);        break;
     case '\b'   : lcd_send_byte(0,0x10);  break;
     default     : lcd_send_byte(1,c);     break;
   }
}

char lcd_getc( BYTE x, BYTE y) {
   char value;

    lcd_gotoxy(x,y);
    lcd.rs=1;
    value = lcd_read_byte();
    lcd.rs=0;
    return(value);
}
 
Última edición por un moderador:
Atrás
Arriba