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();
}
}
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();
}
}