IF... THEN... ELSE syntax help needed.
searthur
Posts: 8
Im looking for some help on the IF
THEN
ELSE syntax. Im trying to look at the status of three input pins and then change some output pins if a certain condition exists. Below is my source file. Can anyone tell me what Im doing wrong?
Main:
IF IN5=0 THEN GPOHI
ELSEIF
IN6=0 THEN GPOHI
ELSEIF
IN7=1 THEN GPOHI
ELSE GPOLO
ENDIF
GOTO Main
END
GPOHI:
HIGH 15 'Energize relay 1
HIGH 14 'Energize relay 2
HIGH 13 'Energize relay 3
GOTO Main
GPOLO:
LOW 15 'Relax relay 1
LOW 14 'Relax relay 2
LOW 13 'Relax relay 3
GOTO Main
Main:
IF IN5=0 THEN GPOHI
ELSEIF
IN6=0 THEN GPOHI
ELSEIF
IN7=1 THEN GPOHI
ELSE GPOLO
ENDIF
GOTO Main
END
GPOHI:
HIGH 15 'Energize relay 1
HIGH 14 'Energize relay 2
HIGH 13 'Energize relay 3
GOTO Main
GPOLO:
LOW 15 'Relax relay 1
LOW 14 'Relax relay 2
LOW 13 'Relax relay 3
GOTO Main
Comments
IF IN7=1
You left out two IF statements.
IF IN5=0 THEN GPOHI
IF IN6=0 THEN GPOHI
IF IN7=1 THEN GPOHI
GOTO GPOLO
or:
Main:
IF IN5=0 OR IN6=0 OR IN7=1 THEN GPOHI
GOTO GPOLO
Main:
IF IN5=0 THEN GPOHI
IF IN6=0 THEN GPOHI
IF IN7=1 THEN GPOHI
GOSUB GPOLO
GOTO Main
END
'******************************************************************[ Subroutines ]
'
GPOHI:
HIGH 15 'Energize relay 1
HIGH 14 'Energize relay 2
HIGH 13 'Energize relay 3
GOTO Main
GPOLO:
LOW 15 'Relax relay 1
LOW 14 'Relax relay 2
LOW 13 'Relax relay 3
RETURN
GOTO Main
' {$PBASIC 2.5}
statement if you want to use 2.5
Main:
IF IN5=0 OR IN6=0 OR IN7=1 THEN GPOHI
GOTO GPOLO
GPOHI:
HIGH 15 'Energize relay 1
HIGH 14 'Energize relay 2
HIGH 13 'Energize relay 3
GOTO Main
GPOLO:
LOW 15 'Relax relay 1
LOW 14 'Relax relay 2
LOW 13 'Relax relay 3
GOTO Main