Electronics development

Moderators: None (Apply to moderate this forum)
Number of threads: 512
Number of posts: 1020

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
I2C in 89C51 SOS!!! Posted by Sridhar5 on 6 Mar 2004 at 11:07 AM
I am trying to establish I2C communication interface for 89C51 (a FLASH version of 8051). Can anybody help me out with assembly programming?
What pins do I use for implementing I2c?
Sridhar.

Report
Re: I2C in 89C51 SOS!!! Posted by My_Ausweis on 10 Mar 2004 at 4:40 AM
As I Know there is no I2C in 89C51,you have to create by your ownself based on the datasheet for I2C Communication, Maybe you can open www.microchip.com, and downloading for the i2c Communication for PIC16F877. Hope this information will help u. Thx
Report
Re: I2C in 89C51 SOS!!! Posted by AsAdi on 9 Mar 2005 at 2:44 AM
: As I Know there is no I2C in 89C51,you have to create by your ownself based on the datasheet for I2C Communication, Maybe you can open www.microchip.com, and downloading for the i2c Communication for PIC16F877. Hope this information will help u. Thx
:
I have implemented a board using AT89C51 which includes PCF8583 as my RTC,and its protocol is I2C,so I had to implement this protocol too,maybe some of these code,with alittle bit changes is useful for you:

sbit RTCSDA = P2^4;
sbit RTCSCL = P2^5;
//RTC PCF8583 Driver
void RTCClock()
{
RTCSCL = 0;
Delay(1*CPUCLOCK/4);
RTCSCL = 1;
Delay(2*CPUCLOCK/4);
RTCSCL = 0;
Delay(1*CPUCLOCK/4);
}
/******************************************************/
void RTCSendOneByte(unsigned char byte)
{
RTCSCL = 0;
if((byte & 0x80) == 0x80) //Sending Byte
RTCSDA = 1;
else
RTCSDA = 0;
RTCClock();

if((byte & 0x40) == 0x40)
RTCSDA = 1;
else
RTCSDA = 0;
RTCClock();

if((byte & 0x20) == 0x20)
RTCSDA = 1;
else
RTCSDA = 0;
RTCClock();

if((byte & 0x10) == 0x10)
RTCSDA = 1;
else
RTCSDA = 0;
RTCClock();

if((byte & 0x08) == 0x08)
RTCSDA = 1;
else
RTCSDA = 0;
RTCClock();

if((byte & 0x04) == 0x04)
RTCSDA = 1;
else
RTCSDA = 0;
RTCClock();

if((byte & 0x02) == 0x02)
RTCSDA = 1;
else
RTCSDA = 0;
RTCClock();

if((byte & 0x01) == 0x01)
RTCSDA = 1;
else
RTCSDA = 0;
RTCClock();

RTCSDA = 1; //Master Makes SDA HIGH
Delay(1*CPUCLOCK/4);
RTCSCL = 1;
while(RTCSDA == 1); //Wait for RTC Acknowledges means it makes RTCSDA low
Delay(1*CPUCLOCK/4);
RTCSCL = 0;
}
/*****************************************************/
void RTCWriteData(unsigned char ads,unsigned char dt)
{
RTCSDA = 1;
Delay(5*CPUCLOCK/4);
RTCSCL = 1;
Delay(5*CPUCLOCK/4);
RTCSDA = 0; /*Start Bit*/
Delay(5*CPUCLOCK/4);
RTCSCL = 0;

RTCSendOneByte(0xA0); //Sending Slave Address 10100000
Delay(1*CPUCLOCK/4);

RTCSendOneByte(ads); //Sending Word Address
Delay(1*CPUCLOCK/4);

RTCSendOneByte(dt); //Sending data byte
Delay(1*CPUCLOCK/4);

RTCSDA = 0;
Delay(5*CPUCLOCK/4);
RTCSCL = 1;
Delay(5*CPUCLOCK/4);
RTCSDA = 1; //Stop bit
Delay(5*CPUCLOCK/4);
}
/******************************************************/
unsigned char RTCReadData(unsigned char ads)
{
unsigned char dd=0,k;

RTCSDA = 1;
Delay(5*CPUCLOCK/4);
RTCSCL = 1;
Delay(5*CPUCLOCK/4);
RTCSDA = 0; /*Start Bit*/
Delay(5*CPUCLOCK/4);
RTCSCL = 0;

RTCSendOneByte(0xA0); //Sending Slave Address 10100000
Delay(1*CPUCLOCK/4);

RTCSendOneByte(ads); //Sending Word Address
Delay(1*CPUCLOCK/4);

RTCSDA = 1;
RTCSCL = 1;
RTCSDA = 0; /*Start Bit*/
Delay(1*CPUCLOCK/4);
RTCSCL = 0;

RTCSendOneByte(0xA1); //Sending Slave Address 10100001
Delay(1*CPUCLOCK/4);

for (k=0x80;k>0;k/=2)
{
RTCSCL = 1;
Delay(1*CPUCLOCK/4);
dd |= (RTCSDA ==1?k:0);
Delay(1*CPUCLOCK/4);
RTCSCL = 0;
Delay(2*CPUCLOCK/4);
}

RTCSDA = 1; //Master Acknowledges
RTCClock();

RTCSDA = 0;
Delay(5*CPUCLOCK/4);
RTCSCL = 1;
Delay(5*CPUCLOCK/4);
RTCSDA = 1; //Stop bit
Delay(5*CPUCLOCK/4);

return dd;
}
/******************************************************/
unsigned char RTCGetSecond()
{
unsigned char a = RTCReadData(2);
return BCD2DEC(a);
}
/******************************************************/
unsigned char RTCGetMinute()
{
unsigned char a = RTCReadData(3);
return BCD2DEC(a);
}
/******************************************************/
unsigned char RTCGetHour()
{
unsigned char a = RTCReadData(4);
return BCD2DEC(a);
}
/******************************************************/
unsigned char RTCGetDay()
{
unsigned char a = RTCReadData(5);
a &= 0x3f;
return BCD2DEC(a);
}
/******************************************************/
unsigned char RTCGetMonth()
{
unsigned char a = RTCReadData(6);
a &= 0x1f;
return BCD2DEC(a);
}
/******************************************************/
unsigned char RTCGetYear()
{
unsigned char a = RTCReadData(5);
a /= 0x40;
return a;
}
/******************************************************/
void RTCSetTime(unsigned char hh,unsigned char mm,unsigned char ss)
{
RTCWriteData(4,DEC2BCD(hh));
RTCWriteData(3,DEC2BCD(mm));
RTCWriteData(2,DEC2BCD(ss));
}
/******************************************************/
void RTCSetDate(unsigned char yy,unsigned char mn,unsigned char dd)
{
unsigned char a = yy/4;
a = yy-a*4;
a *= 64;
a |= DEC2BCD(dd);
RTCWriteData(5,a);
a = DEC2BCD(mn);
RTCWriteData(6,a);
}
/******************************************************/
/******************************************************/
/******************************************************/




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.