IF question.


Closed Thread
Results 1 to 6 of 6

Thread: IF question.

  1. #1
    Join Date
    May 2007
    Posts
    10

    Default IF question.

    I have just recently purchased Pic Basic Pro and I am having trouble with a very simple problem. I am programming a 16F84A and I need to monitor one or two inputs to turn on one out put. It's as simple as that. Oddly enough I have had success with other functions such as lcdout but this simple one is stumping me.
    Here is my attempt at code:

    If Pin0 = 1 Then outpintwo 'call the pin two function

    If Pin0 = 1 AND Pin1 = 1 Then outpintwo

    Any advice would be appreciated.
    Thanks
    Steve Matson

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    i don't know how you have declared Pin0, but in PBP you should use variable.. not sure if BasicStamp/PicBasic work with PBP. anyways..

    Code:
            MyPushButton VAR PORTB.0
            '
            '
            '
            '
            '
            '
            If MyPushButton = 0 then DoSomething
    HTH
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3


    Did you find this post helpful? Yes | No

    Default Try this

    'Declare hardware
    PinZero var portb.0 'push button to ground on this pin
    PinOne var portb.1 'another pushbutton to ground on this pin
    Sig1Out var portb.2 ' LED and resistor to show result
    Sig2Out var portb.3 ' LED and resistor to show result

    TRISA = %00000011 ' two inputs 6 outputs
    OPTION_REG = %00000000 'turn on weak pullups - PinZero and PinOne will now float high

    Loop:
    IF PinZero = 0 then Out1 'pinzero has been pulled low by pushbutton pressed
    IF (PinZero = 0) AND (PinOne = 0) then Out2
    low sig1out
    low sig2out
    goto loop

    Out1:
    high sig1out
    pause 20
    goto loop

    Out2:
    high sig2out
    pause 20
    goto loop

    HTH
    Brian

  4. #4


    Did you find this post helpful? Yes | No

    Default

    Hi Steve Matson,

    i had the same issue last night.

    The trick is very simple !

    You used:
    If Pin0 = 1 AND Pin1 = 1 Then outpintwo

    But you need to do:

    If (Pin0 = 1) AND (Pin1 = 1) Then outpintwo

    The () make all the difference

    Regards

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Look hard at your logic.

    IF PinZero = 0 then Out1 When this is true, you never make it to the 2nd comparison
    since Out1 returns you right back to Loop.

    If this evaluates as false, then the 2nd comparison will be checked, but then it will always
    be false, because PinZero has to be 1 to fall-through to the next comparison.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    Jan 2005
    Location
    Puerto Rico
    Posts
    133


    Did you find this post helpful? Yes | No

    Thumbs up

    code Example:

    if (ThrottleUp=1) then
    if (ThrottleDn=1) then
    if (TrimOK=2) then
    if (AutoRun=1) then
    GoSub EnablePump 'Set required PWM/Timer2 registers
    GoSub EnableGlow
    PumpMath=0
    RunStatus =0
    Evt1 = 0
    goto AutoStart
    endif
    endif
    endif
    endif
    My Hobbies is PicBasic PRO

Similar Threads

  1. ADCIN question
    By Greg McFadden in forum General
    Replies: 4
    Last Post: - 16th September 2008, 02:53
  2. AN Question for "word" variable read The serial port
    By redfoen in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 14th December 2007, 17:39
  3. Remote PIC input question
    By Adrian in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 1st September 2007, 15:44
  4. Question for a math guru
    By Christopher4187 in forum General
    Replies: 3
    Last Post: - 22nd November 2006, 09:45
  5. Please answer my first question
    By John_001 in forum Off Topic
    Replies: 1
    Last Post: - 15th September 2006, 06:49

Members who have read this thread : 1

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