RTC take two


Closed Thread
Results 1 to 5 of 5

Thread: RTC take two

  1. #1
    Join Date
    Oct 2009
    Posts
    583

    Default RTC take two

    I thought I would start a new thread as the other one based on the RTC giving strange readings seems to be something with the BDC conversions.

    I have tried the following to set the time / date to a DS1307 RTC chip within my main section of code.

    Code:
    gosub write_1307
    read_1307:                          ' Read time Secs,Mins,Hours,Day,Date,Month,Year,Control
    I2CREAD SDA,SCL,$D1,$00,[STR DB0\8] ' Read 8 bytes from DS1307
    
    lcdout $fe,1,"Time=",hex2 DB0[2],":",hex2 DB0[1],":",hex2 DB0[0]    'bit 0=sec, bit 1=min, bit 2=hrs
    lcdout $fe,$c0,"Date=",hex2 DB0[4],":",hex2 DB0[5],":",hex2 db0[6]  'bit 4=day, bit 5=month, bit 6=year
    goto read_1307
    
    
    ********************************************
    
    Write_1307:                          ' format: Sec Min Hr Day D M Y Control .  EG to Set time & date to 19:00:00  14th Feb 2010 
    I2CWRITE SDA,SCL,$D0,$00,[$00,$00,$19,$7,$14,$2,$10,$90] ' Write to DS1307
    pause 10
    RETURN                               '
    This works a treat - however I want to be able to set the values in the I2CWRITE string and have a routine that places the decimal values of 00 to 23 for hours and 00-59 for minutes into two variables SetHour and SetMin

    Code:
    time:
    
    LCDOUT $FE,1
    LCDOUT $FE,2,"Set Time" 
        
    inp3:
    
    IF H_butt = 0 THEN GOSUB IncHours
    IF M_butt = 0 THEN GOSUB IncMinutes
        SetHour=Hours
        SetMin=Minutes
     
    LCDOUT $FE,$C0,#SetHour DIG 1,#SetHour DIG 0,":",#SetMin DIG 1,#SetMin DIG 0
    pause 200
    If S_butt = 0 then
    pause 250 
    goto savetime
    endif
    goto inp3
    From what I understand PBO has a command / modifier IHEX, but I'm not sure on how to use it. Basically what I would like to do is take those decimal values in the two variables sethour and setmin and convert them to HEX and then place it to the relevant byte that gets written to the RTC... something like

    Code:
    DB0[2] = IHEX sethour
    DB0[1] = IHEX setmin

    The current version uses a BCD conversion... but this is where I think the issues I had detailed in the previous thread lay, - is there a simple way that will convert the values and write them to the relevant bytes for the 1307 ?

  2. #2
    Join Date
    Feb 2011
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Re: RTC take two

    second is variable value which displays sec digits when second is displayed as hex number.

    second = (sec >> 1)*16 + (sec & $F) to convert time number sec to hex value second that displays time number, I think.

  3. #3
    Join Date
    Feb 2011
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Re: RTC take two

    I made a typo error above

    should be --

    second = (sec >> 4)*16 + (sec & $F)

  4. #4
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: RTC take two

    Many thanks

  5. #5
    Join Date
    Feb 2011
    Posts
    60


    Did you find this post helpful? Yes | No

    Default Re: RTC take two

    And if you want to add to time values from DS1307 then convert to decimal before addition --

    sec = (RTCsec >> 4)*10 + (RTCsec & $F)

Similar Threads

  1. I2C RTC Help
    By isaac in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 17th February 2012, 12:32
  2. Rtc Revisted
    By jcleaver in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th March 2007, 05:50
  3. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 18:07
  4. X1226 RTC - Help
    By charudatt in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 14th August 2006, 18:54
  5. Rtc
    By sonic in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 7th May 2004, 06:39

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