View Full Version : Multiple IF-THEN statements
DavidK
- 19th June 2007, 09:56
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
sayzer
- 19th June 2007, 10:10
try this;
IF rtcsec <= $07 OR (rtcsec >= $30 AND rtcsec <= $37) THEN
portb.7 = 1
ELSE
portb.7 = 0
ENDIF
-----------------------------
paul borgmeier
- 19th June 2007, 10:36
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
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.
sayzer
- 19th June 2007, 11:27
.... - go with Jerson's version ...
Who is Jerson ?
--------------
Acetronics2
- 19th June 2007, 12:40
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 !!!
DavidK
- 19th June 2007, 15:38
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
paul borgmeier
- 19th June 2007, 17:25
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
Jerson
- 20th June 2007, 05:45
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
sayzer
- 20th June 2007, 10:37
...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...
--------------------
mister_e
- 20th June 2007, 18:09
IF A=B... will B=A ? :D
Acetronics2
- 20th June 2007, 18:17
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
mister_e
- 20th June 2007, 18:28
LMAO! Jule Sayzer :D
Powered by vBulletin® Version 4.1.7 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.