Combine bits from various registers into a virtual port

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Combine bits from various registers into a virtual port

551 Views
danielhembree
Contributor III

I'm sure this is a fairly straightforward answer, but it is currently beyond my capability. I have a system that uses the three I/O ports on an MC9S08SE8. The system's I/O ports are made up of a variety of the I/O pins on the MC9S08SE8. Below is an example of this. Although I would have liked to, I was unable to use the entire Port B for LEDs on my system. The last LED is on Port C.

 

#define SRC1_LED PTBD_PTBD4

#define SRC2_LED PTBD_PTBD5

#define SRC3_LED PTBD_PTBD6

#define SRC4_LED PTBD_PTBD7

#define MON1_LED PTBD_PTBD1

#define MON2_LED PTBD_PTBD2

#define MON3_LED PTBD_PTBD3

#define MONO_LED PTCD_PTCD7  

 

How can I programmatically combine these definitions and refer to them as one 'virtual port'? I initially thought a structure would do it but I don't know how to assign the definitions as members of the structure. Structures are a new concept for me anyway.

 

Thanks for the help.

 

Dan

Labels (1)
0 Kudos
3 Replies

441 Views
danielhembree
Contributor III

Perhaps I am misunderstanding the response, but I have no difficulty manipulating the bits individually. What I was originally looking for was a way to group the various and separate bits into one collection and refer to them in that way. I actually did end up using a struct to do this, but not in the way I had originally envisioned. I'm not really even sure what I did was necessary now that I think about it. Anyway, thanks for the help!

Dan

0 Kudos

441 Views
Monica
Senior Contributor III

Hello Daniel,

did you get to try Ian's suggestion?

Please don't forget to keep us posted, we'd like to know.

Best,

Monica.

0 Kudos

441 Views
iansmusical
Contributor V

Hi Daniel,

I don't think I have the full answer but I'd imagine it would be possible using #defines or a 16 bit variable and the use of a structure might be overkill? Either way I think your code will need intelligence so as to know which actual port to write the virtual port value to. Thus something like:

  if the bit corresponding to MONO_LEDPTCD_PTCD7 is set

    write a 1 in bit 7 OR'd with port c

  else /* MONO_LEDPTCD_PTCD7 is reset */

    write a 0 in bit 7 etc

  write the remaining virtual port values to port d

Hope this helps! :-)

Ian

0 Kudos