DS1307 RTC example


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    Little confused with BCD to Decimal conversion and vice versa.
    Please clarify, if I have 3 variables sec, minu, hrs and want decimal values in them, is the following correct?
    AIM: To get the decimal values inside sec (0-59), minu (0-59) & Hrs (0-23)
    The first thing my code is doing is resetting DS1307 with the following line of code:
    Code:
    I2CWRITE SDA,SCL,$D0,$00,[$17,$3B,$17,$01,$00,$00,$00,$90]
    The above line only executes once only when PIC is powered for the first time only.
    As you can see I choose a 24Hr format for my time. I also want to start my time with 23:59:23. I am only interested in hrs,min,sec,day only.
    Now if I read back the time:
    Code:
    I2CREAD SDA,SCL,$D1,$00,[STR DB0\8]
    and want decimal values in my variables, please guide what is the correct way of doing it as the following is not working
    Code:
    temp=db0[0]
    sec =(temp>>4)*10+(temp & $0F)
    
    temp=db0[1]
    minu =(temp>>4)*10+(temp & $0F)
    
    temp=db0[2]
    hrs=(temp>>4)*10+(temp & $0F)
    Lcdout $FE,1,DEC2 sec," : ",DEC2 minu," : ",DEC2 hrs
    ___________________
    WHY things get boring when they work just fine?

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Dave
    Always wear safety glasses while programming.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Thanks Mack, I have seen the code there and tried it as well, but it is giving errors. Also I don't see any variable saving values in Decimal format coming from DS1307 and converting decimal to BCD as well to store in DS1307.
    ___________________
    WHY things get boring when they work just fine?

  4. #4
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    This is using a different RTC but it has DEC vars.
    http://www.picbasic.co.uk/forum/cont...USB-SD-LOGGING
    Dave
    Always wear safety glasses while programming.

  5. #5
    Join Date
    Apr 2012
    Location
    Ptolemaida
    Posts
    50


    Did you find this post helpful? Yes | No

    Default Re: DS1307 RTC example

    Thank you a LOT Malcolm for your owsome code !! i tried on PIC16F628A ( with some modifications [changed the LCD disp with a Serout to my PCTerminal] ).
    It is a rly nice code for starters i can do so many things now !!
    Best regards, Kostas.

Similar Threads

  1. 16F628 and an RTC DS1307
    By aurbo in forum General
    Replies: 2
    Last Post: - 7th March 2011, 22:06
  2. Random seed using the ds1307 RTC
    By rookie11 in forum General
    Replies: 7
    Last Post: - 25th November 2007, 20:31
  3. PIC 16F877 I2C communications
    By sigmoideng in forum General
    Replies: 7
    Last Post: - 13th July 2007, 10:28
  4. DS1307 on fire
    By brid0030 in forum General
    Replies: 6
    Last Post: - 25th November 2006, 02:44
  5. X1226 RTC - Help
    By charudatt in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th August 2006, 17:54

Members who have read this thread : 1

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