DS1307 RTC example


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Oct 2007
    Location
    Vancouver, BC, Canada
    Posts
    33


    Did you find this post helpful? Yes | No

    Default

    just some code correction. as the above was posted 6 months ago. the attachment is the corrected code.

    ' Dec 18.2010:
    ' rewrite so that we can adjust the day of the month of OCt, November and December
    ' please read FindDays to be clear.
    ' in the FindDays sub, the SetMonth to be in Decimal from 0 to 12.
    ' code rewrite in the adjustment of the date of the month
    ' variable Dummy was created
    Attached Files Attached Files
    ________________
    KV

  2. #2


    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?

  3. #3
    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.

  4. #4


    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?

  5. #5
    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.

  6. #6
    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, 23:06
  2. Random seed using the ds1307 RTC
    By rookie11 in forum General
    Replies: 7
    Last Post: - 25th November 2007, 21:31
  3. PIC 16F877 I2C communications
    By sigmoideng in forum General
    Replies: 7
    Last Post: - 13th July 2007, 11:28
  4. DS1307 on fire
    By brid0030 in forum General
    Replies: 6
    Last Post: - 25th November 2006, 03:44
  5. X1226 RTC - Help
    By charudatt in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th August 2006, 18: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