"Select Case" Help


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    bmsherma, Try this...

    SELECT CASE VOLTAGE

    CASE < 257
    PORTC = %0001

    CASE < 513
    PORTC = %0010

    CASE < 769
    PORTC = %0100

    CASE < 1024
    PORTC = %1000

    END SELECT
    Pause 100

    I use this construct when determining groups of numbers. You start with the smallest and move up to the largest.

    Dave Purola,
    N8NTA

  2. #2
    Join Date
    Nov 2009
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Thanks

    Thanks everyone for the advice.

    Dave P, your idea seems to work. However what if I want to isolate the low range OR the high range. I'm essentially trying to put logical operators in my case statement.

    Case is < 256 OR is > 768
    PORTC = %0001

    Case Else
    PORTC = %1000

    Can I write that first Case statement with the OR term?

    Or would I have to do this:

    Case is < 256
    PORTC = %0001
    Case is > 768
    PORTC = %0001
    Case else
    PORTC = %1000

    Is there no way to use logical operators in Case Statements in PICBasicPRO??!

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    bmsherma, The second way you have it is the way I would do the construct..

    Dave Purola,
    N8NTA

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by bmsherma View Post
    Is there no way to use logical operators in Case Statements in PICBasicPRO??!
    NO!, logical operators are NOT allowed in Case statements.
    <br>
    DT

  5. #5
    Join Date
    Nov 2009
    Posts
    3


    Did you find this post helpful? Yes | No

    Default Thanks

    Thanks everyone for the help!!

    This forum is GREAT

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,653


    Did you find this post helpful? Yes | No

    Wink

    Hi,

    With a very, very very little Trickery ... I think it makes it.

    Code:
    IF ( Voltage.8 ^ Voltage.9 ) THEN 
    
       PORTC = 1
    
    ELSE
    
       PORTC = 8
    
    ENDIF
    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 " !!!
    *****************************************

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


    Did you find this post helpful? Yes | No

    Wink

    Or ... With Select Case

    Code:
    Voltage = Voltage.Highbyte
    
    SELECT CASE Voltage
    
        Case 1,2
    
           PORTC = 1
    
        Case Else
    
           PORTC = 8
    
    END SELECT
    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 : 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