PDA

View Full Version : Reference a port pin from a variable



JimAvanti
- 10th February 2012, 19:05
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

HenrikOlsson
- 11th February 2012, 08:23
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

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.

JimAvanti
- 13th February 2012, 05:15
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

JimAvanti
- 15th February 2012, 20:18
I just tried that suggestion and it worked.

Thanks,
Jim


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

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.