Autor Tema: Ayuda, PCF8574 y LCD  (Leído 3459 veces)

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

Desconectado piriots

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 609
Ayuda, PCF8574 y LCD
« en: 16 de Junio de 2005, 06:39:00 »
Hola gente de todopic. Tengo un problema con la libreria para controlar un lcd de 2x16 con I2c. El caso es que al compilar el programa con el ccs 3.222 me da un error al I2C_write. No se lo que puede pasar, a ver si podeis echarle un vistazo a la libreria.

[code]

//-----------------------------------------------------------------------------
// Title:         lcd4_i2c.c
// Description:   Driver for common LCD 4 row modules using I2C protocol.
// Date:          May-2002
// Ver.Rev.:      1.1
// Author:        XP8100 (blixenonline@terra.es) #Based on the routines LCD.C from CCS#
// Modified:      To HM-Baybus Project by Manuel Díaz
//-----------------------------------------------------------------------------
//
// 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
//    
 Go to start of second line
//      Move back one position
//
//     lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1)
//
//-----------------------------------------------------------------------------
// LCD pins D0-D3 are not used.
//-----------------------------------------------------------------------------
//
// Commment   : Control of a compatible LCD HITACHI from a bus I2C with
//              an EXPANDER of I/O with connection I2C. The tests of these
//              routines have been programmed using the IC PCF8574P of Phillips.
//              I use 4 bits mode programming. The 8 bits mode programming
//              is possible if you uses 2 x PCF8574P.
//
// As defined in the following structure the pin connection is as follows:
//
//  PCF8574P     LCD
//  ========     ======
//     P0        Enable
//     P1        RS
//     P2        RW
//     P3        No connect
//     P4        D4
//     P5        D5
//     P6        D6
//     P7        D7
//
//
//
// THIS DOCUMENT IS PROVIDED TO THE USER "AS IS"
//-----------------------------------------------------------------------------

#define lcd_type 2            // 0=5x7, 1=5x10, 2=2 lines
#define lcd_line_two 0x40     // LCD RAM address for the second line
#define lcd_line_three 0x14   // LCD Ram address for the 3 line
#define lcd_line_four 0x54    // LCD Ram address for the 4 line

#define IOE_ADDR  0x70        // I2C addr for i/o expander PCF8574P

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.

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

void lcd_send_nibble( byte n, byte type ) {
   switch (type) {
      case "C" :
                  i2c_write(n << 4);
                  delay_cycles(1);
                  i2c_write(n << 4 | 0x01);
                  delay_us(2);
                  i2c_write(n << 4 & 0xFE);
                  break;
      case "D" :
                  i2c_write(n << 4 | 0x02);
                  delay_cycles(1);
                  i2c_write(n << 4 | 0x03);
                  delay_us(2);
                  i2c_write(n << 4 & 0x02);
                  break;
       }
}

void lcd_send_byte( byte n, byte type ) {
   delay_ms(1);
   lcd_send_nibble(n >> 4, type);
   lcd_send_nibble(n & 0xf, type);
}


void lcd_init() {
byte i;
   i2c_start();
   i2c_write(IOE_ADDR);
   lcd_send_nibble(0, "C");
   delay_ms(15);
   for (i=1;i<=3;++i)   {
      lcd_send_nibble(3, "C");
      delay_ms(5);
   }
   lcd_send_nibble(2, "C");
   delay_ms(5);
   for (i=0;i<=3;++i)   {
     lcd_send_byte(LCD_INIT_STRING, "C");
   }
   i2c_stop();
}

void lcd_gotoxy( byte x, byte y) {
   i2c_start();
   i2c_write(IOE_ADDR);
   switch(y){
      case 1: address= 00; break;
      case 2: address= lcd_line_two; break;
//      case 3: address= lcd_line_three; break;
      default: address= 00; break;
//      default: address= lcd_line_four; break;
   }
   address+=x-1;
   lcd_send_byte(0x80|address, "C");
   i2c_stop();
}

void lcd_gotonl (){
 /*  switch(address){
      case 00 : address= lcd_line_two; break;
  //    case lcd_line_two : address= lcd_line_three; break;
  //    case lcd_line_three: address= lcd_line_four; break;
      default : address= 00; break;
   }*/
   address= lcd_line_two;
   lcd_send_byte(0x80|address, "C");
}

void lcd_putc( char c) {
   i2c_start();
   i2c_write(IOE_ADDR);
   switch (c) {
      case "f" : lcd_send_byte(1, "C");
                  delay_ms(2);
                  break;
      case "
" : lcd_gotonl(); break;
      case "" : lcd_send_byte(0x10, "C"); break;
      default : lcd_send_byte(c, "D"); break;
   }
   i2c_stop();
}
[code]

Salu2 y gracias de antemano

Desconectado J1M

  • Moderadores
  • PIC24H
  • *****
  • Mensajes: 1960
RE: Ayuda, PCF8574 y LCD
« Respuesta #1 en: 16 de Junio de 2005, 12:36:00 »
hola piriots, te he respondido x el otro foro, de todas formas t lo pego tb x aki, x si sirve d ayuda a alguien mas:

te esta dando este fallo: i2c_write, eso es pq estas usando el bus i2c sin haberlo inicializado, supongo q se usará con el PCF8574, pon esto debajo de la declaración de la frecuencia del reloj del sistema del pic (en el main.c)

#use i2c(Master, SDA=PIN_A0, SCL=PIN_A1)

saludos! cambia los pines SDA y SCL si no coinciden con los tuyos, y fuerza a usar el hardware si fuera necesario (puedes ver q es eso en la ayuda del CCS)

saludos!

Desconectado omibaya

  • PIC12
  • **
  • Mensajes: 57
RE: Ayuda, PCF8574 y LCD
« Respuesta #2 en: 30 de Julio de 2005, 12:10:00 »
Hola, esta directiva tambien la puedes aplicar al inicio de este fichero, a mi me funciono correctamente

Desconectado RaDoN

  • Moderadores
  • PIC24H
  • *****
  • Mensajes: 1498
RE: Ayuda, PCF8574 y LCD
« Respuesta #3 en: 30 de Julio de 2005, 12:47:00 »
Como se hace eso de forzar a usar el hardware?
Si juegas contra el mejor, pierdes como los demás.

Desconectado piriots

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 609
RE: Ayuda, PCF8574 y LCD
« Respuesta #4 en: 30 de Julio de 2005, 14:02:00 »
Es sencillo, pones FORCE_HW y ya esta.

#use i2c(master,sda=pin_c4,scl=pin_c3, force_hw)

Salu2

Desconectado RaDoN

  • Moderadores
  • PIC24H
  • *****
  • Mensajes: 1498
RE: Ayuda, PCF8574 y LCD
« Respuesta #5 en: 30 de Julio de 2005, 14:04:00 »
Sonrisa GiganteSonrisa GiganteSonrisa GiganteSonrisa GiganteSonrisa GiganteSonrisa GiganteSonrisa GiganteSonrisa GiganteSonrisa Gigante

gracias, que verde estoi de i2c!!!
Si juegas contra el mejor, pierdes como los demás.

Desconectado piriots

  • Colaborador
  • PIC24F
  • *****
  • Mensajes: 609
RE: Ayuda, PCF8574 y LCD
« Respuesta #6 en: 30 de Julio de 2005, 14:06:00 »
Tranquilo que yo llevo casi 1 mes peleando con el i2c master-slave y no rula ni de coña.