Reassigning I/O within the program ?


Closed Thread
Results 1 to 18 of 18

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    >myPIN = 2 ...set this in your IF statements
    >low portb.0[myPIN]


    That would READ PORTB.2, and set either PORTB.0 or PORTB.1 low depending on the state of RB2(0 or 1).

    portb.0[myPIN] = 1 ; lets you control any pin, assuming TRIS has been set

    But it can't be used in SERIN/OUT, PULSIN/OUT, RCTIME, HIGH/LOW, etc., like the PIN numbers can.
    DT

  2. #2
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    >myPIN = 2 ...set this in your IF statements
    >low portb.0[myPIN]


    That would READ PORTB.2, ....
    How in the world wout that READ a pin?

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by tenaja View Post
    How in the world wout that READ a pin?
    With most PBP statements, you only have 3 options for the PIN's.
    It's usually described like this in the manual ...
    Pin may be a constant, 0-15, or a variable that contains a number 0-15 (e.g. B0) or a pin name (e.g. PORTA.0).
    But portb.0[myPIN] is an Array operation.
    The only one of the 3 options that fits an array result is "or a variable that contains a number 0-15".

    In order to know which PIN to use, it has to READ the variable, or in this case do the array operation (reading a PIN).
    Since it's a BIT array, it will only see a 1 or a 0.

    hth,
    DT

  4. #4
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    With most PBP statements, you only have 3 options for the PIN's.
    It's usually described like this in the manual ...


    But portb.0[myPIN] is an Array operation.
    The only one of the 3 options that fits an array result is "or a variable that contains a number 0-15".

    In order to know which PIN to use, it has to READ the variable, or in this case do the array operation (reading a PIN).
    Since it's a BIT array, it will only see a 1 or a 0.

    hth,
    Either we are miscommunicating, or they have changed the way bit arrays work, or you must be misunderstanding bit arrays. I have been using this method for 8 years:
    PORTB.0[PinToChange] = NewPinState

    The value for PinToChange can be any number 0 to7, and this allows you to use it on ANY PORT. The value for NewPinState must be 0 or 1.

    PORTA.0[4] = NewPinState
    PORTB.0[4] = NewPinState

    Will set PortA.4 AND PortB.4 to the NewPinState

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by tenaja View Post
    Either we are miscommunicating, or they have changed the way bit arrays work, or you must be misunderstanding bit arrays. I have been using this method for 8 years:
    PORTB.0[PinToChange] = NewPinState
    Obviously miscommunicating.

    In post #6 you originally said
    myPIN = 2 ...set this in your IF statements
    low portb.0[myPIN] ...allows you to use any port you like, and changing PICs is easy.
    In my reply I stated that portb.0[myPIN] = 1 will work, but it can't be used as a PIN in PBP statements like SERIN/OUT, PULSIN/OUT, RCTIME, HIGH/LOW, etc.

    LOW is a PBP statement with a PIN parameter.
    DT

  6. #6
    Join Date
    Sep 2007
    Location
    USA, CA
    Posts
    271


    Did you find this post helpful? Yes | No

    Default

    Oops, well, I meant them to match.
    The second was pasted from a working file. I don't know why the syntax wouldn't work for a LOW, though.

    The point is, though, that there are ways to do it without the IFs. On the other hand, PBP is dreadfully inefficient, so it might be better to use the IFs anyway.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by tenaja View Post
    ... I don't know why the syntax wouldn't work for a LOW, though.
    That's what I was trying to explain in post#9.
    If there's something in that post you don't understand, I'll try to go a little deeper.

    The point is, though, that there are ways to do it without the IFs. On the other hand, PBP is dreadfully inefficient, so it might be better to use the IFs anyway.
    I completely disgree.
    There are many ways to be inefficient with PBP, but PBP itself is not the bottleneck.
    DT

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