Hi,
I want to define a register say my_flages and also define each bit separately to access individually. For example bit 0 of my_flages as key_on. And to set bit 0 in C
Key_on = 1;
And also to do other basic operations the same way.
Thanks
Herschel
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi,
I want to define a register say my_flages and also define each bit separately to access individually. For example bit 0 of my_flages as key_on. And to set bit 0 in C
Key_on = 1;
And also to do other basic operations the same way.
Thanks
Herschel
Try this...
Use Bitwise operations to extract each bit...
#define key_on 0x01
#define bit1 0x02
#define bit2 0x04
#define bit3 0x08
#define bit4 0x10
#define bit5 0x20
#define bit6 0x40
#define bit7 0x80
unsigned my_flages = 0;
if (my_flages & key_on)...
if(my_flages & bit1)...
if(my_flages & bit2)...
if(my_flages & bit3)...
if(my_flages & bit4)...
if(my_flages & bit5)...
if(my_flages & bit6)...
if(my_flages & bit7)...
Hope this helps,
Mark
Hi Mark,
Thanks for your reply. This how I have been doing this but what I want is to define individual bits on a register and manupilate individual bits
Example;
if (my_flages)......
rather than using the AND operator to the entire register.
Can it be done?
Herschel