04.03.2013 Views

Basic Micro Studio Syntax Manual

Basic Micro Studio Syntax Manual

Basic Micro Studio Syntax Manual

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Commands<br />

The above statement is looking for the variable temp to equal 10. If the comparison is true then we<br />

will jump to label. If the comparison is not true, then lets keep looping. Since there is nothing to make<br />

the variable equal to 10 the code snippet would loop forever.<br />

Notes<br />

1. Multiple ELSEIF blocks may be used in a single IF...THEN block.<br />

2. ELSE will only execute following code if no conditions were true.<br />

3. ENDIF is required to close a block of conditionals.<br />

Example<br />

This fi rst example demonstrates using the IF...THEN argument with a goto label. If something is true<br />

jump to the label after the THEN statement. Otherwise, if the condition is false execute the commands<br />

on the next line after the THEN statement. You can follow the program fl ow with a terminal window<br />

connected at 9600 baud.<br />

value var long<br />

value = 0<br />

main<br />

value = value+1<br />

if value = 10 then reset<br />

;display the value on the PC terminal window<br />

serout s_out,i9600,["Value=",dec value,13]<br />

pause 1000<br />

goto main<br />

reset<br />

value = 0<br />

goto main<br />

GOSUB Example<br />

A GOSUB statement can be used after a THEN command. When the condition is true a GOSUB will<br />

send the program to the GOSUB label. Eventually a RETURN statement is expected. This will return<br />

the program to the next line of code after the GOSUB statement was used. It is an easy way to create<br />

conditional branching in a main program loop. The program will increment value by 1 each loop.<br />

Once value is equal to 10 the condition becomes true and the GOSUB label is executed. This resets<br />

value to 0 starting the process over. The program was written to be followed using a terminal window<br />

connected to it at 9600 baud. Follow the results until you understand the decision making process.<br />

Can you guess what the terminal window will show?<br />

value var long<br />

value = 0<br />

main<br />

value = value+1<br />

if value = 10 then gosub reset<br />

;display the value on the PC terminal window<br />

serout s_out,i9600,["Value=",dec value,13]<br />

pause 1000<br />

goto main<br />

reset<br />

value = 0<br />

return<br />

126

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!