Modifying melabs sample code to set time to 24 hour for DS1302 ?


+ Reply to Thread
Results 1 to 5 of 5
  1. #1

    Default Modifying melabs sample code to set time to 24 hour for DS1302 ?

    Hello.
    I'm dealing with this:

    http://melabs.com/samples/LABX1-16F877A/rtcx.htm

    It works fine, but I want it to display time in 24 hour format, not in AM/PM.
    After reading DS1302 datasheet, I've found out that I need to set bit 7 to 1 and write this to register 84H. However, the code above bursts only 8 bytes, how can I modify it to write to appropriate register?

  2. #2
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,786

    Default Re: Modifying melabs sample code to set time to 24 hour for DS1302 ?

    maybe in the line:

    Code:
    rtchr = $08
    you do this:
    Code:
    rtchr = $88
    Ioannis

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    1,551

    Default Re: Modifying melabs sample code to set time to 24 hour for DS1302 ?

    except that hours will now not display properly
    Code:
    Lcdout $fe, 1, hex2 rtcmonth, "/", hex2 rtcdate, "/" , hex2 rtcyear,_
    
    
      "  ", hex2 rtchr, ":", hex2 rtcmin, ":", hex2 rtcsec
    bit 7 needs to be masked off before display
    This is more entertaining than Free to Air TV

  4. #4
    Join Date
    Oct 2009
    Posts
    588

    Default Re: Modifying melabs sample code to set time to 24 hour for DS1302 ?

    Not sure if it will work with the same chip, but this code worked with a DS1307 and displays in 24 hrs mode

    Code:
    I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCYear,RTCCtrl]  ; read DS1307 chip
    If RTCHour.6=1 then
    			
    CounterA=(RTCHour>>4)&$01                           ' Work-Out 12 or 24 hour Display for Hours
    else
    CounterA=(RTCHour>>4)&$03
    endif
    CounterA=CounterA*10+(RTCHour&$0F)                  ' Display Hours appropriately for 12 or 24 hour Mode 
    If RTCHour.6=1 then			
    LCDOut $FE,$D4,#CounterA
    else
    LCDOut $FE,$D4,#CounterA Dig 1,#CounterA Dig 0
    endif
    LCDOut ":",#(RTCMin>>4)&$0F,#RTCMin&$0F
    
    timeH=(RTCHour>>4)                               'convert the BCD format of the hours register and store in variable timeH
    timeH=(timeH &$03)*10
    timeH=timeH+(RTCHour&$0F)
    
    timeM=(RTCMin>>4)
    timeM=(timeM &$07)*10
    timeM=timeM+(RTCMin&$0F)                         'convert the BCD format of the mins register and store in variable timeM
    CounterA var byte ' General purpose Variable

    TimeH and TimeM are byte variables too

    Hope that helps. Like I said it's untested on the chip you are using, but I guess they are more or less the same just better precision

  5. #5
    Join Date
    Aug 2003
    Location
    Australia
    Posts
    1,001

    Default Re: Modifying melabs sample code to set time to 24 hour for DS1302 ?

    There would be a number of ways.
    To drop bit 7 from a byte, where you know bit 7 will always be set (which you do:
    Code:
    byte = byte - %10000000
    Or leave it as 12 hour, read the am/pm flag, and adjust the hour prior to display.

    Code:
    if pm != 0 then
    hour = hour + 12
    endif

Similar Threads

  1. LCD -- melabs sample program
    By Michael in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 19th June 2017, 13:42
  2. pulsin sample time
    By longpole001 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 11th July 2012, 15:30
  3. Hello, long time no post (ADC sample rate)
    By Jhong2 in forum General
    Replies: 0
    Last Post: - 14th April 2009, 04:13
  4. Set the starting time with ds1302 picbasic
    By crisxstyle in forum Off Topic
    Replies: 9
    Last Post: - 30th September 2008, 15:14
  5. RTC 1302 !!! Set time Routine !!
    By uludere72 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 24th February 2006, 10:28

Members who have read this thread : 25

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