Você está na página 1de 36

COMMANDS

Section 1

Contents
C OMMANDS

AND

SYNT
AX
YNTAX

Introduction .................................................................................................. 2
Comments ...................................................................................................... 3
Constants ....................................................................................................... 3
Symbols ......................................................................................................... 3
Variables ........................................................................................................ 4
Command Summary (A-O) ................................................................................. 5
Commands Summary (P-Z) ................................................................................ 6
backward .................................................................................................. 7
branch ..................................................................................................... 7
button ..................................................................................................... 8
debug ...................................................................................................... 8
eeprom ..................................................................................................... 9
end ........................................................................................................ 1 0
for...next ................................................................................................ 1 1
forward ................................................................................................... 1 1
gosub .................................................................................................... 1 2
goto ...................................................................................................... 1 2
halt ....................................................................................................... 1 3
high ...................................................................................................... 1 3
highA .................................................................................................... 1 3
if...then .................................................................................................. 1 4
infrain .................................................................................................... 1 5
if sensor...then ........................................................................................ 1 6
input ..................................................................................................... 1 6
inputa ................................................................................................... 1 7
lcd ......................................................................................................... 1 7
let ......................................................................................................... 1 8
lookdown ............................................................................................... 1 9
lookup ................................................................................................... 1 9
LOW pin ................................................................................................ 2 0
lowa ...................................................................................................... 2 0
nap ........................................................................................................ 2 0
output ................................................................................................... 2 1
outputa ................................................................................................. 2 1
pause ..................................................................................................... 2 1
pot ........................................................................................................ 2 2
peek ...................................................................................................... 2 3
poke ...................................................................................................... 2 4
pulsin .................................................................................................... 2 4
pulsout .................................................................................................. 2 5
pwm ...................................................................................................... 2 5
random .................................................................................................. 2 5
readadc .................................................................................................. 2 6
read ....................................................................................................... 2 6
readmem ................................................................................................ 2 7
return .................................................................................................... 2 7
reverse ................................................................................................... 2 8
serin ...................................................................................................... 2 8
serout .................................................................................................... 2 9
servo ...................................................................................................... 3 0
sleep ...................................................................................................... 3 1
symbol ................................................................................................... 3 1
sound .................................................................................................... 3 2
switch on ............................................................................................... 3 2
switch off ............................................................................................... 3 3
toggle ................................................................................................... 3 3
wait ....................................................................................................... 3 4
write ...................................................................................................... 3 4
writemem ............................................................................................... 3 5
Contacts ....................................................................................................... 3 6

revolution

copyright 2001

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
2

Section 1

COMMANDS AND SYNTAX


INTRODUCTION
The following section describes the syntax for the BASIC language that the
Programming Editor supports. As the Programming Editor software supports a number
of different devices, some commands are only supported in certain modes. The five
modes are:

BASIC mode
This is the original PBASIC syntax for the BASIC Stamp devices, including the Stamp
Microcontroller and Stamp Controller.

Extended BASIC mode


This supports the same devices such as BASIC mode, but has additional simplified
pseudo commands (e.g. if input0 is on then rather than if pin0 = 1 then)

PIC16F84A mode
This supports the programming of a PIC16F84A to take the place of a Stamp module.
This also has additional commands to support the pins on PORTA. See the PIC16F84A
datasheet for more information.

PICAXE mode
These are the commands supported by the PICAXE range of controllers.

Assembler mode
These are the commands that can be converted into assembler code via the automatic
sequential BASIC to Assembler feature. See the assembler datasheet for more
information.
The remainder of this section is split into these topics:

Comments
Constants
Symbols
Variables
Commands

revolution

copyright 2001

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
3

Section 1

COMMENTS
Comments begin with an apostrophe () or semi-colon (;) and continue until the end
of the line. The keyword REM may also be used for remarks.
Example:
high 0 make pin 0 high
high 0 ;make pin 0 high
REM make pin 0 high

CONST
ANT
CONSTANT
ANTSS
Constants can be declared in four ways: decimal, hex, binary, and ASCII.
Decimal numbers are typed directly without any prefix.
Hexadecimal (hex) numbers are preceded with a dollar-sign ($).
Binary numbers are preceded by a percent-sign (%).
ASCII values are enclosed in quotes ().
Examples:
100
$64
%01100100
A
Hello
B1 = B0 ^ $AA

100 decimal
64 hex
01100100 binary
A ascii (65)
Hello - equivalent to H,e,l,l,o
xor variable B0 with AA hex

SYMBOLS
Symbols can be assigned constant values, alias names for variables, and program
addresses. Constant values and alias variable names are assigned by following the
symbol name with an equal-sign (=), followed by the variable or constant.
Symbols can use any word that is not a command. Symbols can contain numeric
characters (flash1, flash2 etc.) but the first character cannot be a numeric (e.g. 1flash)
Program addresses are assigned by following the symbol with a colon (:).
Example:
symbol RED_LED = 7
symbol COUNTER = B0
let COUNTER = 200
LOOP:
high RED_LED
pause COUNTER
low RED_LED
pause COUNTER
goto LOOP

revolution

copyright 2001

define a constant symbol


define a variable symbol
preload variable with value 200
define a program address
address symbol end with colons
switch on output 7
wait 0.2 seconds
switch off output 7
wait 0.2 seconds
loop back to start

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
4

