View previous topic :: View next topic |
Author |
Message |
MikeW
Joined: 15 Sep 2003 Posts: 184 Location: Warrington UK
|
Bit toggling a variable |
Posted: Wed Oct 12, 2005 6:29 am |
|
|
I have spent an hour trying to sort this out, and failed.
I am trying to toggle a bit in a variable.
I define a flag
int16 General_Flags1;
then define the bit
#define T_1Sec_Toggle_Flag T_Timer_Flags,15
so, i think that bit 15 of General_Flags1 holds my boolean
I now wish to toggle that bit by using something like :-
#define bit_toggle(my_bit) {#asm btg my_bit #endasm}
of course, this only works for a byte, so i get an error saying it can only be 0..7, not 15
can some guru help ?
is there a better way.
Basically, I am looking for a function like output_toggle(pin), which works with a variable of more than 8bits, rather than a pin.
Mike |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Wed Oct 12, 2005 6:40 am |
|
|
The PIC is an 8 bit machine and thus only 0-7 is allowed. What you must do is use bit 7 of the upper byte. For CCS this is &myvar + 1 when using assembly. Another option would be to use a struct to define the bits and then just do a myvar.bit15 = !myvar.bit15; |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Wed Oct 12, 2005 8:06 am |
|
|
This is not a function but it is easy to read.
Code: | int16 General_Flags1;
#bit T_1Sec_Toggle_Flag = T_Timer_Flags.15
T_1Sec_Toggle_Flag=!T_1Sec_Toggle_Flag; |
|
|
|
MikeW
Joined: 15 Sep 2003 Posts: 184 Location: Warrington UK
|
|
Posted: Wed Oct 12, 2005 8:17 am |
|
|
looks good to me, many thanks
MikeW |
|
|
|