Jump to content


Port Encapsulation... Union? Struct?

2 replies to this topic

#1 mityeltu



  • EstablishedMember
  • Pip
  • 86 posts
  • Gender:Male
  • Location:Tennessee
  • Interests:Communications

Posted 09 February 2017 - 04:00 PM

I am trying to encapsulate 2 ports from 18F2620 into a single variable. What I want to be able to do is something like the following pseudocode


variable ex_port = porta:portb // 16 bits of 2 ports in a single variable

for (z = 0, z<16, z++)

ex_port.z = 1

next z


what I'm trying to do is to sequence through both ports as well as to be able to address each individual port pin wihtout having to first address the individual port. I hope that makes sense.


Is there some way to bundle the ports together like this?


Since boostc does not support bitfields, this becomes pretty large if I used a structure of bytes.

I hope I'm not just making this way harder than it needs to be. Is there an easy way?

#2 richardc



  • EstablishedMember
  • 19 posts
  • Gender:Male
  • Location:Gippsland VIC,Australia

Posted 10 February 2017 - 03:21 AM

unsigned int my_port@0x0f80;

would cover it

#3 JorgeF


    Super Enthusiast

  • EstablishedMember
  • PipPipPip
  • 276 posts
  • Gender:Male
  • Location:ES @ Europe, third rock from the Sun

Posted 17 February 2017 - 09:23 PM



The problem is not to join the 2 ports under a single 16 bit variable as long as the 2 ports have concecutive addresses in RAM, , like exemplified by richardc.


The real problem is beeing able to scan all the bits in a loop.

The dot (.) operator when applied to bit access has a serious limitation, it doesn't acept a variable for the bit number.

So you can access all 16 bits (x.0 to x.15) but you can't use the loop index to do it, only compile time constants.


Best regards


Edited by JorgeF, 17 February 2017 - 09:24 PM.

Reply to this topic


1 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

    Bing (1)