C18 structure for 'bits'

Status
Not open for further replies.
i use it:

//First:
//Create a standard struct of 8 bits

volatile struct _8bits
{
unsigned bit0:1;
unsigned bit1:1;
unsigned bit2:1;
unsigned bit3:1;
unsigned bit4:1;
unsigned bit5:1;
unsigned bit6:1;
unsigned bit7:1;
};

/*After that, every time that I want to create a (unsigned char) controlling every bit I do that*/

struct _8bits FLAG_xxx

//Declare every bit

#define usable_bit_a FLAG_xxx.bit0
#define usable_bit_b FLAG_xxx.bit1
#define usable_bit_c FLAG_xxx.bit2
#define usable_bit_d FLAG_xxx.bit3
#define usable_bit_e FLAG_xxx.bit4
#define usable_bit_f FLAG_xxx.bit5
#define usable_bit_g FLAG_xxx.bit6
#define usable_bit_h FLAG_xxx.bit7


//using in code - example
usable_bit_a = 0;


/*---------- THA-DÁ! -------------*/


//another struct of bit example

volatile struct
{
unsigned LEFT:1;
unsigned RIGHT:1;
unsigned UP:1;
unsigned DOWN:1;
} KEY;

//using in code - example

if (KEY.LEFT == 1)
{

//true

}
else
{

//false

}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…