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
Variable Bit Testing
Moderator: Benj
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: VARIABLE BIT TESTING
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.
If instead you need the bit value to be equal to 0 or 1 then you can instead do this.
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.
Code: Select all
bytevar & 0x01
Code: Select all
bytevar & 0x02
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.
Code: Select all
bytevar & (0x01 << bitvar)
Code: Select all
bitstate = bytevar & (0x01 << bitvar)
Code: Select all
bitstate = (bytevar >> bitvar) & 0x01
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel