Matching time conditions


Closed Thread
Results 1 to 40 of 49

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Steve,

    Thanks for that, which I guess is similar to some of the code posted above.

    This is the section of code based on your suggestion, and it too displays the value of AlarmH1 as 21 when the rtc is displaying 21 hrs, however the led on D7 fails to light (I've tested an the hardware works)

    Code:
    //    Alarmh1 =(rtchour>>4)*10+(rtchour & $0F)  
        alarmhour = 21
    	
    	LCDOut ":",#(RTCMin>>4)&$0F,#RTCMin&$0F,":"
    	LCDOut #(RTCSec>>4)&$0F,#RTCSec&$0F," "
    	LCDOut $FE, $D4,"value = ",  dec alarmh1
    
        if alarmhour = alarmh1 then
         PORTD.7=1
        endif
    Welcome any comments... even if it's to point out the illogical of my logical coding.

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


    Did you find this post helpful? Yes | No

    Default

    Mel, thanks for the post, which happened whilst I was typing mine.

    It's not the displaying of the time I'm having a brain freeze on, it's working out how to do the comparison with another variable so that if the condition is true (ie the hour set ( between 0 and 23) matches the RTC hour) the LED can be made to light (or a value in another variable can be set)

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


    Did you find this post helpful? Yes | No

    Default

    Last three lines of my post Malcolm...

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie View Post
    Last three lines of my post Malcolm...
    Mel,

    I've used your example but still can't make the LED go high

    Code:
    AlarmH1=(RTCHour>>4)
    AlarmH1=(AlarmH1&$03)*10
    AlarmH1=AlarmH1+(RTCHour&$0F)
        
    alarmhour = 21
    	
    	LCDOut ":",#(RTCMin>>4)&$0F,#RTCMin&$0F,":"
    	LCDOut #(RTCSec>>4)&$0F,#RTCSec&$0F," "
    	LCDOut $FE, $D4,"value = ",  # AlarmH1
    
        if AlarmH1 = alarmhour then
         PORTD.7=1
        endif
    The LCD displays 21 as the value for AlarmH1

    what am I doing wrong ???

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


    Did you find this post helpful? Yes | No

    Default

    You've set TRIS for PORTD.7 for Output?

    You've checked that anything else that share that pin is switched off (eg any Analogue or other devices).

    You've connected your LED the correct way around (with a current limiting Resistor) and it works?

    Personally I like to use HIGH and LOW... eg...

    HIGH PortD.7

    eg

    If AlarmH1=AlarmHour then
    HIGH PortD.7
    else
    LOW PortD.7
    endif

  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
    You've set TRIS for PORTD.7 for Output?

    You've checked that anything else that share that pin is switched off (eg any Analogue or other devices).

    You've connected your LED the correct way around (with a current limiting Resistor) and it works?

    Personally I like to use HIGH and LOW... eg...

    HIGH PortD.7

    eg

    If AlarmH1=AlarmHour then
    HIGH PortD.7
    else
    LOW PortD.7
    endif
    Scrub my last post - I used your HIGH LOW example and it worked

    Thank you.....

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


    Did you find this post helpful? Yes | No

    Default

    LOL - the LED just went out as the clock turned to 22:00 hrs

    The best bit is I've learned more about datasheets through this thread, and some of the pitfalls of my poor coding

    Thank you for your patience Mel - I do appreciate it

  8. #8
    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

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


    Did you find this post helpful? Yes | No

    Default

    If I use the LCD to check, I get 21 for both values of AlarmH1 and alarmhour, so the two do match... and I've tried PortB.5 just in case port D wasn't set for output (well it's been along day !)

    Code:
    LCDOut $FE, $D4,"value = ",  # alarmh1, #alarmhour

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