DS1307 I2C help

General discussion on mikroC.
Post Reply
Author
Message
m.levin
Posts: 3
Joined: 11 Sep 2011 12:11

DS1307 I2C help

#1 Post by m.levin » 24 Dec 2011 18:56

Hi

This is the first time I have had a play with any I2C devices and I am stuck.

All I want to do is display the Secs and minutes to the UART line and see the change on the UART Terminal
I am using a PIC18F452
Below is part of the code

Code: Select all

       
    I2C1_Init(100000);
    I2C1_Start();
    I2C1_Wr(0xD0);
    I2C1_Wr(0x00);                     // Start at REG 3 - Day of week
    I2C1_Start();
    I2C1_Wr(0xD1);
    sec=  (I2C1_Rd(1) & 0x7F);
    mins= (I2C1_Rd(1) & 0x7F);
    hr=   (I2C1_Rd(1) & 0x3F);
    dow=  (I2C1_Rd(1) & 0x7F);   // REG 3
    day=  (I2C1_Rd(1) & 0x3F);   // REG 4
    mth=  (I2C1_Rd(1) & 0x1F);   // REG 5
    year= (I2C1_Rd(0));         // REG 6
    I2C1_Stop();
   UART1_Write(sec);
   delay_ms(100);
   UART1_Write(mins);
   delay_ms(100);

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: DS1307 I2C help

#2 Post by janko.kaljevic » 26 Dec 2011 13:43

Hello,

Did you try our example for DS1307?
You can test it in order to see how it work.

Best regards.

Post Reply

Return to “mikroC General”