I am hoping someone can cast their eyes over the following. The idea is a garage door opener, but none of the tests appear to return true. I am simulating in MiSim.
The code was paired down to the following in an attempt to troubleshoot nested IF statements. Does GCBASIC support a ELSEIF?
dir PORTB.0 IN
dir PORTB.1 IN
dir PORTB.2 IN
dir PORTB.6 OUT
dir PORTB.7 OUT
dir PORTA OUT
dim GateOpening
dim GateClosing
SET GateOpening OFF
SET GateClosing OFF
SET OpenMotor OFF
SET CloseMotor OFF
SET GateClosing ON
SET GateOpening OFF
MAIN:
if GateOpenSwitch = ON then SET OpenMotor OFF 'Gate has fully opened.
if GateClosedSwitch = ON then SET CloseMotor OFF 'Gate has fully closed.
if Switch ON then goto SUB1 'Button Pressed
goto MAIN
SUB1:
SET PORTB.5 ON
wait until Switch OFF 'Debounce the switch
SET PORTB.5 OFF
if OpenMotor = ON then goto SUB2 'Motor Running, goto stop and exit
if CloseMotor = ON then goto SUB2 'Motor Running, goto stop and exit
if GateOpening = ON then goto SUB3 'Gate Stopped when Opening. Close the Gate
if GateClosing = ON then goto SUB4 'Gate Stopped when Closing. Open the Gate
SUB2:
SET OpenMotor OFF 'Gate Opening. Stop the Gate
SET CloseMotor OFF 'Gate Closing. Stop the Gate
goto MAIN
SUB3:
SET GateClosing ON
SET GateOpening OFF
SET CloseMotor ON
goto MAIN
SUB4:
SET GateOpening ON
SET GateClosing OFF
SET OpenMotor ON
goto MAIN
Regards,
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
No elsif that I know of. The proper syntax for bits should be:
if OpenMotor On then goto SUB2
This is for a bit.
Use = for a byte.
The gateopening and gateclosing are not defined, therefore they are bytes. Can't set a bit to be a byte.
There is no need to use the subs and goto's. This is not good design. You can have multiple statements in an if:
if OpenMotor On Then
Set OpenMotor Off
Set CloseMotor Off
...
Nested If statements are fine.
Good luck
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi All,
I am hoping someone can cast their eyes over the following. The idea is a garage door opener, but none of the tests appear to return true. I am simulating in MiSim.
The code was paired down to the following in an attempt to troubleshoot nested IF statements. Does GCBASIC support a ELSEIF?
#chip 16f84A,4
#define Switch PORTB.0
#define GateOpenSwitch PORTB.1
#define GateClosedSwitch PORTB.2
#define OpenMotor PORTB.6
#define CloseMotor PORTB.7
dir PORTB.0 IN
dir PORTB.1 IN
dir PORTB.2 IN
dir PORTB.6 OUT
dir PORTB.7 OUT
dir PORTA OUT
dim GateOpening
dim GateClosing
SET GateOpening OFF
SET GateClosing OFF
SET OpenMotor OFF
SET CloseMotor OFF
SET GateClosing ON
SET GateOpening OFF
MAIN:
if GateOpenSwitch = ON then SET OpenMotor OFF 'Gate has fully opened.
if GateClosedSwitch = ON then SET CloseMotor OFF 'Gate has fully closed.
if Switch ON then goto SUB1 'Button Pressed
goto MAIN
SUB1:
SET PORTB.5 ON
wait until Switch OFF 'Debounce the switch
SET PORTB.5 OFF
if OpenMotor = ON then goto SUB2 'Motor Running, goto stop and exit
if CloseMotor = ON then goto SUB2 'Motor Running, goto stop and exit
if GateOpening = ON then goto SUB3 'Gate Stopped when Opening. Close the Gate
if GateClosing = ON then goto SUB4 'Gate Stopped when Closing. Open the Gate
SUB2:
SET OpenMotor OFF 'Gate Opening. Stop the Gate
SET CloseMotor OFF 'Gate Closing. Stop the Gate
goto MAIN
SUB3:
SET GateClosing ON
SET GateOpening OFF
SET CloseMotor ON
goto MAIN
SUB4:
SET GateOpening ON
SET GateClosing OFF
SET OpenMotor ON
goto MAIN
Regards,
No elsif that I know of. The proper syntax for bits should be:
if OpenMotor On then goto SUB2
This is for a bit.
Use = for a byte.
The gateopening and gateclosing are not defined, therefore they are bytes. Can't set a bit to be a byte.
There is no need to use the subs and goto's. This is not good design. You can have multiple statements in an if:
if OpenMotor On Then
Set OpenMotor Off
Set CloseMotor Off
...
Nested If statements are fine.
Good luck