Page 1 of 1

Is there any way to....

Posted: Mon Nov 07, 2011 12:52 pm
by Sparkoids
I have some Flowcode that works perfectly getting a variable when the 4 input buttons are set to Active High but the PCB is designed for Active Low :-(

Which means instead of reading 0x0 when no button is pressed it actually reads 0xF - I have logic probed the PCB and all the ports are high as they would be.

Does anyone know if there is a simple way to "reverse" the reading so it acts as if it's Active High as per the Flowchart?

I do not want to set up a IF it = x THEN let it = y because of the number of combinations and the hex is confusing me regarding the calculations required later!

Any ideas please - I'm not sure what I'm actually asking for!!!!

Re: Is there any way to....

Posted: Mon Nov 07, 2011 3:06 pm
by JonnyW
Hello. You want to use exclusive OR:

Code: Select all

Read input
input = input ^ 0xF
This should invert all the bits on your input.

Cheers,

Jonny

Re: Is there any way to....

Posted: Mon Nov 07, 2011 3:31 pm
by Sparkoids
Many thanks! :-)

Re: Is there any way to....

Posted: Mon Nov 07, 2011 5:01 pm
by Benj
The not symbol '~' could also be useful.

input = (~input) & 0x0F

Re: Is there any way to....

Posted: Tue Nov 08, 2011 11:43 am
by Sparkoids
Works with both it appears......

Re: Is there any way to....

Posted: Tue Nov 08, 2011 11:44 am
by Sparkoids
And thank you both for that....

Re: Is there any way to....

Posted: Tue Nov 08, 2011 12:21 pm
by Sparkoids
Last remark on the matter.

Apparently it is better to use NOT since it only uses 1 byte and XOR uses 2 bytes I'm told.

Personally I'm just glad it works!

Re: Is there any way to....

Posted: Tue Nov 08, 2011 9:24 pm
by JonnyW
Hi. Yes - if you just want to invert all bits then 'not' is better than 'xor' - you would tend to use xor to invert a selection of bits, like 0xF, and leave the other bits as they were.

Jonny