Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

interfacing 24c32a with p89c61x2 with i2c

Status
Not open for further replies.

freemanantony

Member level 4
Joined
May 19, 2010
Messages
70
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Chennai, India
Activity points
2,005
hai,
i am interfacing philips p89c61x2 with atmels eeprom 24c32a.do we have to use two word address to write to the eeprom.my code is posted below.iz not working .can anyone help me?
#include<reg51.h>
#include<stdlib.h>
#include<stdio.h>


sbit SDA=P3^5;
sbit SCL = P3^4;
unsigned char tempdata;
void delay()
{
unsigned char i;
for(i=0x00;i<0xFF;i++);
}

void longdelay(void)
{
int h,s;
for(s=0;s<0x50;s++)
for(h=0;h<0xFF;h++);

}


void scl_high()
{
hg:
SCL=1;
if(SCL!=1)
goto hg;
}

void start()
{
SDA=1;
scl_high();
SDA=0;
delay();
SCL=0;
}

void stop()
{
SDA=0;
scl_high();
SDA=1;
}

void write (unsigned char data1)
{
unsigned char i;
for(i=0;i<8;i++)
{
SCL=0;
if (data1 & 0x80)
{
SDA = 1;
}
else
{
SDA = 0;
}
SCL = 1;
data1 = data1 << 1;
delay();
SCL= 0;
}
SDA = 1;
delay();
scl_high();

sa:

if (SDA != 1)
{
goto sb;

}
else
{

goto sa;
}
sb:
delay();
SCL=0;
delay();
}

void read()
{
unsigned char j;
unsigned char tp;
unsigned char dat;
SDA = 1;
for(j=0;j<8;j++)
{
scl_high();
tp = SDA;
if (tp==1)
dat = (tempdata | 0x01);
else
dat = (tempdata & 0xFE);
tempdata = dat<<1;
SCL = 0;
delay();
delay();
delay();
}

scl_high();
SCL=0;
}

void eeprom_write(unsigned char address1,unsigned char address2, unsigned char dat)
{
start();
write(0xA2);
write(address1);
write(address2);

write(dat);
stop();
}


void eeprom_read(unsigned char address1,unsigned char address2)
{
start();
write(0xA2);
write(address1);
write(address2);

stop();
start();
write(0xA3);
read();
stop();
}

void sent (unsigned char dat)
{
SBUF = dat;
while(TI==0);
TI=0;
}

void send_data()
{
unsigned char R;
unsigned char J;


R = tempdata & 0xF0;
R = R >> 4;
R = R + 0x30;
sent (R);
J = tempdata & 0x0F;
J = J + 0x30;
sent (J);
}

void main(void)
{
//unsigned char address ;
//unsigned char dat ;
EA=0;
longdelay();
longdelay();
longdelay();
longdelay();
TMOD = 0X20;
SCON = 0X50;
TH1 = 0XFD;
TR1=1;

while(1)
{
eeprom_write(0x00,0x00,0x3E);
eeprom_read(0x00,0x00);
send_data();
eeprom_write(0x00,0x05, 0x2E);
eeprom_read(0x00,0x05);
send_data();
eeprom_write(0x00,0x08, 0xEA);
eeprom_read(0x00,0x08);
send_data();
eeprom_write(0x0F,0xFF, 0XFE);
eeprom_read(0x0F,0xFF);

send_data();
}
}
 

hai,
i am interfacing philips p89c61x2 with atmels eeprom 24c32a.do we have to use two word address to write to the eeprom.

two word means(2bytes or 32 bytes)?

---------- Post added at 11:13 ---------- Previous post was at 11:12 ----------

for your EEPROM you have to use 2 bytes of EEPROM MEMORY address followed by the data to be write

---------- Post added at 11:15 ---------- Previous post was at 11:13 ----------

refer the figure for Data write (in pdf page 6 )
ww1.microchip.com/downloads/en/DeviceDoc/21163E.pdf
 
for your EEPROM you have to use 2 bytes of EEPROM MEMORY address followed by the data to be write

---------- Post added at 11:15 ---------- Previous post was at 11:13 ----------


refer the figure for Data write (in pdf page 6 )
ww1.microchip.com/downloads/en/DeviceDoc/21163E.pdf

then follow it you will get outout
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top