Multiple IF-THEN statements


Closed Thread
Results 1 to 12 of 12
  1. #1
    Join Date
    Jun 2006
    Location
    California
    Posts
    33

    Default Multiple IF-THEN statements

    I know it is late and maybe that is the problem. I am trying to run multiple IF-THEN statements. Individually they work fine, but combining them does not. The combined statements assemble fine. BTW, I am reading a clock chip and after every minute rollover, I cycle a cooling fan approx 7 seconds at the 0 second point and 30 second point. I may have to adjust this time (or increase the number of cycles) so I want to be flexible. Where am I missing it?

    IF (rtcsec >= $00) AND (rtcsec <= $07) THEN
    portb.7 = 1
    IF (rtcsec >= $30) AND (rtcsec <= $37) THEN
    portb.7 = 1
    ELSE
    portb.7 = 0
    ENDIF
    ENDIF

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    try this;

    Code:
    IF rtcsec <= $07 OR (rtcsec >= $30 AND rtcsec <= $37) THEN
       portb.7 = 1
    ELSE
       portb.7 = 0
    ENDIF

    -----------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by DavidK View Post
    I know it is late and maybe that is the problem. I am trying to run multiple IF-THEN statements. Individually they work fine, but combining them does not. The combined statements assemble fine. BTW, I am reading a clock chip and after every minute rollover, I cycle a cooling fan approx 7 seconds at the 0 second point and 30 second point. I may have to adjust this time (or increase the number of cycles) so I want to be flexible. Where am I missing it?

    IF (rtcsec >= $00) AND (rtcsec <= $07) THEN
    portb.7 = 1
    IF (rtcsec >= $30) AND (rtcsec <= $37) THEN
    portb.7 = 1
    ELSE
    portb.7 = 0
    ENDIF
    ENDIF
    Here is why yours did not work - all I did was format your IF-Thens

    Code:
    IF (rtcsec >= $00) AND (rtcsec <= $07) THEN
    	portb.7 = 1
    	IF (rtcsec >= $30) AND (rtcsec <= $37) THEN 
    		portb.7 = 1
    	ELSE
    		portb.7 = 0
    	ENDIF
    ENDIF
    As you can see in order for the code to reach your between 30-37 check, the first condition must be true (between 0-7) - go with Jerson's version or two separate checks like you said you had working.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  4. #4
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by paul borgmeier
    .... - go with Jerson's version ...
    Who is Jerson ?


    --------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Post one test only version ...

    Hi,

    May be we could simplify ...

    RTCSEC is ALWAYS >= 0 with PbP ... huh ...


    IF ( RTCSEC & $F0) = 0 or 3 ... AND
    IF RTCSEC & $0F < 8 ... PortB.7 = 1

    Else Portb.7 = 0

    so,

    IF (( rtcsec & $F0 = 0 ) OR (rtcsec & $F0 = $30 )) AND ( rtcsec & $0F < 8 ) THEN
    PORTB.7 = 1
    ELSE
    PORTB.7 = 0
    ENDIF

    ...


    Alain

    PS: Hi Sayzer ... you've also got one point !!!
    Last edited by Acetronics2; - 19th June 2007 at 12:52.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    Jun 2006
    Location
    California
    Posts
    33


    Did you find this post helpful? Yes | No

    Talking

    WOW !! That simple. I was real foggy last night. Tried the code suggestion and it works perfect. Now hopefully I can get by with just two cooling’s otherwise I have to install a temperature sensor, wich I might do anyway. Fans make noise.

    Thanks everyone for your help and explanations

  7. #7
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Red face

    Quote Originally Posted by sayzer View Post
    Who is Jerson ?


    --------------
    MY apologies - Please substitute Sayzer for Jerson. That is what staying up to 4AM gets me. Jerson regularly contributes and for some reason, I mixed you up when I was writing my reply? (I hope neither of you are offended by that - if you are, next time either of you are in SLC, UT, I will by you a beer or a beverage of your choice).

    Paul
    Last edited by paul borgmeier; - 19th June 2007 at 17:27.
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  8. #8
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    947


    Did you find this post helpful? Yes | No

    Default

    Who is Jerson ?
    Hey, that's me. No offence taken Paul. I am in a way lucky to be entitled to one of your free beers/beverages. Thanks.

    Jerson

  9. #9
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by paul borgmeier View Post
    ...Please substitute Sayzer for Jerson. ...

    Paul
    Which one is correct ?

    "Please substitute Sayzer for Jerson" OR "Please substitute Jerson for Sayzer ".


    I am confused a little there.

    Is it something with my English or my understanding?

    P.S. - Not offended of any kind...
    --------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  10. #10
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    IF A=B... will B=A ?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  11. #11
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,615


    Did you find this post helpful? Yes | No

    Talking

    Hi, Steve

    You're Wrong ...

    Here you will find ALL "SAYZER" or ALL "JERSON" ...

    no "equality" between them anywhere ...

    Let's say ...

    Give back to Sayzer what's Jule's ... ( Approximate joke ... but I really love it ... ever heard of Jules Sayzer ??? ... "tu quoque mi fili, "etc,etc ...)

    and give back to Jerson ... What's jerson's ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  12. #12
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    LMAO! Jule Sayzer
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Similar Threads

  1. Multiple PICS from Same Crystal?
    By WOZZY-2010 in forum General
    Replies: 2
    Last Post: - 6th February 2010, 15:18
  2. Multiple RETURNS within a single subroutine
    By BrianT in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 21st June 2009, 16:43
  3. How much code space do PBP statements use.
    By Darrel Taylor in forum Code Examples
    Replies: 5
    Last Post: - 13th February 2009, 21:31
  4. Multiple SERIN's
    By JoeR in forum mel PIC BASIC
    Replies: 4
    Last Post: - 6th October 2005, 22:22
  5. Multiple IR LEDs from 1 port using transistor
    By belpe123 in forum General
    Replies: 3
    Last Post: - 20th May 2005, 22:07

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