PDA

View Full Version : IF question.



Steve Matson
- 19th November 2007, 16:45
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

mister_e
- 19th November 2007, 23:49
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..



MyPushButton VAR PORTB.0
'
'
'
'
'
'
If MyPushButton = 0 then DoSomething

HTH

BrianT
- 20th November 2007, 00:41
'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

ruijc
- 20th November 2007, 10:31
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

Bruce
- 20th November 2007, 14:51
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.

jetpr
- 23rd November 2007, 03:15
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