DS1307 - How to store Decimal Value & how to convert back to BCD?


Closed Thread
Results 1 to 3 of 3
  1. #1

    Exclamation DS1307 - How to store Decimal Value & how to convert back to BCD?

    I was reading about this chip (1307) and also few posts about it, I understand that it outputs and accepts data in BCD format. I have tried searching the forum for the answers. But few came very near to what I want. I tried some of the methods but could not reach to a satisfactory conclusion.

    Please help me with the formula for the following:
    Case 1:
    If I have a temp (byte) variable. And I have the decimal value 56 in it
    1) How do I change and store the BCD value in a variable to be sent to the 1307?To clarify more, I need excat 56 in BCD

    Case 2:
    If I have a temp (byte) variable. And I have the BCD value 56 in it
    1) How do I change and store the Decimal value in a variable? To clarify more, I need excat 56 in decimal form inside my variable & NOT 86 as an equivalent decimal value for HEX.

    I am making a timer to switch anything ON/OFF at user defined time. My whole code works using decimal values including the LCDOUT command for sec,min, hrs & days

    But I am badly stuck in getting time from the 1307 & changing it to decimal & use it in my code. The same holds true for reversing the process and writing to the 1307.

    I find it easy to convert days into decimal. But the complexity of using BCD & the structure of HRS being different to minutes & seconds is proving difficult to overcome. I am looking to opt for a 24Hr format.
    ___________________
    WHY things get boring when they work just fine?

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    If it's just for display purpose, use LCDOUT modifiers such as DEC, HEX and see what happen.

    There's a couple of example in here about how to convert BCD in Decimal. Look at this one
    http://www.picbasic.co.uk/forum/showthread.php?t=852

    and this
    http://melabs.com/resources/samples/...ted/mn1307.txt
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    ___________________
    WHY things get boring when they work just fine?

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts