newbe: IF..THEN statement


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2009
    Posts
    5

    Default newbe: IF..THEN statement

    When using the IF..Then statement how many comparison terms can you have? Is the following a legal instruction:

    IF (PORTA.0 = 1 AND PORTA.1 = 1) OR (PORTA.2 = 1) THEN PORTB.0 = 1

    Any help would be appreciated

    thank you,
    Shawn

  2. #2
    Join Date
    Jan 2009
    Location
    Miami, Florida USA
    Posts
    699


    Did you find this post helpful? Yes | No

    Default

    No, your line is not legal. Replace it by

    IF (PORTA.0=1) AND (PORTA.1=1) THEN PORTB.0=1

    IF PORTA.2=1 THEN PORTB.0=1

    Robert
    Last edited by rsocor01; - 11th November 2009 at 00:35.

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Or...

    If ((porta.0 = 1) and (porta.1 = 1)) or (porta.2 = 1) then portb.0 = 1
    ___________________
    WHY things get boring when they work just fine?

  4. #4
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    Since the three inputs are all on the same port, then you can tray:

    A0 var BYTE

    A0 = PortA.0 + PortA.1 + PortA.2

    If A0 > 2 then PortB.0 = 1

    or.....

    IF PortA & %00000111 > 2 then portB.0 = 1

    Al.
    Last edited by aratti; - 11th November 2009 at 01:07.
    All progress began with an idea

  5. #5
    Join Date
    Nov 2009
    Posts
    5


    Did you find this post helpful? Yes | No

    Smile

    Thank you very much, this is very helpful.

Similar Threads

  1. 16F883 and Problems with HIGH statement
    By aaanekre in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 29th October 2009, 01:09
  2. END Statement
    By jderson in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 9th November 2008, 14:48
  3. ADC_IN statement
    By Russ Kincaid in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 15th April 2007, 10:15
  4. using AND as an IF statement
    By dw_pic in forum mel PIC BASIC
    Replies: 27
    Last Post: - 8th June 2006, 18:05
  5. getting around the basic IF - THEN statement
    By dw_pic in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 7th February 2006, 14:10

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