Section 1

VARIABLES
Modes:
The following sections show the variables which apply to the following modes:

BASIC and Extended are used when programming Stamp modules.


PIC16F84A is used when downloading directly into a PIC16F84A
PICAXE is used when programming PICAXE modules
Assembler is used when converting into assembler code.

BASIC
The BASIC mode has 16 bytes of RAM organized as 56 variables: 8 words, 16 bytes,
and 32 bits. The 32 bit variables cover the bottom 2 words or 4 bytes.
Words: PORT
W0, W1, W2, W3, W4, W5, W6
Bytes:

PINS, DIRS
B0, B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12, B13

Bits:

PIN0, PIN1, PIN2, PIN3, PIN4, PIN5, PIN6, PIN7 (together equal PINS)
DIR0, DIR1, DIR2, DIR3, DIR4, DIR5, DIR6, DIR7 (together equal DIRS)
BIT0, BIT1, BIT2, BIT3, BIT4, BIT5, BIT6, BIT7 (together equal B0)
BIT8, BIT9, BIT10, BIT11, BIT12, BIT13, BIT14, BIT15 (together B1)

Note that (within BASIC and Extended modes only) B12 and B13 (W6) is used within
GOSUB commands as a stack. It should therefore not be used as a general purpose
register.
Extended
The extended mode supports all the BASIC variables. In addition:
INPUT0, INPUT1 etc. can be used instead of pin0, pin1 etc.
OUTPUT0, OUTPUT1 etc. can be used instead of 0, 1, 2 etc.
PIC16F84A
The PIC16F84A mode supports the extended mode variables, with the following
modification.
PINSA is used instead of B12
DIRSA is used instead of B13
PICAXE
The PICAXE mode supports the extended mode variables, with the following
modification.
INFRA is used instead of DIRS
In addition the PEEK and POKE commands can be used to address other registers.
Assembler
The assembler mode supports the extended mode variables.
In addition the PEEK and POKE commands can be used to address other registers.

revolution

copyright 2001

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
5

Section 1

COMMAND SUMMARY (A-O)


Modes:
The following table shows the commands which apply to the following modes:

BASIC and Extended are used when programming Stamp modules.


PIC16F84A is used when downloading directly into a PIC16F84A
PICAXE is used when programming PICAXE modules
Assembler is used when converting into assembler code.
Command
BASIC
Backward
Branch
X
Button
X
Debug
X
Eeprom
X
End
X
Fornext
X
Forward
Gosub
X
Goto
X
Halt
High
X
HighA
Ifthen
X
If infra.. then
If sensor.. then
Infra
Input
X
InputA
Lcd
Lookdown
X
Lookup
X
Low
X
LowA
Nap
X
Output
X
OutputA

revolution

Extended
X
X
X

PIC16F84A
X
X

X
X
X
X
X
X
X
X

X
X
X
X
X
X
X
X
X
X

PICAXE18
X
X
X
X
X
X
X
X
X
X
X
X

PICAXE28
X
X
X
X
X
X
X
X
X
X
X
X

Assembler
X
X
X

X
X

X
X
X
X
X
X
X
X

X
X
X
X
X
X
X
X
X

copyright 2001

X
X
X
X
X
X
X
X
X
X

Revolution Education Ltd.

X
X
X
X

X
X
X
X

X
X
X
X

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
6

Section 1

COMMANDS SUMMARY (P-Z)


Modes:
The following table shows the commands which apply to the following modes:

BASIC and Extended are used when programming Stamp modules.


PIC16F84A is used when downloading directly into a PIC16F84A
PICAXE is used when programming PICAXE modules
Assembler is used when converting into assembler code.
Command
Pause
Peek
Poke
Pot
Pulsin
Pulsout
PWM
Random
Readadc
Read
Readmem
Return
Reverse
Serin
Serout
Servo
Sleep
Sound
Switch on
Switch off
Symbol
Toggle
Wait
Write
Writemem

BASIC
X

Extended
X

X
X
X
X
X
X
X
X
X
X
(use pot) (use pot)
X
X

PIC16F84A
X

PICAXE18
X
X
X

PICAXE28
X
X
X

Assembler
X
X
X

(use readadc)

(use readadc)

(use readadc)

X
X
X
X
X
X

X
X
X
X
X
X
X
X

X
X
X
X
X
X
X
X

X
X
X
X
X
X
X
X
X
X
X
X

X
X

X
X
X
X
X

X
X
X
X

X
X
X
X

X
X
X

X
X

X
X

X
X
X
X
X
X
X
X

X
X
X
X
X
X
X
X

X
X
X
X
X
X
X
X

X
X
X

revolution

copyright 2001

Revolution Education Ltd.

Email: info@rev-ed.co.uk

X
X
X
X
X
X
X
X
X

Web: www.rev-ed.co.uk

COMMANDS
7

Section 1

backward
BACKW
ARD m
otor
CKWARD
motor

Make motor output turn backwards


- Motor is the motor name A or B.
NB: This is a pseudo command that actually parses multiple high/low
commands.
Example:
loop: forward A
wait 5
backward A
wait 5
halt A
wait 5
goto loop

motor a on forwards
wait 5 seconds
motor a on backwards
wait 5 seconds
motor A reverse
wait 5 seconds
loop back to start

