Data from DS1307 (BCD) saved to ext memory and read back to display


Results 1 to 11 of 11

Threaded View

  1. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Data from DS1307 (BCD) saved to ext memory and read back to display

    Hi Roger, I'm no expert, but maybe this can be of some use.

    I have these variables to display the time on an LCD

    Code:
    TimeH           var byte                 'variable to store Hours
    TimeM           var byte                 'variable to store Minutes
    SS              VAR Byte                 'variable to store Seconds
    
    RTCsec          var byte                'RTC Seconds
    RTCMin          var byte		        'RTC Minutes
    RTCHour         var byte	            'RTC Hours
    I then read the DS1307 and convert the BDC value into time as follows

    Code:
    I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour]   ' read the RTC
    	
    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)                         'convert the BCD format of the mins register and store in variable timeM
    timeM=(timeM &$07)*10
    timeM=timeM+(RTCMin&$0F)    
    
    ss=(RTCSec>>4)                            'convert the BCD format of the sec register and store in variable ss
    ss=(ss &$07)*10
    ss=ss+(RTCSec&$0F)   
    
    LCDOut $FE,$C0+11,#TimeH DIG 1,#TimeH DIG 0,":",#TimeM DIG 1,#TimeM DIG 0          'display the current time on the LCD
    Now maybe (I don't know as I've never written to an external e-prom) you can save the byte variables for TimeH, TimeM and SS with something like
    Code:
    I2Cwrite SDApin,SCLpin,$insert address of eeprom,[TimeH,TimeM,SS]
    Like I said, I'm no expert, and may be sending you off on a tangent !!

    Forgot to add, this is the routine to convert to BDC if required

    Code:
    CounterA=SetMN
    Gosub ConvertBCD
    RTCMin=CounterB
    
    CounterA=SetHR
    Gosub ConvertBCD
    RTCHour=CounterB
    I2Cwrite SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour]
    
    
    ConvertBCD:
    	CounterB=CounterA DIG 1                        ' CounterA is the entry variable
    	CounterB=CounterB<<4                           ' CounterB holds the converted BCD result on exit
    	CounterB=CounterB+CounterA DIG 0
    Return
    CounterA and CounterB are byte variables, as are setHR and setMN. I used these as the initial time to display on the LCD. For example I want to set the initial time to 12:00 I use 12 for setHR and 0 for setMN. If you need to convert from decimal to BDC before sending to the eepprom, then maybe this bit of code can help ??
    Last edited by Scampy; - 19th July 2016 at 19:19. Reason: added more examples

Similar Threads

  1. Replies: 2
    Last Post: - 3rd January 2013, 17:57
  2. DS1307 - How to store Decimal Value & how to convert back to BCD?
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd January 2011, 00:44
  3. loading data to EXt. eeprom
    By MINHLE in forum General
    Replies: 0
    Last Post: - 28th December 2009, 18:56
  4. Write Onewire data toa I2C memory / read ASCI
    By Eugeniu in forum mel PIC BASIC Pro
    Replies: 67
    Last Post: - 16th November 2008, 20:19
  5. cannot read/write to 16F690 data memory after CPD_ON
    By awdsas in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 22nd November 2006, 12:46

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