Reference a port pin from a variable


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2012
    Posts
    64

    Default Reference a port pin from a variable

    I know you can reference an I/O pin for a given port in a loop such as “PortC.0(idx)”. I was wondering if there was a similar way to reference pins from multiple ports in one loop. I am looking to access Pins from ports A, B, C, D, and E.

    Thanks,
    Jim

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,521


    Did you find this post helpful? Yes | No

    Default Re: Reference a port pin from a variable

    Hi,
    Looking at the datasheet for the 16F877 for example it shows that all the port registers are concecuitive in memory. So I think it'll work to just do something like
    Code:
    FOR i = 0 to 34 35 bits (depending on how wide PortE is)
    TOGGLE PORTA.0[i]
    NEXT
    Just be careful so you don't write beyond the port registers and obviosuly there will be a "gap" at bits 6 and 7 of port A.
    Never tried it myself.

    /Henrik.

  3. #3
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Reference a port pin from a variable

    Henrik,
    I was thinking the same thing might work, but haven't tried it yet. I will actually be getting the port index from eeprom data, so gaps and order won't matter. I will give it a try and let you know how it worked.

    Thanks,
    Jim

  4. #4
    Join Date
    Feb 2012
    Posts
    64


    Did you find this post helpful? Yes | No

    Default Re: Reference a port pin from a variable

    I just tried that suggestion and it worked.

    Thanks,
    Jim

    Quote Originally Posted by HenrikOlsson View Post
    Hi,
    Looking at the datasheet for the 16F877 for example it shows that all the port registers are concecuitive in memory. So I think it'll work to just do something like
    Code:
    FOR i = 0 to 34 35 bits (depending on how wide PortE is)
    TOGGLE PORTA.0[i]
    NEXT
    Just be careful so you don't write beyond the port registers and obviosuly there will be a "gap" at bits 6 and 7 of port A.
    Never tried it myself.

    /Henrik.

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