branch
BRANCH offset,(address0,address1...addressN)

Branch to address specified by offset (if in range).


- Offset is a variable/constant which specifies which Address# to use (0-N).
- Addresses are labels which specify where to go.
Example:
rest:
loop:

let infra = 0
reset infra variable for PICAXE system
if infra > 0 then test
jump to test if new signal detected
goto loop
else loop back

test:
branch infra,(btn0,btn1, btn2, btn3)
branch to button routines
goto rest
else loop back to start
btn0:
btn1:
btn2:
btn3:

etc.
etc.
etc.
etc.

revolution

copyright 2001

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
8

Section 1

button
BUTT
ON pin,d
own
state
,d
elay
,r
ate
,bytevari
able
,tar
getstate
,ad
dress
BUTTON
pin,down
ownstate
state,d
,delay
elay,r
,rate
ate,bytevari
,bytevariable
able,tar
,targ
etstate,ad
,add

Debounce button, auto-repeat, and branch if button is in target state.


-

Pin is a variable/constant (0-7) which specifies the i/o pin to use.

Downstate is a variable/constant (0 or 1) which specifies what logical state


is read when the button is pressed.

Delay is a variable/constant (0-255) which specifies down-time before


auto-repeat in BUTTON cycles.

Rate is a variable/constant (0-255) which specifies the auto-repeat rate in


BUTTON cycles.

Bytevariable is the workspace. It must be cleared to 0 before being used by


BUTTON for the first time.

Targetstate is a variable/constant (0 or 1) which specifies what state (0=not


pressed, 1=pressed) the button should be in for a branch to occur.

Address is a label which specifies where to go if the button is in the target


state.

Example:
loop:

button 0,0,200,100,b2,0,cont
jump to cont unless pin0 = 0
toggle 1

else toggle input

cont:

debug
DEBUG var

Display information in the debug window upon encounter during execution.


-

Variables can be printed with their current values by simply naming the
variable.

Example:
loop: debug b1
let b1 = b1 + 1
pause 500
goto loop

revolution

copyright 2001

display value
increment value of b1
wait 0.5 seconds
else loop back to start

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
9

Section 1

eeprom
EEPROM {location},(data,data...)

Preload EEPROM data locations.


This is not an instruction, but rather a means to preload otherwise cleared
EEPROM locations.
-

Location is an optional constant (0-255) which specifies where to begin


storing the data in the eeprom. If no location is specified, storage continues
from where it last left off. If no location was initially specified, storage
begins at 0.
Data are constants (0-255) which will be stored in the eeprom.

When using the Stamp modules, data storage builds upward from 0 while
program storage builds downward from 255. When using the PICAXE-18, data
storage builds upward from 0 while program storage builds downward from
128.
When programming FLASH microcontrollers (PIC16F84, PICAXE-28,
assembler) this command is mapped to the FLASH data memory. Therefore
check the upper data memory limit, as the PIC16F84A, PIC16F870, PIC16F872
and PICAXE-28 only have 64 data memory bytes (valid locations 0-63).
Example:
EEPROM 0,(Hello World)

save values in EEPROM

main: for b0 = 1 to 11
read b0,b1
serout 7,T2400,(b1)
next b0

revolution

copyright 2001

start a loop
read value from EEPROM
transmit to serial LCD module
next character

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
10 Section 1

end
END

Sleep terminally until the power cycles (program re-runs) or the pc connects.
Power is reduced to an absolute minimum (assuming no loads are being
driven).
Note: The compiler always places an END instruction after the last line of a
program.
Example:
loop:
let b2 = 15
pause 2000
gosub flsh
let b2 = 5
pause 2000
gosub flsh
end

flsh: for b0 = 1 to b2
high 1
pause 500
low 1
pause 500
next b0
return

revolution

copyright 2001

set b2 value
wait for 2 seconds
call sub-procedure
set b2 value
wait for 2 seconds
call sub-procedure
stop accidentally falling into sub

define loop for b2 times


switch on output 1
wait 0.5 seconds
switch off output 1
wait 0.5 seconds
end of loop
return from sub-procedure

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
11 Section 1

for...next
FOR variable = start TO end {STEP {-}increment}
NEXT {variable}

Establish FOR-NEXT loop.


-

Variable will be used as a counter

Start is the initial value of Variable

End is the terminal value of Variable

Increment is an optional value which overrides the default counter delta of


+1. If Increment is preceeded by a -, it will be assumed that End is greater
than Start, and therefore, Increment will be subtracted each time through
the loop rather than added

Example:
loop: for b0 = 1 to 20
high 1
pause 500
low 1
pause 500
next b0
pause 2000
goto loop

define loop for 20 times


switch on output 1
wait 0.5 seconds
switch off output 1
wait 0.5 seconds
end of loop

wait for 2 seconds


loop back to start

forward
FORW
ARD m
otor
FORWARD
motor

Make motor output turn forwards


- Motor is the motor name A or B.
NB: This is a pseudo command that actually parses multiple high/low
commands.
Example:
loop: forward A
wait 5
backward A
wait 5
halt A
wait 5
goto loop

revolution

copyright 2001

motor a on forwards
wait 5 seconds
motor a on backwards
wait 5 seconds
motor A reverse
wait 5 seconds
loop back to start

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
12 Section 1

gosub
GOSUB address

