PDA

View Full Version : Condition testing



jtburnham
- 29th August 2006, 15:58
I'm using PBPro and I hoping someone can answer a fairly simple question for me. I want to test for 1 or more set bits on port a.

For single bit testing, this doesn't work -

IF (porta AND %00000001) THEN ...

This also doesn't work -

IF (porta AND %00000001) = 1 THEN ...

For multiple bit testing, this doesn't work -

IF (porta AND %00000101) THEN ...

This also doesn't work -

IF (porta AND %00000101) = 1 THEN ...

Is there another way besides IF (porta.0 = 1 AND porta.3 = 1) THEN... to test for set bits? I thought AND was an accepted test for byte testing.

Thank you for your help.

Jim Burnham

Melanie
- 29th August 2006, 17:41
IF (porta AND %00000101) = 1 THEN

Your logic is flawed because for example if bit PortA.2 is set then the equation would equal 4 and not 1.

Try this instead...

If (PortA and %00000101)<>0 then

Ioannis
- 29th August 2006, 20:34
Inside the parenthesis the test is logical but outside is a comparison of two numbers. It is allways 'false' condition...

Ioannis

jtburnham
- 30th August 2006, 00:16
Your logic is flawed ...



My wife frequently makes the same observation.

I do see where I was going wrong.

Thank you all.

Jim

Ioannis
- 30th August 2006, 10:02
See? As always women are addressing (here Melanie...) this kind of problems!

Ioannis