Interactive PIC Commands

END The END command denotes the end of your program. The END command must be on the last line of your program
Example: END
END IF The END IF command line tells the PIC that the IF command line has finished.
Example: END IF
END PROC This is used at the end of a procedure.
Example: END PROC
END REPEAT Tells the PIC that this is the end of a REPEAT loop.
Example: END REPEAT
END WHILE This is used in a while loop. When the PIC encounters END WHILE either it returns to the WHILE loop to test the condition again or carries out the commands below END WHILE.
Example: END WHILE
GO (procedure name) To call a procedure use the GO command followed by the name of the
procedure you wish to call. When the procedure has been carried out
the PIC resumes the program at the line below the GO (name) command line.
Example: GO lights on
IF COUNT (number) > (number) THEN When you switch on any of the input lines, an incrementing
count is made. This command line enables the count variable to be
incorporated into programs. If the input line count specified is higher than the comparison number the commands below are carried
out, otherwise all the command lines are ignored until END IF.
Example:
IF COUNT 3 > 12 THEN
SWITCH ON 1
END IF
IF COUNT (number) < (number) THEN If the input line count specified is lower than the comparison number
the commands below are carried out; otherwise all the command lines are ignored until END IF.
Example:
IF COUNT 2 < 8 THEN
SWITCH OFF 1
END IF
IF COUNT (number) = (number) THEN If the input line count specified equals the comparison number the
commands below are carried out; otherwise all the command lines are ignored until END IF.
Example:
IF COUNT 3 = 7 THEN
SWITCH ON ALL
END IF
IF INPUT (number) AND (number) IS OFF THEN If the two specified input lines are off, carries out the commands
until END IF.
Example: IF INPUT 0 AND 4 IS OFF THEN
IF INPUT (number) AND (number) IS ON THEN If the two specified input lines are on, carries out the commands
until END IF.
Example: IF INPUT 2 AND 4 IS ON THEN
IF INPUT (number) IS OFF THEN Similar to IF INPUT (number) IS ON THEN except this line determines if the input is off.
Example: IF INPUT 3 IS OFF THEN
IF INPUT (number) IS ON THEN This command line is similar to the WAIT UNTIL INPUT (number) IS ON command line. If the condition is not met, the PIC skips over the command lines, until it reaches the END IF command. Alternatively if the condition is met the PIC carries out the command lines until END IF.
Example:
IF INPUT 4 IS ON THEN
SWITCH ON 6
END IF
END
If input four is on. Carry out the commands until END IF.
MOTOR (letter) GO FORWARD Rotates the connected motor shaft forwards.
Example: MOTOR A GO FORWARD
MOTOR (letter) GO BACKWARD Rotates the connected motor shaft backwards.
Example: MOTOR C GO BACKWARD
PROC (name) A procedure is a list of commands which is called by the main program.
The purpose is to group together a series of commands which you would have to keep typing in over and over again. Each procedure must have a name which does not conflict with a command word. The name of the procedure is entered after the PROC command word.
Examples:
PROC one
PROC lights
PROC leave
This procedure switches on and off output lines
PROC lights
SWITCH ON 0 TO 7
WAIT 5
SWITCH OFF 0 TO 7
WAIT 5
END PROC

The END PROC command tells the PIC that this is the end of the procedure.
The procedure(s) must be below the main program but before the END PROC command or they will not work properly. Note: You may
call a second procedure from one procedure, but I-PIC does not support calling a further procedure from the second procedure.

REM (text) The REM command is useful for putting in remarks about the program. Type in the REM command followed by any sentence or remarks about the program you are writing.
Example: REM this is the start of the procedure.
REPEAT (number) Repeats the commands on the lines below until it reaches the END REPEAT command, when it begins to execute the commands again. It repeats the command line sequence by the number after REPEAT. REPEAT 4 command line will repeat the commands below 4 times.
Example:
REPEAT 4
WAIT 1
SWITCH ON 1
WAIT 1
SWITCH OFF 1
END REPEAT
END
This example switches on and off output line 1, 4 times. When you
use the REPEAT command you must tell the PIC by using the END REPEAT command that you have finished the repeat sequence.
REPEAT FOREVER Repeats the commands on the lines below until it reaches END REPEAT when it begins to execute the commands again. It repeats the commands forever!
Example: REPEAT FOREVER
SUB END REPEAT Tells the PIC that this is the end of a SUB REPEAT loop.
Example: SUB END REPEAT
SUB REPEAT (number) To repeat a further series of commands within a REPEAT loop,
use SUB REPEAT (number) and the SUB END REPEAT command lines.
Example:
REPEAT 4
WAIT 1
SWITCH ON 1
WAIT 1
SWITCH OFF 1
SUB REPEAT 3
SWITCH ON 4
WAIT 1
SWITCH OFF 4
WAIT 1
SUB END REPEAT
END REPEAT
END
If you go to a procedure from within a REPEAT (number) loop and require a repeat loop, use the SUB REPEAT (number) and the SUB END REPEAT command lines.

