با سلام
من با EEPROM AT24C08 ارتباط برقرار کردم و مشکلی ندارم در کلیاتش.فقط نمیتونم به ادرس های بالاتر از 255 دسترسی پیداکنم! روش شکستن به 2 بایت رو هم میرم ولی جواب نمیده.کسی می تونه کد زیر زو بررسی کنه و بگه چه جوری اصلاحش کنم؟؟؟ (اگه کد به هم ریخته زیر رو تو NOTE PAD ویندوز یا CODEVISION کپی کنین گویا تر میشه)
#define SLA_W 0xa0 //EEPROM write and read
#define SLA_R 0xa1
#define REP_START TWCR = 0xa4 //Following are TWI commands
#define START TWCR = 0xa4
#define STOP TWCR = 0x94
#define CLR_TWINT TWCR = 0x84
#define Wait() while((TWCR & 0x80)==0)
#define DATA TWDR
int z,i;
unsigned char j;
char str[100];
void eep_write1( int address, unsigned char data)
{
START; //send start pulse START=0xa4
Wait(); //wait untill the TWINT bit set,if TWINT
DATA = SLA_W; //send SLave Address + write bit
CLR_TWINT; //clear TWINT bit by writing 1 into it
Wait(); //wait untill the TWINT bit set
DATA =address; //Send the starting address where we are going to write out data
CLR_TWINT;
Wait();
for(j=0;j<1;j++) {
DATA=data;
CLR_TWINT;
Wait();
}
STOP;
delay_ms(10);
}
int eep_read1(int address)
{
START;
Wait();
DATA = SLA_W;
CLR_TWINT;
Wait();
DATA =address;
CLR_TWINT;
Wait();
REP_START;
Wait(); // READ FROM EEPROM
DATA = SLA_R;
CLR_TWINT;
Wait();
for(j=0;j<1;j++) {
CLR_TWINT;
TWCR = 0xc4; //read DATA
Wait();
}
CLR_TWINT;
return DATA;
}
من با EEPROM AT24C08 ارتباط برقرار کردم و مشکلی ندارم در کلیاتش.فقط نمیتونم به ادرس های بالاتر از 255 دسترسی پیداکنم! روش شکستن به 2 بایت رو هم میرم ولی جواب نمیده.کسی می تونه کد زیر زو بررسی کنه و بگه چه جوری اصلاحش کنم؟؟؟ (اگه کد به هم ریخته زیر رو تو NOTE PAD ویندوز یا CODEVISION کپی کنین گویا تر میشه)
#define SLA_W 0xa0 //EEPROM write and read
#define SLA_R 0xa1
#define REP_START TWCR = 0xa4 //Following are TWI commands
#define START TWCR = 0xa4
#define STOP TWCR = 0x94
#define CLR_TWINT TWCR = 0x84
#define Wait() while((TWCR & 0x80)==0)
#define DATA TWDR
int z,i;
unsigned char j;
char str[100];
void eep_write1( int address, unsigned char data)
{
START; //send start pulse START=0xa4
Wait(); //wait untill the TWINT bit set,if TWINT
DATA = SLA_W; //send SLave Address + write bit
CLR_TWINT; //clear TWINT bit by writing 1 into it
Wait(); //wait untill the TWINT bit set
DATA =address; //Send the starting address where we are going to write out data
CLR_TWINT;
Wait();
for(j=0;j<1;j++) {
DATA=data;
CLR_TWINT;
Wait();
}
STOP;
delay_ms(10);
}
int eep_read1(int address)
{
START;
Wait();
DATA = SLA_W;
CLR_TWINT;
Wait();
DATA =address;
CLR_TWINT;
Wait();
REP_START;
Wait(); // READ FROM EEPROM
DATA = SLA_R;
CLR_TWINT;
Wait();
for(j=0;j<1;j++) {
CLR_TWINT;
TWCR = 0xc4; //read DATA
Wait();
}
CLR_TWINT;
return DATA;
}
دیدگاه