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