Conditional branching. Syntax:
if [expression] then [statement]
or
if [expression] then { [statement block] }
Similarly for else:
else [statement]
or
else { [statement block] }
Executes the statement block repeatedly until expression evaluates to true. The evaluation of the expression is performed after the statement block, so the statement block will always be executed at least once. Syntax:
repeat { [statement block] } until [expression]
Similar to repeat, this repeatedly executes the statement block. However, the expression is evaluated before execution, not after. So if the expression evaluates to false on the first pass, then the statement block will not get executed. Syntax:
while [expression] { [statement block] }
This causes execution of the code to continue at the next statement after the label specified. Goto syntax:
goto
[labelname]
Label syntax:
labelname:
It is often considered good programming practice to avoid the use of goto. Use of control statements and subroutines will result in a much more readable program.
Calls a subroutine. Syntax:
call
[SubName]
where SubName
is the name of the subroutine to be called.
This causes the code execution to stop for the given period of time. The interval is in milliseconds. Syntax:
delay
[interval]
Note
At present, Microbe assumes that the PIC is operating at a frequency of 4MHz - i.e. each instruction takes 1 microsecond to execute. If this is not the case, the interval must be adjusted proportionately.
This is used to define the pin mapping for a (common cathode) seven segment display connected to the PIC. Syntax:
sevenseg
[name] [a] [b] [c] [d] [e] [f] [g]
where [a]...[g] are the PIC pins to which the respective segments of the seven segment display are attached. The pins can be written either as PORTX.N or RXN.
To display a number on the seven segment, the pin mapping is treated as a write only variable.
Example 5.4. Defining and outputting to a seven segment
sevenseg seg1 RB0 RB1 RB2 RB3 RB4 RB5 RB6 seg1 = x + 2
This is used to define the pin mapping for a keypad connected to the PIC. Syntax:
keypad
[name] [row 1] ... [row 4] [column 1] ... [column n]
where [row 1] ... [row 4] and [column 1] ... [column n] are the PIC pins to which the respective rows and columns of the keypad are attached (at the moment, the number of rows is not changeable). See the section called “sevenseg” (above) for more information on pin mappings.
The columns of the keypad should be pulled down via 100k resistors to ground. The row pins must be configured as outputs and the column pins as inputs. Once the keypad has been defined, it is treated as a read only variable.
Example 5.5. Defining and reading from a keypad
keypad keypad1 RB0 RB1 RB2 RB3 RB4 RB5 RB6 x = keypad1
By default, the values returned for a keypad are:
The value of the number if it is a numeric key (1 to 3 along top row; hexadecimal A to D down the fourth column and continuing for each extra column).
253 for the key in row 4, column 1.
254 for the key in row 4, column 3.
These values can be redefined by using the alias command, where the name of the key in row x, column y (rows and columns starting at 1), is Keypad_x_y. For example, to give the star key on a 4x3 keypad the value zero, the following alias would be used: