If...then...else


Closed Thread
Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2010
    Posts
    25

    Default If...then...else

    Why do I get a Syntax Error for the ELSE row?

    loop2:
    ADCIN 0, involt 'Read channel 0 to involt
    PAUSE 100 'Wait 100 ms
    IF involt >= 128 THEN GPIO.5 = 0
    ELSE GPIO.5 = 1 ENDIF
    GOTO loop2
    END

    PIC12F683 & PBP2.60

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    ELSE likes to be on a line of it's own.
    Try

    Code:
    loop2: 
    ADCIN 0, involt 'Read channel 0 to involt
    PAUSE 100 'Wait 100 ms
    IF involt >= 128 THEN GPIO.5 = 0 
    ELSE 
    GPIO.5 = 1 
    ENDIF
    GOTO loop2
    END
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Aug 2010
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    ELSE likes to be on a line of it's own.
    No, didn't help:

    ERROR Line 30: ELSE without a matching IF..THEN. (ADC1.pbp)
    ERROR Line 32: ENDIF without a matching IF..THEN. (ADC1.pbp)

    That would suggest that they should all be on the same row, but that was my first attempt.

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by mikebike View Post
    No, didn't help:

    ERROR Line 30: ELSE without a matching IF..THEN. (ADC1.pbp)
    ERROR Line 32: ENDIF without a matching IF..THEN. (ADC1.pbp)

    That would suggest that they should all be on the same row, but that was my first attempt.
    Code:
    loop2: 
    ADCIN 0, involt 'Read channel 0 to involt
    PAUSE 100 'Wait 100 ms
    
    IF involt >= 128 THEN 
      GPIO.5 = 0 
    ELSE 
      GPIO.5 = 1 
    ENDIF
    
    GOTO loop2
    END
    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 " !!!
    *****************************************

  5. #5
    Join Date
    Aug 2010
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    Thanks, that worked. But why?

  6. #6
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    IF xxx THEN label
    can be on one line because it act as a GOTO.
    If not a label the THEN needs to be on a second line.
    YUP, I messed up on my first post. Was not paying attention...
    Dave
    Always wear safety glasses while programming.

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mikebike View Post
    Thanks, that worked. But why?
    simply because the compiler considers there's no need for ELSE nor ENDIF, if he sees anything on the right side of THEN ...

    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 " !!!
    *****************************************

  8. #8
    Join Date
    Aug 2010
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    There is a lot to think of......

    But my very first program works just fine now!

    One LED blinks every second and goes on continously after 9 minutes.
    Another LED goes on when the voltage drops below 2.5 Volts....

    B.t.w. I understand that there is a calibration factor inside each PIC that shall/could be used to get better clock accuracy.
    Is the PBP using this automatically?
    My 9 minute timer is accurate within 1 second (two different PICs) just as it is.

  9. #9
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    The calibration on the chip seems to be pretty good from the factory, normally.
    PBP does not use it nor control the speed of the chip with the exception of OSCON. PBP code can be used to change the factory setting if needed.
    Dave
    Always wear safety glasses while programming.

  10. #10
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,651


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mikebike View Post

    B.t.w. I understand that there is a calibration factor inside each PIC that shall/could be used to get better clock accuracy.
    Is the PBP using this automatically?
    .
    No ... PBP doesn't use it automatically ...

    the 683 has a factory calibration value you can't access to. you just have the OSCTUNE register to modify somewhat the osc speed, if you need it.
    in INTOSC_HF mode only ....

    factory cal is supposed to be good ... but you can trim to your needs ( I did it with a 16F88, to get exact R/C timings with internal OSC . trimming was less than 10 units ... )

    @ contrario, The 629 and 675 ( i.e. ) need to fetch the cal data and store it @ poweron ... achieved through DEFINE OSCCAL_1K 1

    just read relevant µChip datasheets , OSC Chapter , to see how it works, then PBP manual firsts pages ...

    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 " !!!
    *****************************************

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