Hello,
A "bit array" type does not exist within C.
There are two different methods of addressing a single bit within a register -
- Bit field method, as used within the device header files.
- Bit mask method.
For the bit field method, the macro that is used to define each bit within the bit field may be used for all bit operations (e.g. set bit, clear bit and test bit state), but a separate macro is required for each bit within the register, as you have observed.
Conversely, the bit mask method requires a separate macro for each bit operation, but a common macro may be used for each bit within the register. This method is probably closer to what you require.
The attached file contains a range of macros that make use of the bit mask method. For your specific example, you might create some further macros:
#define SET_OUTPUT(n) b_bset( n, PTBD)
#define CLR_OUTPUT(n) b_bclr( n, PTBD)
Now some general comments:
The most efficient code for setting or clearing a single bit within a page zero register, will make use of the assembly instructions BSET and BCLR. It is known that the CW compiler does do this for the usual bit field method, but I am uncertain whether this remains so for the bit mask method. You would need to check tha ASM output from the compiler.
Some programmers avoid the use of bit fields. Their reason is that, a bit field applied to a 8-bit register is "non-standard" C (16 bits is usually required), and this will be problematic for some non-CW compilers. These programmers would always utilize the bit mask method instead.
Regards,
Mac