DS1337 - 12h to 24h mode


Closed Thread
Results 1 to 31 of 31

Hybrid View

  1. #1
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: DS1337 - 12h to 24h mode

    Some additional direction.

    12hr Mode

    Display Value to LCD:
    1. Mask off 12/24Hr mode bit
    2. Mask off am/pm bit
    3. Display new masked value with Hex2 modifier

    Change Hour Value in RTC:
    1. Mask off 12/24Hr mode bit
    2. Mask off am/pm bit
    3. Convert new masked value from BCD to Decimal
    4. Change Hour value in Decimal
    5. Convert Decimal Hour back to BCD
    6. Set am/pm bit
    7. Set 12/24Hr mode bit
    8. Write new value to RTC Hour register


    24hr Mode

    Display Value to LCD:
    1. Display value with Hex2 modifier

    Change Hour Value in RTC:
    1. Convert value from BCD to Decimal
    2. Change Hour value in Decimal
    3. Convert Decimal Hour back to BCD
    4. Write new value to RTC Hour register


    Here is a table that shows two hour values in their various permutations.
    SampleTable.txt

    Hope this helps.
    Regards,
    TABSoft

  2. #2
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: DS1337 - 12h to 24h mode

    I am having difficulty dealing with the bit 5 and 6 of the hours..
    using the subroutine add hours:
    I have 11 with bi6 and bit = 0
    click on addhour, brings me at hour 32 with bit 6 = 0 and bit 5 = 1
    ...
    ADDHour: 'increment hours
    pause 200
    if PortC.5=1 then return
    if PortC.6=1 then

    I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour]
    hourmode = RTCHour.6
    rtcAMPM = RTCHour.5
    ' lcdout $FE,1, "RTCH1: ", bin RTCHour
    ' lcdout $FE,$C0, "BCDR: ", dec BCDResult
    ' pause 2000

    if hourmode = 0 then ' this is 24H mode 0H to 23H
    ' hourmode = 1
    BCDResult = RTCHour
    gosub Bcd2Dec

    BCDResult = BCDResult + 1
    if BCDResult > 23 then BCDResult = 0
    Pause 2
    BCDResult_temp = BCDResult
    gosub Dec2Bcd
    RTCHour = BCDResult
    if BCDResult_temp > 12 then RTCHour.5 = 1
    I2cwrite SDApin,SCLpin,$D0,$02,[RTCHour]

    elseif hourmode = 1 then ' this is 12H mode 0H to 12H
    ' hourmode = 0
    rtcAMPM = RTCHour.5 ' Assign AM/PM
    RTCHour = RTCHour & %00011111 ' Bits 4-0 = Hours 0-12
    BCDResult = RTCHour
    ' lcdout $FE,1, "RTCH1: ", bin RTCHour
    ' lcdout $FE,$C0, "BCDR: ", dec BCDResult
    ' pause 2000
    gosub Bcd2Dec

    BCDResult = BCDResult + 1 ' in decimal
    if BCDResult > 12 then BCDResult = 1
    Pause 2
    gosub Dec2Bcd
    RTCHour = BCDResult
    RTCHour.6 = hourmode
    RTCHour.5 = rtcAMPM
    ' lcdout $FE,1, "RTCH2: ", bin RTCHour
    ' lcdout $FE,$C0, "BCDR: ", bin BCDResult
    ' pause 2000
    I2cwrite SDApin,SCLpin,$D0,$02,[RTCHour]
    endif
    endif
    return

  3. #3
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: DS1337 - 12h to 24h mode

    Concerning your table:
    With 12Hr 04PM $64 0110 0100 100
    Without 12Hr 04PM $4 0000 0100 4

    what do you mean with or without ? the AM PM bit ?? because bit 6 is a 1 on the first line, a one means 24H mode, you have 12H showing. What am I not getting ???

  4. #4
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: DS1337 - 12h to 24h mode

    Reading the DS1337 Datasheet if bit 6 is High (1) 12hr mode is selected. See snippet from the Datasheet below.

    "The DS1337 can be run in either 12-hour or 24-hour mode. Bit 6 of the hours register is defined as the 12- or 24-hour mode-select bit. When high, the 12-hour mode is selected."

    With or without refers to the need, when in 12Hr mode, to mask off(set to 0) BOTH the 12/24Hr and AM/PM bits when using LCDOUT, SEROUT, HSEROUT, etc ; and when changing the value of the Hours in your code to be written back to the RTC. Such as when you allow the user to change the time via buttons.
    With = Bits ARE NOT masked ( leads to errors)
    Without = Bits ARE masked

    Not performing these actions when needed during hour value manipulation and displaying the values will lead to incorrect settings in the RTC and visually strange clock display. E.g. 44 being displayed on the LCD instead of the expected 4 AM or 64 being displayed on the LCD instead of expected 4 PM.
    Last edited by Tabsoft; - 15th January 2015 at 04:44. Reason: Clarified with or without
    Regards,
    TABSoft

  5. #5
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: DS1337 - 12h to 24h mode

    Just for grins, try doing 2 successive writes to the RTC with a 10ms pause in between.

    I've ran into these kind of issues whenever the hours.6 bit is changed in the RTC.
    Do this when you 1st initialize the RTC on startup and every time you write to the RTC.
    The issue is when the 12/24hr mode bit is changed (hours.6).

    From the DS
    "All hours values, including the alarms, must be reinitialized whenever the 12/24-hour mode bit is changed."
    Regards,
    TABSoft

  6. #6
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: DS1337 - 12h to 24h mode

    Hello,

    I think I found the problem but I dont know how to get around it,
    I have bit 5 confusing me when in 24H mode. How do you remove it from calculation,
    The problem is this,
    You need to get only number between 20 and 23H used with bit 5.
    You also need to know what time you are now to do the calculation, at 18H hour you dont need it so RTCHour is 4 bits
    at 20H you need the 5 bits,
    So which and when to separate the two,... it seems to me like a chicken or egg issue.. which came first,, or in this case .. which to calculate first

  7. #7
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: DS1337 - 12h to 24h mode

    The only time you should need to worry about bit 5 is when bit 6 = 1 (12 hour mode).

    When bit 6 = 0 (24 hour mode) you do not have to remove or mess with bit 5. Bit 5 is part of the number [B]not[B] an am/pm bit.

    24Hr mode

    Time is 11:00 hours, hours = %00010001 notice bit 5 is a zero which means the 2nd 10s is clear, and bit 4 (1st 10s) is a one which is set.
    Time is 21:00 hours, hours = %00100001 notice bit 5 is a one which means the 2nd 10s is set, and bit 4 (1st 10s) is zero which is clear.
    Regards,
    TABSoft

Similar Threads

  1. 12H format setting for DS1307
    By larzazral in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 23rd February 2010, 07:34
  2. example code for DS1337
    By TONIGALEA in forum mel PIC BASIC Pro
    Replies: 25
    Last Post: - 8th December 2009, 21:16
  3. Code for DS1337
    By Fernanda in forum Off Topic
    Replies: 2
    Last Post: - 21st July 2008, 20:18
  4. PBPro for 16-bit PICs (24F/24H/DSPICs)?
    By Sergeant in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 20th April 2007, 20:18
  5. DS1337 Problem
    By snow in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 9th January 2005, 12:17

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