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
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.
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
Re: Reference a port pin from a variable
I just tried that suggestion and it worked.
Thanks,
Jim
Quote:
Originally Posted by
HenrikOlsson
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.