Go to subroutine at address. Up to 16 GOSUBS are allowed and they can be


nested up to 4 deep.
-

Address is a label which specifies where to go.

Example:
loop:
let b2 = 15
pause 2000
gosub flsh
let b2 = 5
pause 2000
gosub flsh
end
flsh: for b0 = 1 to b2
high 1
pause 500
low 1
pause 500
next b0
return

set b2 value
wait for 2 seconds
call sub-procedure
set b2 value
wait for 2 seconds
call sub-procedure
stop accidentally falling into sub

define loop for b2 times


switch on output 1
wait 0.5 seconds
switch off output 1
wait 0.5 seconds
end of loop
return from sub-procedure

goto
GOTO address

Go to address.
- Address is a label which specifies where to go.
Example:
loop: high 1
pause 5000
low 1
pause 5000
goto loop

revolution

copyright 2001

switch on output 1
wait 5 seconds
switch off output 1
wait 5 seconds
loop back to start

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
13 Section 1

halt
HAL
otor
HALTT m
motor

Make motor output stop.


- Motor is the motor name A or B.
NB: This is a pseudo command that actually parses multiple low commands.
Example:
loop: forward A
wait 5
backward A
wait 5
halt A
wait 5
goto loop

motor a on forwards
wait 5 seconds
motor a on backwards
wait 5 seconds
motor A reverse
wait 5 seconds
loop back to start

high
HIGH pin

Make pin output high.


- Pin is a variable/constant (0-7) which specifies the i/o pin to use.
Example:
loop: high 1
pause 5000
low 1
pause 5000
goto loop

switch on output 1
wait 5 seconds
switch off output 1
wait 5 seconds
loop back to start

highA
HIGHA pin

Make pin on PORTA output high.


- Pin is a variable/constant (0-4) which specifies the i/o pin to use.
Example:
loop: higha 1
pause 5000
lowa 1
pause 5000
goto loop

revolution

copyright 2001

switch on output 1
wait 5 seconds
switch off output 1
wait 5 seconds
loop back to start

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
14 Section 1

if...then
IF variable ?? value {AND/OR variable ?? value ...} THEN address
?? can be =, <>, =>, =<, >, <

Compare and conditionally branch.


- Variable(s) will be compared to Value(s).
- Value is a variable/constant.
- Address is a label which specifies where to go if condition is true.
Example:
loop: if pin0 = 1 then flsh
jump to flsh if pin0 is high
goto loop
else loop back to start
flsh: high 1
pause 5000
low 1
goto loop

revolution

copyright 2001

switch on output 1
wait 5 seconds
switch off output 1
loop back to start

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
15 Section 1

infrain
INFRAIN

Wait until a new infrared command is received.


This command is used to wait for a new infrared signal from the infrared
transmitter. All processing stops until the new command is received. The value
of the command received is placed in the predefined variable infra.
Example:
loop:
infrain
if infra =
if infra =
if infra =
if infra =
if infra =
if infra =
goto loop
swon1:
swon2:
swon3:
swoff1:
swoff2:
swoff3:

1
2
3
4
5
6

then
then
then
then
then
then

swon1
swon2
swon3
swoff1
swoff2
swoff3

'wait for new signal


'switch on 1
'switch on 2
'switch on 3
'switch off 1
'switch off 2
'switch off 3

high 1
goto loop
high 2
goto loop
high 3
goto loop
low 1
goto loop
low 2
goto loop
low 3
goto loop

revolution

copyright 2001

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
16 Section 1

if sensor...then
NB: This is a special pseudo command that was developed for the Higher Still
Technological Studies Inputs Module when used with the Stamp Controller
module. If you are not using this module you should use the POT or READADC
command instead.
IF SENSORA ?? value {AND/OR variable ?? value ...} THEN address
?? can be =, <>, =>, =<, >, <

Compare and conditionally branch.


- Variable(s) will be compared to Value(s).
- Value is a variable/constant.
- Address is a label which specifies where to go if condition is true.
NB: This is a pseudo command that actually parses multiple BASIC commands.
The BASIC equivalent is a pulsin b11 command followed by an if b11 then
command.
Note that as this command uses variable b11 this variable should not be used
at any other time during the program.
Example:
loop: if sensorA > 50 then flsh
jump to flsh if sensorA > 50
goto loop
else loop back to start
flsh: high 1
pause 5000
low 1
goto loop

switch on output 1
wait 5 seconds
switch off output 1
loop back to start

input
INPUT pin

Make pin an input


- Pin is a variable/constant (0-7) which specifies the i/o pin to use.
Example:
loop: input 1
reverse 1
reverse 1
output 1

revolution

copyright 2001

make
make
make
make

pin
pin
pin
pin

input
output
input
output

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
17 Section 1

inputa
INPUT
A pin
INPUTA

Make pin on PORTA an input


- Pin is a variable/constant (0-4) which specifies the i/o pin to use.
Example:
loop: inputa 1
outputa 1

make pin input


make pin output

lcd
LCD
LCD
LCD
LCD

