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.

error in c code when trying to interface 8051 with eeprom

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
hello
i trying to interface eeprom with 8051 with i2c. i am getting syntax error near sda= and scl=.can anyone help me


#include<reg51.h>
#include<stdlib.h>

#define SDA P3^5
#define 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;
}


do {
SDA = 1;
} while(SDA==1);

}

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();
}
SDA = 1;
scl_high();
SCL = 0;
}

void eeprom_write(unsigned char address, unsigned char dat)
{
start();
write(0x00);
write(address);
write(dat);
stop();
}


void eeprom_read(unsigned char address)
{
start();
write(0x00);
write(address);
stop();
start();
write(0x01);
read();
stop();
}

void sent (unsigned char dat)
{

while(TI==0);
SBUF = dat;
}

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()
{
unsigned char address = 0x00;
unsigned char dat = 0x3E;
EA=0;
longdelay();
longdelay();
longdelay();
longdelay();
TMOD = 0X20;
SCON = 0X50;
TH1 = 0XFD;
eeprom_write(address, dat);
eeprom_read(address);
while(1)
send_data();
}
 

Show what error is presented.
Also, you did´nt say the compiler you are using.

+++
 

hi

just change the #define with sbit like follows
sbit SDA = P3^5;
sbit SCL = P3^4;

i think this will solve your problem

regards

ml
 
thank you andre for your time.itz showing syntax error near '='.i am using keil uvision2 compiler
 

hi

please try the solution i mentioned, it will be solved

ml
 

thank you micro lab for the reply but when i am using sbit it is showing fatal error l211:i/o error on output file:
exception 0029h: access to file denied
 

hi

that could be of some thing else
because in keil this is how we address the individual port pins
what you can do is just remove all other parts and try to compile, you will get the solution
like
#include<reg51.h>

sbit SDA = P3^5;
sbit SCL = P3^4;

void main(void){
SCL = 1;
SDA = 1;
while(1);
}

just check whether it's compiling or not


ml
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top