Using parentheses for operation order when setting an IO pin?


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Jun 2005
    Posts
    53


    Did you find this post helpful? Yes | No

    Default Re: Using parentheses for operation order when setting an IO pin?

    After having issues with the original code, I did switch mine to

    Code:
    GoSub SetAllPinsHigh
    Select Case Mode
        Case 1
            PinA = 0
        Case 2
            PinB = 0
        Case 3
            PinC = 0
        Case 4
            PinD = 0
        Case 5
            PinE = 0
    End Select
    Which did work and I did notice the word count dropped a bit. Your code looks like a pretty good way to do it too, thanks! Is there much difference between BRANCH and SELECT CASE? It looks like BRANCH needs GOTOs to avoid running through any following modes but is BRANCH a more simple / smaller option?

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


    Did you find this post helpful? Yes | No

    Default Re: Using parentheses for operation order when setting an IO pin?

    Mark, I did notice that some combined statements like :

    IF JUNK & %11110000 = %11110000 THEN 'LOOK AT CURRENT STATE "this doesn't work"
    don't work unless surrounded by parenthesis are :

    IF ((JUNK & %11110000) = %11110000) THEN 'LOOK AT CURRENT STATE "This works"

    I noticed it with such directives as the "&" and the "%".
    Dave Purola,
    N8NTA
    EN82fn

  3. #3
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default Re: Using parentheses for operation order when setting an IO pin?

    Quote Originally Posted by markedwards View Post
    After having issues with the original code, I did switch mine to

    Code:
    GoSub SetAllPinsHigh
    Select Case Mode
        Case 1
            PinA = 0
        Case 2
            PinB = 0
        Case 3
            PinC = 0
        Case 4
            PinD = 0
        Case 5
            PinE = 0
    End Select
    Which did work and I did notice the word count dropped a bit. Your code looks like a pretty good way to do it too, thanks! Is there much difference between BRANCH and SELECT CASE? It looks like BRANCH needs GOTOs to avoid running through any following modes but is BRANCH a more simple / smaller option?

    if you can change the Mode to arrive as 1-2-4-8-16 then ;

    Code:
    GoSub SetAllPinsHigh
    PinA = ~Mode.0 '%00000001
    PinB = ~Mode.1 '%00000010
    PinC = ~Mode.2 '%00000100
    PinD = ~Mode.3 '%00001000
    PinE = ~Mode.4 '%00010000
    Could work.
    Last edited by sayzer; - 16th September 2018 at 09:26.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

Similar Threads

  1. Strange Behavior in setting several pin outputs states.
    By kappuz in forum mel PIC BASIC Pro
    Replies: 19
    Last Post: - 5th August 2017, 15:57
  2. How do you time an operation?
    By Hylan in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 18th May 2010, 10:41
  3. Setting a pin twice
    By RUBiksCUbe in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th September 2006, 01:45
  4. Must reset PIC to get correct operation?
    By Christopher4187 in forum General
    Replies: 5
    Last Post: - 2nd June 2006, 01:59
  5. Minimum power operation - 16F877A
    By btaylor in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 2nd March 2006, 02:44

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