Matching time conditions - Page 2


Closed Thread
Page 2 of 2 FirstFirst 12
Results 41 to 49 of 49
  1. #41
    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 ?

  2. #42
    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

  3. #43
    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...

  4. #44
    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).

  5. #45
    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  

  6. #46
    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?

  7. #47
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default

    Mel,

    Thanks for the very detailed explanation, it has helped as I wasn't sure how the $xx was related to the binary (ie 07 in binary being 111) and what exactly the >> related to.

    I'll try your suggestion tonight - Thanks for the lesson, and I promise to do my homework from now on

  8. #48
    malc-c's Avatar
    malc-c Guest


    Did you find this post helpful? Yes | No

    Default Now have it working

    Mel, with your help I now have something I can work with

    Code:
    AlarmH1=(RTCHour>>4)
    AlarmH1=(AlarmH1&$03)*10
    AlarmH1=AlarmH1+(RTCHour&$0F)
    
    AlarmM1=(RTCMin>>4)
    AlarmM1=(AlarmM1&$07)*10
    AlarmM1=AlarmM1+(RTCMin&$0F)
    
    AlarmH2=(RTCHour>>4)
    AlarmH2=(AlarmH2&$03)*10
    AlarmH2=AlarmH2+(RTCHour&$0F)
    
    AlarmM2=(RTCMin>>4)
    AlarmM2=(AlarmM2&$07)*10
    AlarmM2=AlarmM2+(RTCMin&$0F)
        
    AlarmHour1 = 19
    Alarmmin1 =  07
    AlarmHour2 = 19
    AlarmMin2 = 09
    
    	
    	LCDOut ":",#(RTCMin>>4)&$0F,#RTCMin&$0F,":"
    	LCDOut #(RTCSec>>4)&$0F,#RTCSec&$0F," "
        LCDOut $FE, $94,"H1M1= ",#AlarmH1,":",#AlarmM1," ",#AlarmH2,":",#AlarmM2
    	LCDOut $FE, $D4,"set= ",#alarmhour1,":",#alarmmin1," ",#alarmhour2,":",#AlarmMin2 
    
    If AlarmHour1=AlarmH1 and alarmmin1=AlarmM1 then
     HIGH PortD.7
     endif
    if alarmhour2=AlarmH2 and AlarmMin2=alarmm2 then 
      LOW PortD.7
    endif
    Ignore the lcdout alarmm1 etc, that was just to view the values. Interestingly it shows 19:05 as 19:5, but works regardless.

    Thanks to everyone who contributed (both on the board and via e-mail), especially Mel for taking so much trouble to explain things in layman terms

  9. #49
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Malc... if you want 05:05:07 rather than 5:5:7 then...

    LCDOut DEC2 DecimalHours,":",DEC2 DecimalMinutes,":",DEC2 DecimalSeconds

    hmmmm... DEC2 seems to be something to look up in the manual here...

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