}void setSDALow(void) { _24C256_sda_d = 1; _24C256_sda = 0; }void setSCLLow(void) { _24C256_scl_d = 1; _24C256_scl = 0; }void clockToHigh(void) { setSCLHigh(); waitFactor(1); }void clockToLow(void) { setSCLLow(); waitFactor(1); }void clockPulse(void) { clockToHigh(); clockToLow(); }void sendBit(unsigned char bit) { if(bit) { setSDAHigh(); } else { setSDALow(); } waitFactor(1); setSCLHigh(); waitFactor(1); setSCLLow(); waitFactor(1);}unsigned char resetBus (void) { unsigned char sdaStatus; clockToHigh(); sdaStatus=getSDAState(); clockToLow(); return(sdaStatus==0?BUSY:ONLINE);}void startCondition(void) { setSDAHigh(); waitFactor(1); setSCLHigh(); waitFactor(1); setSDALow(); waitFactor(1); setSCLLow(); waitFactor(1);}void stopCondition(void) { setSDALow(); waitFactor(1); setSCLHigh(); waitFactor(1); setSDAHigh(); waitFactor(1); setSCLHigh(); waitFactor(1);}void writeByte(unsigned char byte) { unsigned char rotateLeft; unsigned char tmp; unsigned char toReturn; rotateLeft = 0; while(rotateLeft<8) { tmp=byte; tmp=(tmp << rotateLeft) >> 7; rotateLeft++; sendBit(tmp); }}unsigned char readByte(void) { unsigned char byte=0; unsigned char pos=0; _24C256_sda_d=0; while(pos<8) { clockToHigh(); byte|=getSDAState(); if(pos<7) byte<<=1; pos++; clockToLow(); } return(byte);}unsigned char readAck (void) { unsigned char sdaStatus; clockToHigh(); sdaStatus=getSDAState(); clockToLow(); return(sdaStatus==0?OK:NOK);}// ---------------------- High Level Functions ---------------void Write_24C256(unsigned char deviceAddress, unsigned int menAddress, unsigned char byte) { unsigned char myAck=0; unsigned int tmsb,tlsb; unsigned char msb, lsb; tlsb = tmsb = menAddress; tmsb = tmsb >> 8; tlsb = (tlsb << 8) >> 8; msb = (unsigned char) tmsb; lsb = (unsigned char) tlsb; reset_bus: while(resetBus()==BUSY); device_address: startCondition(); writeByte(deviceAddress); myAck=readAck(); if(myAck==NOK) goto reset_bus; men_address: writeByte(msb); myAck=readAck(); if(myAck==NOK) goto reset_bus; men_address1: writeByte(lsb); myAck=readAck(); if(myAck==NOK) goto reset_bus; send_byte: writeByte(byte); myAck=readAck(); if(myAck==NOK) goto reset_bus; stopCondition();}unsigned char Read_24C256(unsigned char deviceAddress, unsigned int menAddress) { unsigned char myAck=0; unsigned char byte=0; unsigned int tmsb,tlsb; unsigned char msb, lsb; tlsb = tmsb = menAddress; tmsb = tmsb >> 8; tlsb = (tlsb << 8) >> 8; msb = (unsigned char) tmsb; lsb = (unsigned char) tlsb; reset_bus: while(resetBus()==BUSY); device_address: startCondition(); writeByte(deviceAddress); myAck=readAck(); if(myAck==NOK) goto reset_bus; men_address: writeByte(msb); myAck=readAck(); if(myAck==NOK) goto reset_bus; men_address1: writeByte(lsb); myAck=readAck(); if(myAck==NOK) goto reset_bus; restart_condition: startCondition(); device_address_read: writeByte(deviceAddress | 0x01); myAck=readAck(); if(myAck==NOK) goto reset_bus; read_byte: byte = readByte(); sendBit(1); stopCondition(); return(byte);}- Final de 24C256.c ----------------------------------------------------------------------------- Inicio de 24C256.h ----------------------------------------------------------------------------#ifndef _24C256_H#define _24C256_H#define _24C256_sda_d pd3_4#define _24C256_sda p3_4#define _24C256_scl_d pd3_5#define _24C256_scl p3_5#define BUSY 0#define ONLINE 1#define OK 1#define NOK 0#define waitUnit 2// ---------------------- High Level Functions ---------------void Write_24C256(unsigned char deviceAddress, unsigned int menAddress, unsigned char byte);unsigned char Read_24C256(unsigned char deviceAddress, unsigned int menAddress);#endif- Final de 24C256.h ----------------------------------------------------------------------------Para utilizar os codigos e bem simples.Basta incluir o arquivo equivalente no header do programa onde vai usar, obviamente colocar o arquivo .C no projeto para ser compilado, e chamar as funcoes do que se deseja fazer, ler ou gravar.Exemplo:#include "24C02.h"// Prototiposvoid main(void);// Variaveis Globaisunsigned char i=0;unsigned char carToWrite;unsigned char car;unsigned char paraGravar;unsigned char inicio, final;unsigned char sdaState; // Ponto de Entradavoid main(void) { carToWrite=0; car=0; for(;;) { inicio=0; final=255; for(i=inicio;i Write_24C02(0xA0, i, i); car=0xFF; car=Read_24C02(0xA0, i); if(i!=car) { asm("nop"); } } asm("nop"); }}Bom e isso ...Espero que o codigo ajude... se precisarem de algo, tipo um projeto pronto e rodando para o R8C/1A por exemplo.. e so me avisar que eu posto um link de download aqui!Enjoy!