Page 1 of 1
Variable Bit Testing
Posted: Fri Jan 03, 2014 11:02 am
by JANUARY1
Hi could you tell me how to do bit testing on a variable not a port MANY THANKS
ON FLOWCODE 5 PROF
and can the interupt be made faster than 15hz on 18f2550 and 16f737
Re: VARIABLE BIT TESTING
Posted: Fri Jan 03, 2014 11:09 am
by Benj
Hello,
You can do something like this.
Say the variable is a byte called bytevar you can check the state of bit 0 by doing this inside a decision icon.
if you want to check bit 1 then it becomes
bit2 = 0x04
bit3 = 0x08
bit4 = 0x10
bit5 = 0x20
bit6 = 0x40
bit7 = 0x80
or you can do it pragmatically using a second variable bitvar to store the bit location 0 to 7.
If you need to store the value of the bit rather then simply acting on it then you can do this in a calculation icon. Note that this will simply copy the bit value across.
Code: Select all
bitstate = bytevar & (0x01 << bitvar)
If instead you need the bit value to be equal to 0 or 1 then you can instead do this.
Code: Select all
bitstate = (bytevar >> bitvar) & 0x01