DS1337 - 12h to 24h mode


Closed Thread
Results 1 to 31 of 31

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: DS1337 - 12h to 24h mode

    Hi Richard,

    Trie both code with same error,
    It does seem to go from 19h to 7h.
    When I attempt to go back to 19H I get a four appearing before the hours .. like so : 7:01:01 to 47:01:01 then the four disappear to come back to 7:01:01 ( yes minutes and seconds are still incrementing. But this is weird that the four would just leave by its own !

    Also the datasheet specifies that the bit 5 hour.5 is used for the hours between the 20 to 23 hours.
    Last edited by lerameur; - 13th January 2015 at 23:18.

  2. #2
    Join Date
    May 2013
    Location
    australia
    Posts
    2,727


    Did you find this post helpful? Yes | No

    Default Re: DS1337 - 12h to 24h mode

    the "4 " probably comes from the fact that temp1 is used in you display routine and its getting messed with by my code

    make a new byte var temp12 for use in the 12/24 routine in place of temp1


    but it should go to 19h not stay at 7h check if the am/pm is getting cleared when 24h mode is selected
    I have to go to work for a while

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


    Did you find this post helpful? Yes | No

    Default Re: DS1337 - 12h to 24h mode

    Give this a whirl.

    Code:
    rtcAMPM    var bit   ' Storage flag to indicate AM or PM ; 0=AM, 1=PM
    hourmode  var bit   ' Storage flag for RTC 12/24 hour mode ; 0=24Hr, 1=12Hr
    BCDResult  var byte  ' Storage for temporary result for BCD Conversions
    
    
    If(PortC.5 = 1) & (PortC.6 = 1) then Pause 1500
      If (PortC.5 = 1) & (PortC.6 = 1) then
       I2CRead SDApin,SCLpin,$D0,$02,[RTCHour]
       hourmode = RTCHour.6
       if hourmode = 1 then          ' Is the RTC set for 12-hour mode
        rtcAMPM = RTCHour.5          ' Assign AM/PM
        RTCHour = RTCHour & %00011111  ' Bits 4-0 = Hours  0-12
       endif
      BCDResult = RTCHour
      gosub Bcd2Dec
      
      if hourmode = 1 then  '12Hr
        if rtcAMPM = 1 then 'PM 
            BCDResult = BCDResult + 12  'PM
        endif
      else
        if BCDResult > 12 then 
            BCDResult = BCDResult - 12
            rtcAMPM = 1
        else
            rtcAMPM = 0
        endif
      endif
      gosub Dec2Bcd
      RTCHour = BCDResult
      hourmode = ! hourmode
      I2cwrite SDApin,SCLpin,$D0,$02,[RTCHour]
      pause 10
      I2cwrite SDApin,SCLpin,$D0,$02,[RTCHour]  ' Need to write twice because you changed the mode bit
      
             
      
     Bcd2Dec:
    ' Subroutine to convert BCD (2 hex digits) to Decimal
    ' Make sure to set BCDResult with parameter value before calling this sub  
    ' Result is stored in BCDResult
    
        BCDResult = (((BCDResult >> 4) * 10) + (BCDResult & $0f))
        
        return
        
    Dec2Bcd:
    ' Subroutine to convert Decimal to BCD (2 hex digits)
    ' Make sure to set BCDResult with parameter value before calling this sub  
    ' Result is stored in BCDResult
         
        BCDResult = (((BCDResult / 10) << 4) | (BCDResult // 10))
        
        return
    Regards,
    TABSoft

  4. #4
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: DS1337 - 12h to 24h mode

    Thanks for all the help.
    I just tried your code tabsoft, work very good from 18H to 7H, but not the opposite.
    hourmode = not hourmode
    but still I print out on the LCD that specific bit and I always get a 1 ...
    wird.. I also have RTChour output in binary and I only get 111 (7) and not 100111 as I thought ..
    Last edited by lerameur; - 14th January 2015 at 00:59.

  5. #5
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: DS1337 - 12h to 24h mode

    I try these lines:
    if RTCHour.6 =0 then RTCHour.6 =1
    if RTCHour.6 =1 then RTCHour.6 =0
    instead of hourmode = ! hourmode
    hourmode is always showing 0 after going from 19 to 7 . and stays at 7 even with buttons pressed

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


    Did you find this post helpful? Yes | No

    Default Re: DS1337 - 12h to 24h mode

    See if this works for you. I can't try it on the HW, but I think this will do it for you

    Code:
    rtcAMPM   var bit   ' Storage flag to indicate AM or PM ; 0=AM, 1=PM
    hourmode  var bit   ' Storage flag for RTC 12/24 hour mode ; 0=24Hr, 1=12Hr
    BCDResult var byte  ' Storage for temporary result for BCD Conversions
    
    
    If(PortC.5 = 1) & (PortC.6 = 1) then Pause 1500
      If (PortC.5 = 1) & (PortC.6 = 1) then
       I2CRead SDApin,SCLpin,$D0,$02,[RTCHour]
       hourmode = RTCHour.6
       if hourmode = 1 then          ' Is the RTC set for 12-hour mode
        rtcAMPM = RTCHour.5          ' Assign AM/PM
        RTCHour = RTCHour & %00011111  ' Bits 4-0 = Hours  0-12
       endif
      BCDResult = RTCHour
      gosub Bcd2Dec
      
      if hourmode = 1 then  '12Hr Convert to 24Hr
        hourmode = 0    ' change to 24Hr
        if rtcAMPM = 1 then 'PM 
            BCDResult = BCDResult + 12  'PM
        endif
      else  '24Hr Convert to 12Hr
        hourmode = 1
        if BCDResult > 12 then 
            BCDResult = BCDResult - 12
            rtcAMPM = 1
        else
            rtcAMPM = 0
        endif
      endif
      gosub Dec2Bcd
      RTCHour = BCDResult
      RTCHour.6 = hourmode
      RTCHour.5 = rtcAMPM 
      I2cwrite SDApin,SCLpin,$D0,$02,[RTCHour]
      pause 10
      I2cwrite SDApin,SCLpin,$D0,$02,[RTCHour]  ' Need to write twice because you changed the mode bit
      
             
      
     Bcd2Dec:
    ' Subroutine to convert BCD (2 hex digits) to Decimal
    ' Make sure to set BCDResult with parameter value before calling this sub  
    ' Result is stored in BCDResult
    
        BCDResult = (((BCDResult >> 4) * 10) + (BCDResult & $0f))
        
        return
        
    Dec2Bcd:
    ' Subroutine to convert Decimal to BCD (2 hex digits)
    ' Make sure to set BCDResult with parameter value before calling this sub  
    ' Result is stored in BCDResult
         
        BCDResult = (((BCDResult / 10) << 4) | (BCDResult // 10))
        
        return
    Regards,
    TABSoft

  7. #7
    Join Date
    Sep 2006
    Posts
    747


    Did you find this post helpful? Yes | No

    Default Re: DS1337 - 12h to 24h mode

    Starting with 19H pushing button attempts shows (4 trials one after the other) :
    - 87 very briefly then 7H. ok, good enough..
    - 1H
    -23H
    -73H briefly then 13H

    I really need to sit down and look at the problem more closely.
    But in this case the hourmode bit changes heyyyy !!

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 : 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