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.

Hardware I2C C code for 8051 needd

Status
Not open for further replies.

ramasamy

Member level 1
Joined
Mar 15, 2005
Messages
34
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,524
I2C C code

Hi
can any body send me Hardware I2C C code for 8051 , it will be very use full for me to implement in my project.
Best regards
Ram
 

Re: I2C C code

Hello Ram,

Hav a luk at the attachment.
This code is written for 89c51(interfacing 89c51 with RTC DS1307 using I2C communication)
Hope this will help yu.

Feel free to contact me if yu have any queries regarding this.

Best Regards,
Viswanath.
 

hi this code not work for me but with these change work


void send_byte(unsigned char c)
{
unsigned mask=0x80;
//i2c_write(c);
//return;


do //transmits 8 bits
{

if(c&mask) //set data line accordingly(0 or 1)
SDAHIGH //data high
else
SDALOW //data low

d_us
d_us
SCKHIGH //clock high
d_us
SCKLOW //clock low
d_us

mask/=2; //shift mask
}while(mask>0);
SDAHIGH //release data line for acknowledge
SCKHIGH //send clock for acknowledge
d_us
slave_ack=READ_SDA(); //read data pin for acknowledge
SCKLOW //clock low
d_us
}

:wink:
 
Last edited:

Enjoy the codes
 

Attachments

  • i2c.rar
    737 bytes · Views: 119

    V

    Points: 2
    Helpful Answer Positive Rating
Enjoy the codes

Sorry because I am replaying in this instead of its older post but I can not stop myself because I really want solution for my problem.

I have written my code for i2c for 89c51 and DS1307 RTC. which is mostly same as your code.

but I am not getting there output.
from datasheet of ds1307 I have found that it is standard to set 100khz frequency for ds1307 and I2C communication.
so, is that compulsory to give specific delay for SCL and SDA?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top