User Manual

MCP Series
Brushed DC Motor Controllers
MCP Series User Manual
165
Notes
Multiple ELSEIF blocks may be used in a single IF...THEN block.
ELSE will only execute following code if no conditions were true.
ENDIF is required to close a block of conditionals.
Example
This rst example demonstrates using the IF...THEN argument with a goto label. If something is
true jump to the label after the THEN statement. Otherwise, if the condition is false execute the
commands on the next line after the THEN statement. You can follow the program ow with a
terminal window connected at 9600 baud.
value var long
value = 0
main
value = value+1
if value = 10 then reset
;display the value on the PC terminal window
puts 0,["Value=",dec value,13]
pause 1000
goto main
reset
value = 0
goto main
GOSUB Example
A GOSUB statement can be used after a THEN command. When the condition is true a GOSUB
will send the program to the GOSUB label. Eventually a RETURN statement is expected. This
will return the program to the next line of code after the GOSUB statement was used. It is an
easy way to create conditional branching in a main program loop. The program will increment
value by 1 each loop. Once value is equal to 10 the condition becomes true and the GOSUB
label is executed. This resets value to 0 starting the process over. The program was written to
be followed using a terminal window connected to it at 9600 baud. Follow the results until you
understand the decision making process. Can you guess what the terminal window will show?
value var long
value = 0
main
value = value+1
if value = 10 then gosub reset
;display the value on the PC terminal window
puts 0,["Value=",dec value,13]
pause 1000
goto main
reset
value = 0
return