Condition testing


Closed Thread
Results 1 to 5 of 5
  1. #1
    jtburnham's Avatar
    jtburnham Guest

    Default Condition testing

    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

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    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

  3. #3
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    Inside the parenthesis the test is logical but outside is a comparison of two numbers. It is allways 'false' condition...

    Ioannis

  4. #4
    jtburnham's Avatar
    jtburnham Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Melanie

    Your logic is flawed ...
    My wife frequently makes the same observation.

    I do see where I was going wrong.

    Thank you all.

    Jim

  5. #5
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    See? As always women are addressing (here Melanie...) this kind of problems!

    Ioannis

Similar Threads

  1. HARDWARE I2C SAMPLE CODE question
    By Michael Wakileh in forum Code Examples
    Replies: 2
    Last Post: - 16th June 2009, 21:07
  2. Auto testing bulbs
    By The Master in forum Off Topic
    Replies: 12
    Last Post: - 2nd September 2008, 10:53
  3. PIC16F877 I2C programme
    By cooqo in forum mel PIC BASIC
    Replies: 3
    Last Post: - 21st April 2008, 10:02
  4. Testing LCD's
    By david miles in forum General
    Replies: 7
    Last Post: - 29th January 2008, 21:35
  5. Testing PortB pin
    By jrt4fun in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd August 2005, 07:08

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts