In old Borland C++ we can define bit fileds in any size like following examples
struct allinputs
{
unsigned Key01 : 1;
unsigned Key02 : 1;
unsigned Key03 : 1;
unsigned Key04 : 1;
unsigned Key05 : 1;
unsigned Key06 : 1;
unsigned Key07 : 1;
unsigned Key08 : 1;
unsigned LeftWise : 1;
unsigned RightWise : 1;
unsigned Start : 1;
unsigned Stop : 1;
unsigned Key12 : 1;
unsigned Key11 : 1;
unsigned Key10 : 1;
unsigned Key09 : 1;
}inputbits;
I test it in code viison and its work very nice the above example for input bits managing and following example for output bits managing
struct allrelay
{
unsigned Relay11:1;
unsigned Relay10:1;
unsigned Relay09:1;
unsigned Left:1;
unsigned Relay15:1;
unsigned Relay14:1;
unsigned Relay13:1;
unsigned Relay12:1;
unsigned Group3LED7:1;
unsigned Group3LED6:1;
unsigned Group3LED5:1;
unsigned Group3LED4:1;
unsigned Group3LED3:1;
unsigned Group3LED2:1;
unsigned Group3LED1:1;
unsigned Group3LED0:1;
unsigned Group2LED0:1;
unsigned Group2LED1:1;
unsigned Group2LED2:1;
unsigned Group2LED3:1;
unsigned Group2LED4:1;
unsigned Group2LED5:1;
unsigned Group2LED6:1;
unsigned Group2LED7:1;
unsigned Relay03:1;
unsigned Relay02:1;
unsigned Relay01:1;
unsigned Relay00:1;
unsigned Right:1;
unsigned Pump:1;
unsigned Relay05:1;
unsigned Relay04:1;
unsigned char SevenSegment;
unsigned Group0LED0:1;
unsigned Group0LED1:1;
unsigned Group0LED2:1;
unsigned Group0LED3:1;
unsigned Group0LED4:1;
unsigned Group0LED5:1;
unsigned Group0LED6:1;
unsigned Group0LED7:1;
unsigned Group1LED7:1;
unsigned Group1LED6:1;
unsigned Group1LED5:1;
unsigned Group1LED4:1;
unsigned Group1LED3:1;
unsigned Group1LED2:1;
unsigned Group1LED1:1;
unsigned Group1LED0:1;
}relaybits;
When I want to transfer SPI bits simply using the following code
- spi(peekb(&relaybits))
- spi(*((unsigned char *) &relaybits + 1))
It depends on the length of the structure information information.
But in the Arduino IDE this definition is not applicable.
The C - Bit Fields not applicable because this definition need more memory. I need only bits in one byte not each bits in another one byte.
Can any body help me to define this bit fields.