BASIC Stamp II Instruction Set
July 20, 1995


+ Indicates new or greatly improved instructions (not available on Stamp I).


BRANCHING ---------------------------------------------------------------------

     IF...THEN   Compare and conditionally branch.
     BRANCH      Branch to address specified by offset.
     GOTO        Branch to address.
     GOSUB       Branch to subroutine at address.
     RETURN      Return from subroutine.

LOOPING -----------------------------------------------------------------------

     FOR...NEXT  Establish a FOR-NEXT loop.

NUMERICS ----------------------------------------------------------------------

     LOOKUP      Lookup data specified by offset and store in variable. This
                 instruction provides a means to make a lookup table.

     LOOKDOWN    Find target match number (0-N) and store in variable.
     RANDOM      Generate a pseudo-random number.

DIGITAL I/O -------------------------------------------------------------------

     INPUT       Make pin an input
     OUTPUT      Make pin an output.
     REVERSE     If pin is an output, make it an input. If pin is an input,
                 make it an output.

     LOW         Make pin output low.
     HIGH        Make pin output high.
     TOGGLE      Make pin an output and toggle state.
     PULSIN      Measure an input pulse (resolution of 2 us).
     PULSOUT     Output a timed pulse by inverting a pin for some time
                 (resolution of 2 us).

     BUTTON      Debounce button, perform auto-repeat, and branch to address if
                 button is in target state.

+    SHIFTIN     Shift bits in from parallel-to-serial shift register.
+    SHIFTOUT    Shift bits out to serial-to-parallel shift register.

+    COUNT       Count cycles on a pin for a given amount of time (0 - 125 kHz,
                 assuming a 50/50 duty cycle).

+    XOUT        Generate X-10 powerline control codes.  For use with X-10
                 TW523 or TW513 powerline interface module.

SERIAL I/O --------------------------------------------------------------------

+    SERIN       Serial input with optional qualifiers, time-out, and flow
                 control. If qualifiers are given, then the instruction will
                 wait until they are received before filling variables or
                 continuing to the next instruction. If a time-out value is
                 given, then the instruction will abort after receiving nothing
                 for a given amount of time. Baud rates of 300 - 50,000 are
                 possible (0 - 19,200 with flow control). Data received must be
                 N81 (no parity, 8 data bits, 1 stop bit) or E71 (even parity,
                 7 data bits, 1 stop bit).

+    SEROUT      Send data serially with optional byte pacing and flow control.
                 If a pace value is given, then the instruction will insert a
                 specified delay between each byte sent (pacing is not
                 available with flow control). Baud rates of 300 - 50,000 are
                 possible (0 - 19,200 with flow control). Data is sent as N81
                 (no parity, 8 data bits, 1 stop bit) or E71 (even parity, 7
                 data bits, 1 stop bit).

ANALOG I/O --------------------------------------------------------------------

     PWM         Output PWM, then return pin to input. This can be used to
                 output analog voltages (0-5V) using a capacitor and resistor.

+    RCTIME      Measure an RC charge/discharge time.  Can be used to measure
                 potentiometers and other variable resistances.

SOUND -------------------------------------------------------------------------

+    FREQOUT     Generate one or two sinewaves of specified frequencies (each
                 from 0 - 32767 hz.).

+    DTMFOUT     Generate DTMF telephone tones.

EEPROM ACCESS -----------------------------------------------------------------

+    DATA        Store data in EEPROM before downloading BASIC program.
     READ        Read EEPROM byte into variable.
     WRITE       Write byte into EEPROM.

TIME --------------------------------------------------------------------------

     PAUSE       Pause execution for 0-65535 milliseconds.

POWER CONTROL -----------------------------------------------------------------

     NAP         Nap for a short period. Power consumption is reduced.
	
     SLEEP       Sleep for 1-65535 seconds. Power consumption is reduced to
                 approximately 50 uA.

     END         Sleep until the power cycles or the PC connects. Power
                 consumption is reduced to approximately 50 uA.

PROGRAM DEBUGGING -------------------------------------------------------------

     DEBUG       Send variables to PC for viewing.
