This very handy feature allows to use any bit slice of a 8 bit variable in an expression. For this purpose, cpik provides the non-standard syntax
var.OFFSET:SIZEwhich corresponds to a slice of SIZE bits starting at bit number OFFSET of var.
Notice that :
As an example, suppose we need to copy PORTB<0-3>
(configured as input) to PORTB<7-4>
(configured as output).
uint8_t x ; x = PORTB << 4 ; PORTB &= 0x0F ; // clear dest bits PORTB |= x ;
struct { unsigned low:4, hi:4 ; } my_portb@0xF81 ; my_portb.hi = my_portb.low ;Of course, this code supposes that PORTB is at address 0xF81, and will fail if it is not the case anymore.
PORTB.4:4 = PORTB.0:4 ;
Of course, if you need your code to be easily reconfigurable, a couple of macro will do the job:
#define LNIBBLE 0:4 #define HNIBBLE 4:4 PORTB.HNIBBLE = PORTB.LNIBBLE ;
Note that explicit bit fields are always unsigned.
cpik is now released with header files which allow to handle device registers as structures or explicit bit fields. Please see section 12.1 for details.
AG 2013-04-10