Port Bits Structure

Coding and general discussion relating to the compiler

Moderators: David Barker, Jerry Messina

Post Reply
birtong
Posts: 1
Joined: Thu Mar 21, 2013 3:46 pm
Location: California

Port Bits Structure

Post by birtong » Thu Mar 21, 2013 5:11 pm

Hi,

I need the ability to look through all the IO bits. I would like an array I can index to loop through each bit, starting at PORTA, absolute 80, bit 1 through PORTE, last bit.

Something like:

Dim PORTbits(40) as bit absolute 80

Can I do this to read and write to each bit.

birtong

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Thu Mar 21, 2013 5:34 pm

You can address individual bit in a port like this

Code: Select all

PORTB.Bits(index)
but this will not set TRIS bits for you. In addition, it will not automatically "read from port, write to latch". If you want to iterate through each port and set a bit, use something like:

Code: Select all

FSR0 = AddressOf(LATA)
POSTINC0 = <byte value>
which will set 8 bits at a time. Using POSTINC will increment the address for the next port. To read, use something like AddressOf(PORTA). Note that when writing, you will need to set the direction bits for a port. Also, check the datasheet and make sure any register addresses are contiguous.

Post Reply