PDA

View Full Version : if then problem



Russ Kincaid
- 22nd March 2007, 02:12
This has got to be simple but I can't see the problem. This is my code:
if not GPIO.1 then time1 = 1 else time1 = 0
endif
IF not GPIO.2 THEN time2 = 2 else time2 = 0
endif
IF not GPIO.3 THEN time4 = 4 else time4 = 0
endif
if not GPIO.4 then time8 = 8 else time8 = 0
endif
The compiler error is: bad expression or missing THEN
I tried putting colons in it even tho the manual doesn't say they are needed, but that was no help.

Hmmm, I copied an IF THEN out of the manual and ran it thru the compiler, same error. What's up?

Russ

Darrel Taylor
- 22nd March 2007, 03:45
You can't put the else part on the same line as the IF.

It should look like...
if not GPIO.1 then
time1 = 1
else
time1 = 0
endif

But then, all you are really doing is inverting the bit, so you could do this.
time1 = GPIO.1 ^ 1
time2 = GPIO.2 ^ 1
time3 = GPIO.3 ^ 1
time4 = GPIO.4 ^ 1
OR, you could do them all at once if the variables are setup right.

time VAR BYTE
time1 VAR time.1
time2 VAR time.2
time3 VAR time.3
time4 VAR time.4

time = GPIO ^ %11110
<br>

Russ Kincaid
- 23rd March 2007, 02:35
Thanks, I can see I have a lot to learn. What is that carot thingy doing? If GPIO is high, does it make it low and vice versa?

Archangel
- 23rd March 2007, 06:39
Thanks, I can see I have a lot to learn. What is that carot thingy doing? If GPIO is high, does it make it low and vice versa?

Hi Russ,
see page 36 section 4.17.14 Bitwise Operators
JS