Matching time conditions


Closed Thread
Results 1 to 40 of 49

Hybrid View

  1. #1
    Join Date
    Jan 2009
    Location
    California, USA
    Posts
    323


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by malc-c View Post
    Scrub my last post - I used your HIGH LOW example and it worked
    If HIGH / LOW works, but PORTD.7 = 1 DOESN'T work, that sounds like a sure sign that you don't have your pin correctly set as an output.

    Using HIGH or LOW automatically sets the pin as an output first before it sets it high or low

    Check your TRIS settings again. PORTD.7 = 1 SHOULD work if the port is set up right....


    steve

  2. #2
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Thanks Steve... I had the TRISO for port D set so no Idea !

    One last thing (for tonight)

    I added a section for minutes too and could get the LED to come on at say 22:34 and go out at 22:35.

    Code:
    AlarmH1=(RTCHour>>4)
    AlarmH1=(AlarmH1&$03)*10
    AlarmH1=AlarmH1+(RTCHour&$0F)
    
    AlarmM1=(RTCMin>>4)
    AlarmM1=(AlarmM1&$03)*10
    AlarmM1=AlarmM1+(RTCMin&$0F)
        
    AlarmHour1 = 22
    Alarmmin1 = 34
    	
    	LCDOut ":",#(RTCMin>>4)&$0F,#RTCMin&$0F,":"
    	LCDOut #(RTCSec>>4)&$0F,#RTCSec&$0F," "
    	LCDOut $FE, $D4,"value = ",  # alarmh1, #alarmhour1
    
    If AlarmH1 = AlarmHour1 and AlarmM1 = alarmmin1 then
    HIGH PortD.7
    else
    LOW PortD.7
    endif
    So I added a a few more variables to try and set a time range but whilst it compiles it no longer lights the LED.


    Code:
    AlarmH1=(RTCHour>>4)
    AlarmH1=(AlarmH1&$03)*10
    AlarmH1=AlarmH1+(RTCHour&$0F)
    
    AlarmM1=(RTCMin>>4)
    AlarmM1=(AlarmM1&$03)*10
    AlarmM1=AlarmM1+(RTCMin&$0F)
        
    AlarmHour1 = 22
    Alarmmin1 = 53
    alarmhour2 = 22
    Alarmmin2 = 55
    	
    	LCDOut ":",#(RTCMin>>4)&$0F,#RTCMin&$0F,":"
    	LCDOut #(RTCSec>>4)&$0F,#RTCSec&$0F," "
    	LCDOut $FE, $D4,"value = ",  # alarmh1, #alarmhour1
    
    If AlarmH1 >= AlarmHour1 and AlarmH1 <= alarmhour2 and AlarmM1=>alarmmin1 and alarmM1<= alarmmin2 then
    HIGH PortD.7
    else
    LOW PortD.7
    endif
    Any ideas ?

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi Malcolm,

    I'm wondering if you missed the link I showed in post 11.

    I really think that's what you're looking for.
    <br>
    DT

  4. #4
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Hi Darrel,

    Must of overlooked that... I'll have a read at work in the morning, and the see if I can implement the suggestions... It's getting late, my two little gray cells have gone to sleep...

  5. #5
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Malcolm, you can't have '&$03' for MINUTES (the way you have for HOURS)... but can you figure why and what value it should be if not $03? Correct that small omission and your code will run (there's incentive for you).

  6. #6
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie View Post
    Malcolm, you can't have '&$03' for MINUTES (the way you have for HOURS)... but can you figure why and what value it should be if not $03? Correct that small omission and your code will run (there's incentive for you).
    I have a hunch it's to do with the register map



    Only the 1st 4 bits are used for hours (0-23) when in 24 Hr mode, where as the minutes use 7 bits of the byte, the latter 3 to store the tens. However I confess at the moment I'm at a loss as to what value I need
    Attached Images Attached Images  

  7. #7
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Never Cut & Paste without first knowing what it is you're doing, otherwise I'll be tempted to put up some code so your PIC will email me the passwords to your Bank Account.

    Let's do this real slow step by step...

    Look at the HOURS Register... and the first line of code...

    Code:
    Bit 7 6 5 4 3 2 1 0
    
        x x f e d c b a  = RTCHour
    
        0 0 0 0 x x f e  = DecimalHour after >>4 rotation
    the 'x' bits we're not interested in, the other bits we are... I've named them from a (Bit 0) through to f (Bit 5). Notice after the >>4 where we shift everything four places to the right we're left with the bits that were in positions 4 thru 7 shifted into positions 0 thru 3, the bits that previously occupied 0-3 have been shifted into oblivion and with zero's shifted into the upper four bits (positions 4-7).

    The next stage is we AND it with $03... this is because we're only interested in the bits located at 0 and 1, and those two x's could be crap we don't want...

    Code:
    Bit 7 6 5 4 3 2 1 0
    
        0 0 0 0 x x f e  = DecimalHour
    
        0 0 0 0 0 0 1 1  = AND'd with $03
    
        0 0 0 0 0 0 f e  = Result after AND operation
    We then multiply the resultant by ten (since it's the TENS digit, and we finally add in the lower four bits of RTCHour ... and that just to clarify visually what ANDing with $0F accomplishes...

    Code:
    Bit 7 6 5 4 3 2 1 0
    
        x x f e d c b a  = RTCHour
    
        0 0 0 0 1 1 1 1  = AND'd with $0F
    
        0 0 0 0 d c b a  = Result after AND operation (the enitire UNITS DIGIT of the BCD RTCHour Register)
    NOW, when you're dealing with MINUTES (see your Datasheet Register for MINUTES) you will notice we have bits 0 thru 6 which are significant (not bits 0 thru 5 as with the HOUR). So if you use $03, you will be happy ONLY if you have 00-39 minutes (because bit 6 of the TENS DIGIT is never extracted - it's masked out - therefore minutes 40-59 won't work)... so instead of $03 you need to do $07 as follows...

    Code:
    Bit 7 6 5 4 3 2 1 0
    
        x g f e d c b a  = RTCMinute
    
        0 0 0 0 x g f e  = DecimalMinute after >>4 rotation
    
        0 0 0 0 0 1 1 1  = AND'd with $07
    
        0 0 0 0 0 g f e  = DecimalMinute AFTER ANDing with $07
    Only then you can multiply it by ten (since it's the TENS DIGIT) and add-in the units as previously.

    Clear as mud I trust?

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