mikroC
making it simple...
mikroC - C Compiler for Microchip PIC microcontrollers
Here, tag is an optional name of the structure;
As an object, bit fields structure takes one byte. Individual fields are packed within byte from right to left. In
For example, if we need to manipulate only bits
struct { |
|
|
unsigned | : 2, | // Skip bits 0 and 1, no identifier here |
mybits | : 3; | // Relevant bits 2, 3, and 4 |
|
| // Bits 5, 6, and 7 are implicitly left out |
} myreg; |
|
|
Here is an example: |
| |
typedef struct { |
| |
prescaler | : 2; timeronoff : 1; postscaler : 4;} mybitfield; |
which declares structured type mybitfield containing three components: prescaler (bits 0 and 1), timeronoff (bit 2), and postscaler (bits 3, 4, 5, and 6).
Bit Fields Access
Bit fields can be accessed in same way as the structure members. Use direct and indirect member selector (. and
//Declare a bit field TimerControl: mybitfield TimerControl;
void main() { TimerControl.prescaler = 0; TimerControl.timeronoff = 1; TimerControl.postscaler = 3; T2CON = TimerControl;
}
MikroElektronika: Development tools - Books - Compilers
page
81