DS1302 year register


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    jsmcl's Avatar
    jsmcl Guest

    Default DS1302 year register

    I don't understand the DS1302 RTC registers. For year, the first four bit nibble is 0-99 (year.) The data sheet shows that bits 4-7 are "10 Year" - what does this mean? What I'm trying to figure out is how to load Y2K dates.

    Steve McLaughlin

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    The registers are held in BCD (Binary Coded Decimal) format.

    The first four bits (Bits 0-3) hold the units part of the Year - that is vaues 0-9. The upper four Bits (Bits 4-7) hold the 'tens' part of the year. Together they will make a value between 0-9 in the upper four Bits and 0-9 in the lower four bits. So the year 1997 (or 2097) will have $97 (Hex). The year 04 (for an implied 2004) will have $04 Hex in that Register. You can therefore store 100 years starting with $00 (for say year 2000) and ending with $99 (for say year 2099). You can only save 100 years, and which 100 years depends on your coding. Now we've gone thru the year 2000 it's usual to imply the 2000 bit and add it to the value saved in the register behind the scenes.

    If you are building a device and expecting it to last beyond 100 years, then this would not necessarilly be the RTC chip of choice - personally, I won't be manning a Tech-Support hotline in 100 years time, so I don't care - it'll be somebody elses problem (now where did I put the quote for the nuclear power plant)...

    In the same way the other registers hold the Seconds, Minutes, Day, Month etc in BCD format, although Bit 7 is used for other things in most of those cases, and the 'tens' part of the register only holds values in Bits 4 thru 6.

    Todays' date in the various Registers could be

    Year = $04
    Month = $09
    Day = $21

    etc etc.

    Do a search on DS1307 and/or BCD as there's quite a few snippets of code for this chip and other than it being I2C interface it's pretty much the same thing.

    Melanie

  3. #3
    jsmcl's Avatar
    jsmcl Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks. So the 1302 will still do leap year, etc., with $04 for year? Is 2004 implied? How does the chip know whether you mean 1904 or 2004 (or say 1997 or 2097?)

    Steve

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    The centuries and millenia, well that's up to your software to keep track - it ONLY stores 100 years 0-99. On my part, whenever I need to display or print a date, I simply prefix with "20", so 04 becomes 2004, and 99 will become 2099... lets face it, beyond that point it's not going to be our problem.

    I don't know what your application is, but an RTC by definition is a REAL-TIME Clock. Even if you're playing with say Jewish Calendar, it'll still apply...

    If Year = > 65 then
    LCDOut "57",HEX2 Year
    else
    LCDOut "58",HEX2 Year
    endif

    If you need to cover say the 100 years from 1950 to 2049, then similarly...

    If Year > 49 then
    LCDOut "19",HEX2 Year
    else
    LCDOut "20",HEX2 Year
    endif

    Both examples assume that Year is still in raw BCD Format.

    Spiltting across a century does make sorting records by date-order a little more fiddly.

    Chinese is a bit tricky because their year doesn't toggle at midnight on December 31/January 1 so the DS1302 isn't suitable.

  5. #5
    jsmcl's Avatar
    jsmcl Guest


    Did you find this post helpful? Yes | No

    Default

    In the Gregorian calendar, which is the calendar used by most modern countries, the following rules decides which years are leap years:
    Every year divisible by 4 is a leap year.
    But every year divisible by 100 is NOT a leap year
    Unless the year is also divisible by 400, then it is still a leap year.
    This means that year 1800, 1900, 2100, 2200, 2300 and 2500 are NOT leap years, while year 2000 and 2400 are leap years.
    This actually means year 2000 is kind of special, as it is the first time the third rule is used in many parts of the world.

    http://www.timeanddate.com/date/leapyear.html

    Basically, the answer is that for purposes of calculating leap-day, it is the same in either century. Ie, 1904 and 2004 (etc.) are the same. So software century works. (I should have reviewed leap year before I started this thread, but maybe it will help someone else.) The RTC doesn't need to know or care which cenury. I plan to check the DS1302 for 1900 and 2000 just for fun, but I don't plan any trips back in time....

    Steve McLaughlin

Similar Threads

  1. real time clock
    By maria in forum Code Examples
    Replies: 44
    Last Post: - 1st March 2022, 12:13
  2. Active low input?
    By CosMecc in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 8th August 2010, 20:31
  3. PIC16F877A pwm use for IR transmission
    By mcbeasleyjr in forum General
    Replies: 0
    Last Post: - 11th July 2009, 18:51
  4. DS1302 16F628 Woes
    By idtat in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 15th January 2009, 14:15
  5. MX7705 or AD7705 experience
    By FM11 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 12th January 2006, 21:54

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