DS1307 Problems help please !!! :-)


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: DS1307 Problems help please !!! :-)

    I tend to convert the time from the RTC chip into two variables such as timeH and timeM for hours and minutes

    Code:
    I2CRead SDApin,SCLpin,$D0,$00,[RTCSec,RTCMin,RTCHour,RTCWDay,RTCDay,RTCMonth,RTCYear,RTCCtrl]  ; read DS1307 chip
    
    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
    And then its a simple matter to match values with other variables to turn lights on or off

    Code:
    lightsetHR = 14                         ' Set lights to come on at 2pm
    lightsetMN = 00  
    
    lightoffHR = 22                         ' Set lights to go off at 10pm
    lightoffMN = 00
    You could then used a simple logic routine like

    Code:
    If timeH >= lightsetHR and timeM>=lightsetMN then turn the lights on
    If timeH < lightsetHR and timeM < lightsetMN or timeH>=lightoffHR and timeM>=lightoffMN then turn lights off

    Or an alternative is to use a counter that resets at midnight. This only works where you need to turn the light on and off between 00:01 and 23:59 in the same day. This basically counts the minutes in a 24 hour period since midnight

    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)                     
    
    Counter1 = (TimeH *60)+ TimeM             'take hours and multiply it by 60 then add odd minutes to get the total minutes into counter1

    Then use if/then statements to match the on / off times to the counter value to turn on / off the light

    Code:
    If Counter1 => OnTime and counter1 < OffTime then                     ' check to see if the time in minutes since midnight matches the on time
    pin made high to turn light on                                                       ' insert the routine to make the pin high and turn the light on
    endif                                                                           
    If Counter1 => OffTime or Counter1 < Ontime then                      ' check to see if the time in minutes since midnight matches the channel off time
    pin made low to turn lamp off                                                  ' insert the line to make the pin low and turn the light off
    I've used both options in various projects and both work within the limitations described above.

    Hope that helps

  2. #2
    Join Date
    May 2012
    Location
    Merseyside, UK
    Posts
    237


    Did you find this post helpful? Yes | No

    Thumbs up Re: DS1307 Problems help please !!! :-)

    Thank you Both

    Both your replies have been implemented now I am running again..... Always have problems with the If/Then/Next Endif stuff :-)

    Thank you again

    BR
    Andy

  3. #3
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: DS1307 Problems help please !!! :-)

    Glad it helped. My solutions may not be the most elegant, but it worked for me... and as all things in life there is always more than one solution

Similar Threads

  1. 7 segment clock PIC16f72 with DS1307 problems!!!!!!!
    By Antorbd04 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 6th December 2013, 16:07
  2. using DS1307
    By Scampy in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 2nd December 2013, 11:01
  3. ds1307
    By jonas2 in forum Code Examples
    Replies: 0
    Last Post: - 2nd November 2009, 10:50
  4. DS1307 help
    By Orlando in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 17th March 2005, 16:17
  5. Ds1307
    By miniman in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 2nd February 2005, 09:29

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