What is a Robot? - California Lutheran University

Download Report

Transcript What is a Robot? - California Lutheran University

The Basic Stamp
Instruction Set Architecture
The Microprocessor
•
•
•
•
A microprocessor is a computer that typically has an architecture that is
well suited to embedded systems applications
– Built in memory
– Built in I/O pins and registers
– Hardware interface support
The instruction set is typically of the Reduced Instruction Set Computer
(RISC) type
– A minimalist list of instructions required to manipulate hardware
devices
– Nothing fancy
They are usually rolled out as a “family” of devices
– Various capabilities to suite a multitude of embedded applications
We’re using the BASIC Stamp – BS2
– The microprocessor is a PIC16C57
– There are a family of BASIC Stamp processors including BS1, BS2,
BS2E, BS2SX, BS2P, BS2PE, BS2PX
The BS2 Instruction Set
• While most microprocessor instruction
sets are specified in Register Transfer
Language (RTL) and assembly
language, the BS2 is specified in
PBASIC
– The architecture is specifically designed to
execute PBASIC instructions
Preliminaries
• The BASIC Stamp IDE is designed to work
with the entire family of BASIC Stamp devices
• Thus, it is important that you provide the
correct compiler directives in your code
'{$STAMP BS2} 'STAMP directive (specifies a BS2)
'{$PBASIC 2.5} ' PBASIC Version directive
• The IDE has buttons to insert these into your
code (you don’t have to memorize them)
The Instructions
Branching
GOSUB address
– Jump to subroutine, address (label)
ON offset GOSUB address1, address2, address3, …
– Call the subroutine at the 0-based offset in the
label list
address
RETURN
– Return from a GOSUB or ON GOSUB command
GOTO address
– Jump to a specific address (label)
ON offset GOTO address1, address2, address3, …
– Jump to the 0-based offset in the address label list
Looping
DO
statements
LOOP
DO WHILE (condition)
statements
LOOP
DO UNTIL (condition)
statements
LOOP
DO
statements
LOOP WHILE (condition)
DO
statements
LOOP UNTIL (condition)
FOR counter = start TO end STEP value
statements
NEXT
–
Beware of counting down, strange things
may happen due to 2’s complement
notation
EXIT
–
Bail out of a loop early (like break in Java)
Conditional Branching
IF condition THEN address
–
Goto address label if condition is true
IF condition THEN
statements
ELSEIF condition THEN
statements
ELSE
statements
ENDIF
–
Conditional statement, ELSEIF is optional
•
•
•
•
BRANCH value, [case0, case1, case2]
Equivalent to:
IF value = 0 THEN case0
IF value = 1 THEN case1
IF value = 2 THEN case2
•
SELECT…CASE
compact form of an IF THEN ELSEIF command
Data Declarations – RAM
symbol VAR type
–
Type can be
•
•
•
•
Bit – 1 bit
Nib – 4 bits
Byte – 8 bits
Word – 16 bits
•
Arrays
symbol VAR type(entries)
•
Alias
symbol VAR symbol
•
Partial access though suffixes
.BITn
.NIBn
.BYTEn
.LOWBYTE
.HIGHBYTE
.LOWNIB
.HIGHNIB
Data Declarations – EEPROM
DATA value1, value2, value3, …
– Write data values to EEPROM to be read later
with READ
– Differs from VAR in that DATA uses EEPROM and
VAR uses RAM
READ location, variable
– read a value from the EEPROM that was
previously loaded with a DATA command
WRITE location, data
– write data to address location in the EEPROM
Data access
LOOKDOWN value, [item0, item1, item2, …]
result
– Assign the 0-based index of value in the item list into result
– No assignment if value is not in the item list
LOOKUP index, [value0, value1, value2, …]
result
• Assign the value from item list at 0-based index into result
• No assignment if index is too big
Termination
END
– End the program, go to low power mode
STOP
– Stop program execution without going into
low power mode
Power Management
NAP period
– go to reduced power mode for 2period * 18 mSecs
SLEEP duration
– put the BASIC stamp into low power mode for duration
Seconds rounded up to units of 2.3 seconds
PAUSE duration
– Sleep for duration mSecs (stay in normal power)
Input/Output
BUTTON pin, downstate, delay, rate, workspace,
targetstate, address
– Read button state with debounce options
COUNT pin, duration, variable
– Count the number of 0-1-0 or 1-0-1 transition for duration
time in mSec
HIGH pin
– Set a high signal on pin
LOW pin
– Set a high signal on pin
Input/Output
INn
– Read from pin n
OUTn
– Write to pin n
TOGGLE pin
– Invert the state of the pin
Input/Output
FREQOUT pin, duration, frequency
– Output a sine wave on a pin
PWM pin, duty, duration
– Use pulse-width modulation to convert a digital value to
analog
PULSIN pin, state, variable
– Measure the width of an incoming pulse on the specified pin
PULSOUT pin, duration
– Send a pulse to pin of width duration in units of 2 uSecs
Input/Output
SERIN
– Read RS232 formatted data on an I/O pin
SEROUT
– Write RS232 formatted data on an I/O pin
Miscellaneous
• Math
SIN, COS, ABS, SQR, RANDOM…
– Note that these do not return floating point
numbers
– The return integers within some defined range
DEBUG output, output, …
– Write data to the debug monitor window
And Then Some…
• There are many more commands
• I’ve just touched on the most useful ones for
what we do
• Online help installed with the IDE shows all
– Look for those labeled BS2
• Full manual can be gotten here:
– http://www.parallax.com/dl/docs/prod/stamps/webBSM-v2.2.pdf