({#}data,{#}data...)
clear
line1
line2

Serial output to the LCD module connected to pin7.


Clear clears the LCD, line1 moves to start of line 1, line2 moves to start of
line2
-

Data are variables/constants (0-255) which provide the data to be output.


Optional #s are for outputting ascii decimal numbers, rather than raw
characters.

NB: This is a pseudo command that actually parses serout commands.


The true BASIC equivalent is serout 7,T2400,(data)
loop: LCD (hello)
LCD line2
LCD (there!)
pause 2000
LCD clear
pause 500
goto loop

revolution

copyright 2001

print the word hello


move to line2
print the word
wait 2 seconds
blank LCD
wait 0.5 seconds
loop back to start

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
18 Section 1

let
{LET} variable = {-}value ?? value ...
??:

+
*
**
/
//
MAX
MIN
&
|
^
&/
|/
^/

;add
;subtract
;multiply (returns low word of result)
;multiply (returns high word result)
;divide (returns quotient)
;divide (returns remainder)
;make less than or equal to
;make greater than or equal to
;and
;or
(typed as SHIFT + \ on UK keyboard)
;xor (typed as SHIFT + 6 on UK keyboard)
;and not
;or not
;xor not

Perform variable manipulation (wordsize-to-wordsize). Math is performed


strictly from left to right.
- Variable will be operated on.
- Value(s) are variables/constants which operate on Variable.
Example:
loop: let b0 = b0 + 1
sound 7,(b0,50)
if b0 > 50 then rest
goto loop

rest: let b0 = 10
goto loop

reset b0 to 10
loop back to start

revolution

copyright 2001

increment b0
make a sound
after 50 reset
loop back to start

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
19 Section 1

lookdown
LOOKDOWN target,(value0,value1...valueN),variable

Get targets match number (0-N) into variable (if match found).
-

Variable receives the result (if any).

Target is a variable/constant which will be compared to Values.

Values are variables/constants.

Example:
rest: let infra = 0
reset infra variable
loop: if infra > 0 then test
jump to test if new signal detected
goto loop
else loop back
test:
lookdown infra,(1234),b0
put the ascii character 1 to 4 into b0

lookup
LOOKUP offset,(data0,data1...dataN),variable

Lookup data specified by offset and store in variable (if in range).


-

Variable receives the result (if any).

Offset is a variable/contant which specifies which data# (0-N) to place in


Variable.

Data are variables/constants.

Example:
loop: let b0 = b0 + 1
lookup b0,(1234),b1
if b0 < 4 then loop
end

revolution

copyright 2001

increment b0
put ascii character into b1
loop

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
20 Section 1

low
LOW pin

Make pin output low.


- Pin is a variable/constant (0-7) which specifies the i/o pin to use.
Example:
loop: high 1
pause 5000
low 1
pause 5000
goto loop

switch on output 1
wait 5 seconds
switch off output 1
wait 5 seconds
loop back to start

lowa
LOW
A pin
LOWA

Make pin on PORTA output low.


- Pin is a variable/constant (0-4) which specifies the i/o pin to use.
Example:
loop: higha 1
pause 5000
lowa 1
pause 5000
goto loop

switch on output 1
wait 5 seconds
switch off output 1
wait 5 seconds
loop back to start

nap
NAP period

Nap for a short period. Power consumption is reduced to an extent dependent


upon the length of the period.
-

Period is a variable/constant which determines the duration of the reducedpower nap. The duration will be 2^period * ~18ms. Period can range from
0 to 7.

Example:
loop: high 1
nap 4
low 1
nap 7
goto loop

revolution

copyright 2001

switch on output 1
nap for 2^4 x 18ms
switch off output 1
nap for 2^7 x 18ms
loop back to start

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
21 Section 1

output
OUTPUT pin

Make pin output.


- Pin is a variable/constant (0-7) which specifies the i/o pin to use.
Example:
loop: input 1
reverse 1
reverse 1
output 1

make
make
make
make

pin
pin
pin
pin

input
output
input
output

outputa
OUTPUT
A pin
OUTPUTA

Make pin on PORTA output.


- Pin is a variable/constant (0-4) which specifies the i/o pin to use.
Example:
loop: inputa 1
outputa 1

make pin input


make pin output

pause
PAUSE millisecon
ds
milliseconds

Pause for some time. The duration of the pause is as accurate as the resonator
time-base, and presumes a 4MHz resonator.
-

Milliseconds is a variable/constant (0-65535) which specifies how many


milliseconds to pause.

Example:
loop: high 1
pause 5000
low 1
pause 5000
goto loop

revolution

copyright 2001

switch on output 1
wait 5 seconds
switch off output 1
wait 5 seconds
loop back to start

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
22 Section 1

pot
NB: See also the READADC command.
POT pin,scale,variable

Digitize a 5-50K ohm pot with a .1uf cap and scale result. This is a method of
analog input via a pin. The pin must connect to the center- tap of the pot,
whose side tap connects to the cap which connects to ground. Use the StampPot menu command to determine the scale, while the stamp module is
connected and the pot circuit is in place.
-

Pin is a variable/constant (0-7) which specifies the i/o pin to use.

Scale is a constant (0-255) which is used to scale the initial result by n/256
(result is then limited to 255).

Variable receives the result (0-255).

Example:
loop: pot 3,20,b1
if b1 > 50 then flsh
goto loop
flsh: high 1
pause 5000
low 1
goto loop

revolution

copyright 2001

read value into b1


jump to flsh if b1 > 50
else loop back to start

switch on output 1
wait 5 seconds
switch off output 1
loop back to start

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
23 Section 1

peek
PEEK location,variable

Read FSR location contents into variable. This allows use of registers not
defined by b0-b13.
-

Location is a variable/constant specifying a register address. Valid values


are 0 to 127.
Data is a variable/constant which provides the data byte to be written.

Use of this command requires care. For inexperienced users it is recommended


that the locations are limited to addresses 80 to 127, which can be used freely.
Addresses 0 to 31 are special function registers (e.g. PORTB) which determine
how the microcontroller operates. Avoid using these addresses unless you
know what you are doing!
Addresses 32 to 79 are general purpose registers reserved for use with the
interpreter. Use of these registers may produce unexpected results when the
interpreter alters the register value.
Addresses 80 to 127 are general purpose registers that can be used freely.
Addresses 128 to 255 do not exist in most low-cost microcontrollers.
peek 80,b1

revolution

put value of register 80 into variable b1

copyright 2001

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
24 Section 1

poke
POKE location,data

Write data into FSR location. This allows use of registers not defined by b0-b13.
-

Location is a variable/constant specifying a register address. Valid values


are 0 to 127.
Data is a variable/constant which provides the data byte to be written.

Use of this command requires care. For inexperienced users it is recommended


that the locations are limited to addresses 80 to 127, which can be used freely.
Addresses 0 to 31 are special function registers (e.g. PORTB) which determine
how the microcontroller operates. Avoid using these addresses unless you
know what you are doing!
Addresses 32 to 79 are general purpose registers reserved for use with the
interpreter. Use of these registers may produce unexpected results when the
interpreter alters the register value.
Addresses 80 to 127 are general purpose registers that can be used freely.
Addresses 128 to 255 do not exist in most low-cost microcontrollers.
Example:
poke 80,b1

save value of b1 in register 80

pulsin
PULSIN pin,state,variable

Measure an input pulse.


-

Pin is a variable/constant (0-7) which specifies the i/o pin to use.

State is a variable/constant (0 or 1) which specifies which edge must occur


before beginning the measurement in 10us units.

Variable receives the result (1-65536). If timeout occurs (.65536s) the


result will be 0.

Example:
pulsin 3,1,b1

revolution

record the length of a pulse on pin 3 into b1

copyright 2001

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
25 Section 1

pulsout
PULSOUT pin,time

Output a timed pulse by inverting a pin for some time.


-

Pin is a variable/constant (0-7) which specifies the i/o pin to use.

Time is a variable/constant which specifies the period (0-65535) in 10us


units.

Example:
loop: pulsout 4,150
pause 20
goto loop

send a 1.50ms pulse out of pin 4


pause 20 ms
loop back to start

pwm
PWM pin,d
uty
,cycles
pin,duty
uty,cycles

Output pwm then return pin to input. This is used to output analog voltages
(0-5V) via a pin connected to a resistor connected to a cap connected to ground;
the resistor-cap junction being the analog output.PWM should be executed
periodically to update/refresh the analog voltage.
-

Pin is a variable/constant (0-7) which specifies the i/o pin to use.

Duty is a variable/constant (0-255) which specifies analog level.

Cycles is a variable/constant (0-255) which specifies number of cycles.


Each cycle takes about 5ms.

Example:
loop: pwm 4,150,20
pause 20
goto loop

send 20 pwm bursts out of pin 4


pause 20 ms
loop back to start

random
RANDOM wordvariable

Generate next pseudo-random number in a word variable.


- Wordvariable is both the workspace and the result.
Example:
loop: random b1
let pins = b1
pause 100
goto loop

revolution

copyright 2001

put random value into b1


put random value on output pins
wait 0.1s
loop back to start

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
26 Section 1

readadc
READADC channel,variable

Read ADC channel contents into variable.


- channel is a variable/constant specifying a byte-wise address (0-3).
- Variable receives the data byte read.
Example:
loop: readadc 1,b1
if b1 > 50 then flsh
goto loop
flsh: high 1
pause 5000
low 1
goto loop

read value into b1


jump to flsh if b1 > 50
else loop back to start

switch on output 1
wait 5 seconds
switch off output 1
loop back to start

read
READ location,variable

Read eeprom location contents into variable. location 255 holds highest
location minus one that is available to user for data storage.
- Location is a variable/constant specifying a byte-wise address (0-255).
- Variable receives the data byte read.
When using the Stamp modules, data storage builds upward from 0 while
program storage builds downward from 255. When using the PICAXE-18, data
storage builds upward from 0 while program storage builds downward from
128.
When programming FLASH microcontrollers (PIC16F84, PICAXE-28,
assembler) this command is mapped to the FLASH data memory. Therefore
check the upper data memory limit, as the PIC16F84A, PIC16F870, PIC16F872
and PICAXE-28 only have 64 data memory bytes (valid locations 0-63).
Example:
loop: for b0 = 0 to 63
read b0,b1
serout 7,T2400,(b1)
next b0

revolution

copyright 2001

start a loop
read value into b1
transmit value to serial LCD
next loop

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
27 Section 1

readmem
READMEM location,variable

Read FLASH program memory eeprom location into variable. Provides


additional 256 bytes storage space to the read command for PIC16F87x devices
(including PICAXE)
- Location is a variable/constant specifying a byte-wise address (0-255).
- Variable receives the data byte read.
Example:
loop: for b0 = 0 to 255
readmem b0,b1
serout 7,T2400,(b1)
next b0

start a loop
read value into b1
transmit value to serial LCD
next loop

return
RETURN

Return from subroutine.


Example:
loop:
let b2 = 15
pause 2000
gosub flsh
let b2 = 5
pause 2000
gosub flsh
end

flsh: for b0 = 1 to b2
high 1
pause 500
low 1
pause 500
next b0
return

revolution

copyright 2001

set b2 value
wait for 2 seconds
call sub-procedure
set b2 value
wait for 2 seconds
call sub-procedure
stop accidentally falling into sub

define loop for b2 times


switch on output 1
wait 0.5 seconds
switch off output 1
wait 0.5 seconds
end of loop
return from sub-procedure

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
28 Section 1

reverse
REVERSE pin

Reverse the direction of a pin (input to output or vice versa)


- Pin is a variable/constant (0-7) which specifies the i/o pin to use.
Example:
loop: input 1
reverse 1
reverse 1
output 1

make
make
make
make

pin
pin
pin
pin

input
output
input
output

serin
SERIN pin,bau
dmod
alifi
er
,qu
alifi
er
...)
pin,baud
odee,(qu
,(qualifi
alifier
er,qu
,qualifi
alifier
er...)
er
,qu
alifi
er
...),{#}vari
able
,{#}vari
able
...
SERIN pin,bau
alifi
...),{#}variable
able,{#}vari
,{#}variable
able...
pin,baud
odee,(qu
,(qualifi
alifier
er,qu
,qualifi
alifier
er...),{#}vari
dmod
SERIN pin,baudmode,{#}variable,{#}variable...

Serial input with optional qualifiers (8 data, no parity, 1 stop).


-

Pin is a variable/constant (0-7) which specifies the i/o pin to use.

Baudmode is a variable/constant (0-7) which specifies the mode:


T2400
T1200
T600
T300
N2400
N1200
N600
N300

true input
true input
true input
true input
inverted input
inverted input
inverted input
inverted input

Qualifiers are optional variables/constants (0-255) which must be received


in exact order before subsequent bytes can be received and stored in
variables.

Variable(s) receive the result(s) (0-255). Optional #s are for inputting ascii
decimal numbers into variables, rather than raw characters.

Example:
loop: for b0 = 0 to 63
serin 6,T2400,b1
write b0,b1
next b0

revolution

copyright 2001

start a loop
receive serial value
write value into b1
next loop

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
29 Section 1

serout
SEROUT pin,baudmode,({#}data,{#}data...)

Serial output (8 data, no parity, 1 stop).


-

Pin is a variable/constant (0-7) which specifies the i/o pin to use.

Baudmode is a variable/constant (0-15) which specifies the mode:


T2400
T1200
T600
T300
N2400
N1200
N600
N300
OT2400
OT1200
OT600
OT300
ON2400
ON1200
ON600
ON300

true output
true output
true output
true output
inverted output
inverted output
inverted output
inverted output
true output
true output
true output
true output
inverted output
inverted output
inverted output
inverted output

always driven
always driven
always driven
always driven
always driven
always driven
always driven
always driven
open-drain
open-drain
open-drain
open-drain
open-source
open-source
open-source
open-source

Data are variables/constants (0-255) which provide the data to be output.


Optional #s are for outputting ascii decimal numbers, rather than raw
characters.

Example:
loop: for b0 = 0 to 63
read b0,b1
serout 7,T2400,(b1)
next b0

revolution

copyright 2001

start a loop
read value into b1
transmit value to serial LCD
next loop

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
30 Section 1

servo
SERVO pin,pulse

Pulse an output pin to drive a radio-control style servo


- Pin is a variable/constant (0-7) which specifies the i/o pin to use.
- Pulse is variable/constant (75-225) which specifies the servo position
This command starts a pin pulsing high for length of time pulse (x0.01 ms)
every 20ms.
Generally r/c servo require a pulse of 0.75 to 2.25ms every 20ms. Therefore the
command servo 1,75 will move the servo to one end (0 degrees) and servo
1,225 will move the servo to the other end (180 degrees). servo 1,150 will
move the servo to the central position.
This command is different to all other BASIC commands in that the pulsing
mode continues until another servo, high or low command is executed. High
and low commands stop the pulsing immediately. Servo commands adjust the
pulse length to the new pulse value, hence moving the servo.
Do not use a pulse value less than 75 or greater than 225, as this may cause the
servo to malfunction. Due to tolerances in servo manufacture all values are
approximate and will require fine-tuning by experimentation.
Note that the overhead processing time required for processing the servo
commands every 20ms causes the other commands to be slightly extended i.e.
a pause command will take slightly longer than expected. The servo pulses are
also temporarily disabled during timing sensitive serin and serout commands.
Example:
loop: servo 4,75
pause 2000
servo 4,150
pause 2000
servo 4,225
pause 2000
goto loop

revolution

copyright 2001

move
wait
move
wait
move
wait
loop

servo to one end


2 seconds
servo to centre
2 seconds
servo to other end
2 seconds
back to start

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
31 Section 1

sleep
SLEEP seconds
Sleep for some seconds (resolution is ~2.3s, accuracy is ~99.9%). Power
consumption is reduced to 1/100th normal (if no loads are being driven).
-

Seconds is a variable/constant which specifies the duration of sleep in


seconds (0-65535).

Example:
loop: high 1
sleep 10
low 1
sleep 100
goto loop

switch on output 1
sleep for 9.2s
switch off output 1
sleep for 98.9s
loop back to start

symbol
SYMBOL symbolname = value

Assign a value to a new symbolname.


-

Symbolname is a text string which must begin with an alpha-character or _.


After the first character, it can also contains number characters (0-9').

Value is a variable or constant which is being given an alternate


symbolname.

Example:
symbol RED_LED = 7
symbol COUNTER = B0
let COUNTER = 200
loop: high RED_LED
pause COUNTER
low RED_LED
pause COUNTER
goto LOOP

revolution

copyright 2001

define a constant symbol


define a variable symbol

preload counter with 200


switch on output 7
wait 0.2 seconds
switch off output 7
wait 0.2 seconds
loop back to start

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
32 Section 1

sound
SOUND pin,(note,duration,note,duration...)

Play notes with durations. The pin must connect to a piezo transducer, or a
speaker and 10uf electrolytic capacitor. The transducer connects between the
pin and ground.
-

Pin is a variable/constant (0-7) which specifies the i/o pin to use.

Note(s) are variables/constants (0-255) which specify type and frequency.


Note 0 is silent for the duration. Notes 1-127 are ascending tones. Notes
128-255 are ascending white noises.

Duration(s) are variables/constants (0-255) which specify duration.

Example:
loop: let b0 = b0 + 1
sound 7,(b0,50)
goto loop

increment b0
make a sound
loop back to start

switch on
SWITCH ON pin
SWITCHON pin

Make pin output high.


- Pin is a variable/constant (0-7) which specifies the i/o pin to use.
NB: This is a pseudo command that actually parses a high command.
Example:
loop: switch on 7
wait 5
switch off 7
wait 5
goto loop

revolution

copyright 2001

switch on output 7
wait 5 seconds
switch off output 7
wait 5 seconds
loop back to start

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
33 Section 1

switch off
SWITCH OFF pin
SWITCHOFF pin

Make pin output low.


- Pin is a variable/constant (0-7) which specifies the i/o pin to use.
NB: This is a pseudo command that actually parses a low command.
Example:
loop: switch on 7
wait 5
switch off 7
wait 5
goto loop

switch on output 7
wait 5 seconds
switch off output 7
wait 5 seconds
loop back to start

toggle
TOGGLE pin

Make pin output and toggle state.


- Pin is a variable/constant (0-7) which specifies the i/o pin to use.
Example:
loop: toggle 7
pause 1000
goto loop

revolution

copyright 2001

toggle output 7
wait 1 second
loop back to start

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
34 Section 1

wait
WAIT secon
ds
seconds

Pause for some time.


- Seconds is a constant (0-65) which specifies how many seconds to pause.
NB: This is a pseudo command that actually parses a pause command.
Example:
loop: switch on 7
wait 5
switch off 7
wait 5
goto loop

switch on output 7
wait 5 seconds
switch off output 7
wait 5 seconds
loop back to start

write
WRITE location,data

Write data into eeprom.


- Location is a variable/constant specifying a byte-wise address (0-255).
- Data is a variable/constant which provides the data byte to be written.
When using the Stamp modules, data storage builds upward from 0 while
program storage builds downward from 255. When using the PICAXE-18, data
storage builds upward from 0 while program storage builds downward from
128.
When programming FLASH microcontrollers (PIC16F84, PICAXE-28,
assembler) this command is mapped to the FLASH data memory. Therefore
check the upper data memory limit, as the PIC16F84A, PIC16F870, PIC16F872
and PICAXE-28 only have 64 data memory bytes (valid locations 0-63).
Example:
loop: for b0 = 0 to 63
serin 6,T2400,b1
write b0,b1
next b0

revolution

copyright 2001

start a loop
receive serial value
write value into b1
next loop

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
35 Section 1

writemem
WRITEMEM location,data

Write FLASH program memory data into location. Provides additional 256
bytes storage space to the read command for PIC16F87x devices (including
PICAXE)
- Location is a variable/constant specifying a byte-wise address (0-255).
- Data is a variable/constant which provides the data byte to be written.
Example:
loop: for b0 = 0 to 255
serin 6,T2400,b1
writemem b0,b1
next b0

revolution

copyright 2001

start a loop
receive serial value
write value into b1
next loop

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

COMMANDS
36 Section 1

CONT
A CT
CONTA
CTSS
The latest version of the Programming Editor can be downloaded from the following
website:

www
.r
ev-ed
.co.uk
www.r
.rev-ed
ev-ed.co.uk
A forum for the discussion of PIC and Stamp projects, and for technical support, also
exists at this site.

Contact Addresses:

Revolution Education Ltd


BIC, Innova Science Park, Mollison Ave, Enfield, EN3 7XU, UK
http://www.rev-ed.co.uk/

Higher Still Development Programme


PO Box 12754, Ladywell House, Ladywell Road, Edinburgh, EH12 7YH, UK
http://www.higher-still.org.uk/

Parallax, Inc
3805 Atherton road, #102, Rocklin, CA 95765, USA
http://www.parallaxinc.com/

revolution

copyright 2001

Revolution Education Ltd.

Email: info@rev-ed.co.uk

Web: www.rev-ed.co.uk

Você também pode gostar