Why I use bitfields... is because I want to quickly set a variable to an individual port or to a defined set off ports. Depending of the function and a hardware switch.
So the first structure is nested in a header file that was giving with the compiler and example projects. This header contains all references to registers and such. It contains the first struct part with individual variables per port...
Expand|Select|Wrap|Line Numbers
- typedef union{ /* PORT DATA */
- IO_BYTE byte;
- struct{
- IO_BYTE P00 :1;
- IO_BYTE P01 :1;
- IO_BYTE P02 :1;
- IO_BYTE P03 :1;
- IO_BYTE P04 :1;
- IO_BYTE P05 :1;
- IO_BYTE P06 :1;
- IO_BYTE P07 :1;
- }bit;
- }PDR0STR;
- __IO_EXTERN __io PDR0STR _pdr0
- #define PDR0 _pdr0.byte
- #define PDR0_P00 _pdr0.bit.P00
- #define PDR0_P01 _pdr0.bit.P01
- #define PDR0_P02 _pdr0.bit.P02
- #define PDR0_P03 _pdr0.bit.P03
- #define PDR0_P04 _pdr0.bit.P04
- #define PDR0_P05 _pdr0.bit.P05
- #define PDR0_P06 _pdr0.bit.P06
- #define PDR0_P07 _pdr0.bit.P07
Expand|Select|Wrap|Line Numbers
- #include "mb90560.h"
- #include "prototypes.h"
- struct myport{
- int adc_act: 7;
- int adc_indicator : 1;
- };
- void main(void)
- {
- myport = &PDR0
- and so on...
Simply put, I've tried a different approach with bitmasking but in combination with interrupts... i don't like the idea that an interrupt happens in the middle of the bitmasking proces.
I hope someone can shine a little light on where I'm stuck. A second bitfield struct seemed the best solution, but it is also the hardest (for me then) to make it work at the same register location.