Example:
REPEAT 6
GO lights
END REPEAT
PROC lights
SUB REPEAT 3
SWITCH ON ALL
WAIT 2
SWITCH OFF ALL
WAIT 2
SUB END REPEAT
END PROC
END

SUB REPEAT FOREVER Repeats the commands on the lines below until it reaches SUB END REPEAT when it begins to execute the commands again. This command line is used within a REPEAT loop.

Example: SUB REPEAT FOREVER

SWITCH OFF (number),(optional number) The SWITCH OFF command turns off an output line on the control board. To switch an output line off we need a number after SWITCH OFF. Like the SWITCH ON command this number can be between 0 to 7.
Example: SWITCH OFF 6 This command switches off output line 6.
Example: SWITCH OFF 3 This command switches off output line 3. To switch off multiple output lines place a comma after each number (except the last number).
Example: SWITCH OFF 2,5
Example: SWITCH OFF 4,6,7
SWITCH ON (number),(optional number) The SWITCH ON command turns on an output line on the control board. To switch an output line on we need a number after the SWITCH ON command.
This number can be between 0 to 7.
Example: SWITCH ON 5 This command switches on output line 5.
Example: SWITCH ON 3 This command switches on output line 3. To switch on multiple output lines place a comma after each number (except the last number).
Example: SWITCH ON 1,3
Example: SWITCH ON 1,5,7
As there are only eight output lines on the control board, typing in
a number above 7, after the SWITCH ON command, will produce an error message.
SWITCH OFF (number) AND (number) This command switches off two output lines at once. SWITCH OFF 1 AND 4 will switch off lines 1 and 4.
Example: SWITCH OFF 3 AND 7 switches off output lines 3 and 7.
Example: SWITCH OFF 4 AND 6 switches off output lines 4 and 6.
SWITCH ON (number) AND (number) With this command we can switch on two lines at once. SWITCH ON 1 AND 4 will switch on lines 1 and 4. Each of these numbers can be between 0 and 7.
Example: SWITCH ON 3 AND 7 switches on output lines 3 and 7.
Example: SWITCH ON 2 AND 4 switches on output lines 2 and 4.
SWITCH OFF (first number) TO (second number) This command line switches off all the output lines between and including the two numbers.
Example: SWITCH OFF 4 TO 7 switches off output lines 4 to 7.
Example: SWITCH OFF 4 TO 6 switches off output lines 4 to 6. Note that for this command line to work the first of the two numbers must be lower than the end number.
Example: SWITCH OFF 6 TO 2 will not work.
Example: SWITCH OFF 2 TO 6 will work.
SWITCH ON (first number) TO (second number) This command line switches on all the output lines between and including the two numbers.
Example: SWITCH ON 3 TO 7 switches on output lines 3 to 7.
Example: SWITCH ON 1 TO 5 switches on output lines 1 to 5. Note that for this command line to work the first of the two numbers must be lower than the end number.
Example: SWITCH ON 7 TO 1 will not work
Example: SWITCH ON 0 TO 6 will work.
SWITCH OFF ALL Switches off all output lines.
SWITCH ON ALL Switches on all output lines.
WAIT (number) The WAIT command will not execute any further commands until the time; given in seconds, has elapsed. The number after WAIT is how long you want the program to wait for. WAIT 10 will hold for 10 seconds. WAIT 3 will hold for 3 seconds.
Example: WAIT 7 holds for 7 seconds.
The maximum number WAIT will hold for is 60.
WAIT UNTIL INPUT (number) IS OFF Using this command line lets you halt the program, until one of the
five input lines is off.
Example: WAIT UNTIL INPUT 3 IS OFF
When the PIC comes across this line in your program it will wait, until
input 3 is off, before continuing with the program.
WAIT UNTIL INPUT (number) IS ON Using this command line lets you halt the program, until one of the
five input lines is on.
Example: WAIT UNTIL INPUT 2 IS ON
When the PIC comes across this line in your program, it will wait until
input 2 is on, before continuing with the program.
WHILE INPUT (number) IS OFF If the input line is off, the PIC carries out the commands until it reaches the END WHILE command, when it returns to test the specified input again.
Example: WHILE INPUT 4 IS OFF
WHILE INPUT (number) IS ON If the input line is on, the PIC carries out the commands until it reaches the END WHILE command, when it returns to test the specified input again.
Example:
WHILE INPUT 1 IS ON
SWITCH ON 6
WAIT 2
SWITCH OFF 6
WAIT 2
END WHILE
END
In the example, WHILE INPUT 1 IS ON the commands below will be repeated forever or until input 1 is off. If a REPEAT FOREVER loop is within a WHILE loop and the PIC is carrying out the commands in the REPEAT FOREVER loop, the PIC will not exit the REPEAT FOREVER loop.
Note: You cannot use a further WHILE loop within an existing WHILE loop.



Page last updated 23/05/2003 © Copyright, I.D.Lee, Didcot Girls' School.
All rights reserved. The original material provided on this site may not be copied or redistributed without written consent from the school.