+ Post New Thread
Results 1 to 4 of 4
  1. #1
    Full Member level 4
    Points: 2,681, Level: 12

    Join Date
    Jun 2007
    Posts
    221
    Helped
    10 / 10
    Points
    2,681
    Level
    12

    help needed interfacing RTC DS1307 with 8051

    Hi friends,

    I am doing a Digital Clock using RTC DS1307 and 89C4051 micro controller.

    Time is displayed on LCD and different alarms can be set through 3 switches.

    I have written the following code for updating RTC registers first time. Only minutes code is shown

    Code:
    //Minutes
    min++;
    if((min>15)&&(min<20))
    {
    onmin=min+6;
    }
    else if((min>=20) &&(min<30))
    {
    onmin=min+12;
    }
    else if((min>=30) &&(min<40))
    {
    onmin=min+18;
    }
    else if((min>=40) &&(min<50))
    {
    onmin=min+24;
    }
    else if((min>=50) &&(min<60))
    {
    onmin=min+30;
    }
    else
    {
    onmin=min;
    }
    I have added so many conditions because, when i enter the data from the switches(Increment/decrement), i am storing the value in a integer type. But we need to write BCD value to RTC DS1307. Suppose if i want to update the Minute register with 19, with out the above conditions it is updating as 11.
    I hope you all understand my query.
    I feel the above code is not efficient, i want to write it with out so many if conditions. Can somebody help me in this regard please?

    Thanks and Regards,
    Viswanath

    •   AltAdvertisment

        
       

  2. #2
    Advanced Member level 4
    Points: 6,490, Level: 19

    Join Date
    Feb 2011
    Posts
    1,170
    Helped
    284 / 284
    Points
    6,490
    Level
    19

    Re: help needed interfacing RTC DS1307 with 8051

    It's not clear why you need to add multiples of 6.
    If you type DS1307 in the search box, it reveals 450 results, so it's highly likely
    at least one of them will help you with this device.
    There is also this URL which shows in
    some extreme detail how to use the DS1307. The microcontroller used was an
    AVR device and not an 8051, but that is not relevant.



    •   AltAdvertisment

        
       

  3. #3
    Full Member level 4
    Points: 2,681, Level: 12

    Join Date
    Jun 2007
    Posts
    221
    Helped
    10 / 10
    Points
    2,681
    Level
    12

    Re: help needed interfacing RTC DS1307 with 8051

    HI,

    Thanks for the link. I will definitely go through it.

    It's not clear why you need to add multiples of 6.
    DS1307 Seconds range is 00-59 BCD.

    for example

    When i update the seconds register with 16, it is updating as 10 and with 20 it is updating as 14.

    So for updating seconds with 16 i need to send 232; and for 206 i need to send 32.

    for this reason i have used different loops.

    My purpose is solved with the code i have shown in my first post, but i want some help to write the code efficiently.

    Thanks and Regards,
    Viswanath

    - - - Updated - - -

    Hi,

    Finally i have replaced whole if loop condition with a single sentence and it is working.


    Code:
    onmin=(((min/10)<<4)+(min%10));
    Thanks and Regards,
    Viswanath



    •   AltAdvertisment

        
       

  4. #4
    Member level 3
    Points: 942, Level: 6

    Join Date
    Dec 2011
    Location
    Chennai
    Posts
    67
    Helped
    8 / 8
    Points
    942
    Level
    6

    Re: help needed interfacing RTC DS1307 with 8051

    Hi

    U Better Go Through This Link, For Set and Display the clock timing is described with 8051

    http://embeddedece.blogspot.in/2012/...s1307-rtc.html



--[[ ]]--