if then problem


Closed Thread
Results 1 to 4 of 4

Thread: if then problem

  1. #1
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107

    Default if then problem

    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
    Last edited by Russ Kincaid; - 22nd March 2007 at 02:26.

  2. #2
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    You can't put the else part on the same line as the IF.

    It should look like...
    Code:
    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.
    Code:
    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.
    Code:
    time    VAR BYTE
      time1 VAR time.1
      time2 VAR time.2
      time3 VAR time.3
      time4 VAR time.4
    
    time = GPIO ^ %11110
    <br>
    DT

  3. #3
    Join Date
    Jan 2006
    Location
    New Hampshire, USA
    Posts
    107


    Did you find this post helpful? Yes | No

    Default

    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?

  4. #4
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Russ Kincaid View Post
    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
    If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
    .
    Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
    .
    There simply is no "Happy Spam" If you do it you will disappear from this forum.

Similar Threads

  1. problem using GOSUB under interrupt
    By fobya71 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 5th March 2010, 19:52
  2. USART Problem , but don't know where, in pc? or in PIC?
    By precision in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 15th July 2007, 08:12
  3. Microcode Studio 18f2455 problem?????
    By volkan in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 21st May 2007, 21:04
  4. Hardware problem or what ?
    By Steve S. in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 4th March 2007, 21:39
  5. 1 slave 1 master 1 MAX232 1 problem ?
    By SuB-ZeRo in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 31st July 2005, 22:59

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