Nagesh29
Junior Member level 2
- Joined
- Oct 9, 2013
- Messages
- 22
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 3
- Activity points
- 129
Hie..
I am using pic 18f4520 microcontroller and DS1307 RTC and MPLAB C18 compiler.
When I try to simulate the code in proteus I get spurious scl transition detected..
My RTC terminal shows the same values I have written in the code but with no change.
Also, when I tried with the same logic in micro c, it works perfectly fine.
I have used the below function to wait I2C bus is micro c:
while(!(I2C1_Is_Idle()));
I have not found similar function in C18 I2C library.
Here is entire my code::
https://obrazki.elektroda.pl/5995338100_1381310071.png
https://obrazki.elektroda.pl/4358774900_1381310071.png
Plz help me with this..
Thanx.!
I am using pic 18f4520 microcontroller and DS1307 RTC and MPLAB C18 compiler.
When I try to simulate the code in proteus I get spurious scl transition detected..
My RTC terminal shows the same values I have written in the code but with no change.
Also, when I tried with the same logic in micro c, it works perfectly fine.
I have used the below function to wait I2C bus is micro c:
while(!(I2C1_Is_Idle()));
I have not found similar function in C18 I2C library.
Here is entire my code::
Code:
#include <p18f4520.h>
#include <i2c.h>
#include <Delays.h>
char minutes,seconds,day,hrs,date,month,year;
void main()
{
OpenI2C(MASTER,SLEW_OFF);
StartI2C();
WriteI2C(0xD0);
WriteI2C(0x00);
WriteI2C(0x80);
WriteI2C(0x10); //minutes
WriteI2C(0x10); // hours
WriteI2C(0x2); //day
WriteI2C(0x22); //date
WriteI2C(0x4); //month
WriteI2C(0x13); //year
StopI2C();
//Start Rtc Oscillator
StartI2C();
WriteI2C(0xD0); //address of rtc device
WriteI2C(0x00); //0th memory location
WriteI2C(0x00); // EOSC-bar: start osciallator of rtc
Delay1KTCYx(25);
while(1)
{
// Read RTC Data
StartI2C();
WriteI2C(0xD0);//address of rtc device
WriteI2C(0x00);//0th memory location
RestartI2C();
WriteI2C(0xD1); //address of rtc device
seconds = ReadI2C();
AckI2C();
minutes = ReadI2C();
AckI2C();
hrs =ReadI2C();
AckI2C();
day =ReadI2C();
AckI2C();
date=ReadI2C();
AckI2C();
year=ReadI2C();
NotAckI2C();
StopI2C();
//while ( !DataRdyI2C() );
seconds = ((seconds & 0xF0) >> 4)*10 + (seconds & 0x0F); // Transform seconds
minutes = ((minutes & 0xF0) >> 4)*10 + (minutes & 0x0F); // Transform months
hrs = ((hrs & 0xF0) >> 4)*10 + (hrs & 0x0F); // Transform seconds
day = ((day & 0xF0) >> 4)*10 + (day & 0x0F); // Transform months
date = ((seconds & 0xF0) >> 4)*10 + (date & 0x0F);
month = ((seconds & 0xF0) >> 4)*10 + (month & 0x0F);
year = ((seconds & 0xF0) >> 4)*10 + (year & 0x0F);
Delay1KTCYx(25);
while(1);
}
}
https://obrazki.elektroda.pl/4358774900_1381310071.png
Plz help me with this..
Thanx.!
Last edited by a moderator: