Datasheet

typedef struct {
lo_nibble : 4;
hi_nibble : 4;
high_byte : 8;} myunsigned;
which declares the structured type myunsigned containing three components:
lo_nibble (bits 3..0), hi_nibble (bits 7..4) and high_byte (bits 15..8).
Bit Fields Access
Bit fields can be accessed in the same way as the structure members. Use direct
and indirect member selector (. and ->). For example, we could work with our pre-
viously declared myunsigned like this:
// This example writes low byte of bit field of myunsigned type to
PORT0:
myunsigned Value_For_PORT0;
void main() {
...
Value_For_PORT0.lo_nibble = 7;
Value_For_PORT0.hi_nibble = 0x0C;
P0 = *(char *) (void *)&Value_For_PORT0;
// typecasting :
// 1. address of structure to pointer to void
// 2. pointer to void to pointer to char
// 3. dereferencing to obtain the value
}
173
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Language Reference
mikroC PRO for AVR
CHAPTER 5