EEPROM externa en HiTech.

Estoy intentando leer y escribir una EEPROM 24C02 en HiTech, y no consigo que se grabe el dato. El terminal WP está a masa, y los tres pines de dirección también.

Si grabo previamente la memoria, en real, la puedo leer, pero con el PIC (Un 16F877A) no me graba el dato, le he dado mil vueltas y no consigo dar con el problema. He probado varios ejemplos y nada. Lo ultimo que he probado es este:

Código:
#include	<htc.h>
#include "i2c.h"
//--------------------------------------------
void write_ext_eeprom(unsigned char address, unsigned char data) {
	i2c_Start();               //Initiate the I2C bus 
	i2c_SendByte(0xA0);     //Send the Address of the Digipcco sensor to the I2C bus 
	while(i2c_ReadAcknowledge());     //Read the ACK from the memori 
	__delay_us(2); 
	i2c_SendByte(address);     //
	while(i2c_ReadAcknowledge());     //Read the ACK from the memori
	__delay_us(2); 
	i2c_SendByte(data);     //
	while(!i2c_ReadAcknowledge());     //Read the ACK from the memori
	__delay_us(2);
	i2c_Stop();
}
//---------------------------------------------
unsigned char  read_ext_eeprom(unsigned char address) {
   	unsigned char data;

	i2c_Start();               //Initiate the I2C bus 
	i2c_SendByte(0xA0);     //Send the Address of the Digipcco sensor to the I2C bus 
	while(i2c_ReadAcknowledge());     //Read the ACK from the memori 
	__delay_us(2);
	i2c_SendByte(address);     //
	while(i2c_ReadAcknowledge());     //Read the ACK from the memori
	__delay_us(2); 
	i2c_Start();
	i2c_SendByte(0xA1);     //
	while(i2c_ReadAcknowledge());     //Read the ACK from the memori
	__delay_us(2); 
	data=i2c_ReadByte();          //Fourth byte (MSB of the Temperature) 
  	i2c_SendAcknowledge(0);    //Sending (0) telling the sensor that we done
	while(!i2c_ReadAcknowledge());     //Read the ACK from the memori
  	__delay_us(2);
	i2c_Stop();                //Stop the sensor sending data  
  	__delay_us(2); 
	return(data);
}
//---------------------------------------------

Y en el main:

Código:
write_ext_eeprom(1, 0x22);

__delay_ms(10);

datoAux = read_ext_eeprom(1);

GotoxyLcd(1,1);
WriteStrLcd("dato: ");
itoa(texto,datoAux,10);
WriteStrLcd(texto);

La secuencia que obtengo en la simulación:

Código:
S A0 A 01 A 22 A Sr P
S A0 A 01 A Sr A1 A FF N Sr P

Saludos.
 
Atrás
Arriba