background image

Page 14  • BASIC Stamp II Manual 0.94  • Parallax, Inc. • (916) 624-8333

BASIC Stamp II

Program and Data Memory

The BS2 has 2K bytes of EEPROM which holds the executable BASIC
program and any data.  Memory not used by the BASIC program can
be read and written at run-time as a data bank, or initialized with data
at download time.  This memory is only affected by downloading or
run-time modification.

There are 32 bytes of RAM which serve as variable space and I/O pin
interface for the BASIC program.  This memory can be accessed as
words, bytes, nibbles, or bits.  Each time the BASIC program is run
anew, this memory is cleared to all zeroes.

So, the 2K byte EEPROM is for program and data, and only affected by
initial downloading or run-time modification.  It survives power-down.
The 32 bytes of RAM are for run-time variables and I/O pin access.
This memory is cleared each time the BS2 is powered up, reset, or down-
loaded to.

The 2K-byte EEPROM is arranged as follows:

byte $000

Data start

Data end

Program end

byte $7FF

Program start

Summary of Contents for BASIC Stamp II

Page 1: ...wn above Everything you need to know about programming the Stamp II may be found in this manual However even if you re only interested in the Stamp II you may gain useful knowledge by referring to the...

Page 2: ...BLANK PAGE...

Page 3: ...ng Programs 9 Editor Function Keys 9 BASIC Instruction Summary 11 Programming the Stamp II 14 Program and Data Memory 14 Defining variables VAR 17 Defining constants CON 20 Defining data DATA 21 Run t...

Page 4: ...amp II RANDOM 50 RCTIME 51 READ 52 RETURN 53 REVERSE 54 SERIN 55 SEROUT 59 SHIFTIN 62 SHIFTOUT 63 SLEEP 64 STOP 65 TOGGLE 66 WRITE 67 XOUT 68 Stamp II Application Notes 69 Note 1 Controlling lights an...

Page 5: ...of the Stamp A 5 volt supply should be connected directly to the Stamp s 5V pin also called VDD but a higher voltage should be connected to the Stamp s PWR pin also called VIN Connecting a high volta...

Page 6: ...nto a 24 pin DIP socket located in the center of the carrier When plugged onto the carrier board the words Parallax BS2 IC should be near the reset button 2 In the Stamp Programming Package you receiv...

Page 7: ...14 P9 I O pin 9 15 P10 I O pin 10 16 P11 I O pin 11 17 P12 I O pin 12 18 P13 I O pin 13 19 P14 I O pin 14 20 P15 I O pin 15 21 5V 5V supply 5 volt input or regulated output 22 RES Active low reset Pu...

Page 8: ...entire screen is available for entering and editing BASIC programs Command line options There are several command line options that may be useful when run ning the software these options are shown bel...

Page 9: ...xt in blocks of one character one word one line one screen or to the beginning or end of a file Cut copy and paste highlighted text Search for and or replace text See how the Stamp IIs memory is being...

Page 10: ...ft Ctrl Left Highlight one word to the left Shift Ctrl Right Highlight one word to the right Shift Home Highlight to beginning of line Shift End Highlight to end of line Shift Page Up Highlight one sc...

Page 11: ...tion provides a means to make a lookup table LOOKDOWN Find target s 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...

Page 12: ...before filling variables or continuing to the next instruc tion If a time out value is given then the instruc tion will abort after receiving nothing for a given amount of time Baud rates of 300 50 00...

Page 13: ...wnloading 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...

Page 14: ...of RAM which serve as variable space and I O pin interface for the BASIC program This memory can be accessed as words bytes nibbles or bits Each time the BASIC program is run anew this memory is clear...

Page 15: ...00 0000 variable space read write A 0000 0000 0000 0000 variable space read write B 0000 0000 0000 0000 variable space read write C 0000 0000 0000 0000 variable space read write D 0000 0000 0000 0000...

Page 16: ...igh nibble of OUTH OUT0 the low bit of OUTS corresponds to pin P0 OUT15 the high bit of OUTS corresponds to pin p15 Word 2 contains the direction bits for all 16 I O pins To place a pin in input mode...

Page 17: ...tements are resolved when you compile the program Alt R or Alt M and they do not generate any executable code Run time statements generate code and are executed at run time There are three compile tim...

Page 18: ...fter bit nib byte word a value may be placed within parentheses to declare an array size sym5 VAR nib 10 make a 10 nibble array define variables within variables or alias variables sym6 VAR sym4 highb...

Page 19: ...4 of a word or byte BIT5 bit5 of a word or byte BIT6 bit6 of a word or byte BIT7 bit7 of a word or byte BIT8 bit8 of a word BIT9 bit9 of a word BIT10 bit10 of a word BIT11 bit11 of a word BIT12 bit12...

Page 20: ...I users W0 W12 and the corresponding B0 B25 are pre defined by the compiler software to make use of Stamp I programs easier If you use a Stamp I program with the Stamp II you can enter the older Wx a...

Page 21: ...limit The compiler will always tell you when you have a conflict DATA statements are used to build data into unused memory Ini tially the DATA location is set to 0 It is advanced by 1 for each byte d...

Page 22: ...DATA word 16 reserve 16 words of undefined data Important concept Defined DATA and BASIC program memory are always downloaded to the BS2 Undefined data and unused EEPROM memory are not downloaded This...

Page 23: ...0 t2 DATA Here s table 2 0 t3 DATA Here s table 3 0 t4 DATA Here s table 4 0 start DATA word t1 word t2 word t3 word t4 Run Time Expressions Run time expressions can contain constants variables operat...

Page 24: ...d be 0 79 There are also binary unary and conditional expression operators Unary operators preceed a variable or constant or expression and have highest priority They are as follows SQR Square root of...

Page 25: ...d return middle 16 bits of result use to simultaneously multiply by a whole and a part ie value 0180 multiplies by 1 and a half Divide Divide and return remainder DIG Return decimal digit 12345 dig 3...

Page 26: ...of all NOT Highest priority unary AND OR XOR Highest priority binaries Note These are arithmetically identical to expression operators though they differ in application Lower priority conditional bina...

Page 27: ...Branch according to an index usage BRANCH index label0 label1 label2 labelN If index 0 a GOTO label0 will be executed If index 1 a GOTO label1 will be executed If the index exceeds the number of labe...

Page 28: ...is pressed Delay specifies down time before auto repeat in BUTTON cycles Rate specifies the auto repeat rate in BUTTON cycles Bytevariable is workspace for the BUTTON instruction It must be cleared to...

Page 29: ...For period milliseconds cycles will be counted on the designated I O pin Both sides of the waveform must be at least 4 s in duration which limits the input frequency to 125 kHz assuming a 50 50 duty...

Page 30: ...BUG dec X Show X in decimal with relation will yield if x 1 X 1 DEBUG dec X Show X in decimal yields 1 When printing numbers these prefixes can be used before expressions ASC Show ASCII value with rel...

Page 31: ...ollowed by a but ASC needs one DEBUG statements can contain many strings and numbers separated by commas In addition there are several special control characters which are interpreted by the PC Name V...

Page 32: ...fault on and off times are 200 ms and 50 ms Ontime and offtime are optional overrides in milliseconds Key s are 0 15 which are the following tones 0 9 are the digits 0 9 10 is 11 is 12 15 are A D whic...

Page 33: ...8333 Page 33 BASIC Stamp II END End program usage END Enter low power mode and keep I O s updated Every 2 3 seconds the I O s will go high z for 18ms Approximately 50 a average cur rent will be consu...

Page 34: ...P is for specifying a step value other than the default of 1 if speci fied stepval must be positive since whether to add or subtract stepval from variable is determined dynamically at run time this al...

Page 35: ...temporarily placed in output mode for modulation Milliseconds specifies how long to output the frequency s Freq1 specifies the first frequency in 1Hz units 0 32768 Hz Freq2 is optional and specifies...

Page 36: ...outine and then RETURN later usage GOSUB ledset The execution point is stored and then a branch to ledset occurs When a RETURN is encountered in ledset execution continues at the in struction followin...

Page 37: ...Stamp II Manual 0 94 Parallax Inc 916 624 8333 Page 37 BASIC Stamp II GOTO Go to a new point in the program usage GOTO joe A branch to joe will occur rather than execution continuing at the next instr...

Page 38: ...e 38 BASIC Stamp II Manual 0 94 Parallax Inc 916 624 8333 BASIC Stamp II HIGH Make a pin an output and have it output 1 usage HIGH pin Pin is 0 15 Make the pin an output and change its output latch to...

Page 39: ...age 39 BASIC Stamp II IF THEN Branch conditionally usage IF conditionalexpression THEN label ie IF x 1 then redoit If the result of conditionalexpression is not 0 execution will be contin ued at label...

Page 40: ...Page 40 BASIC Stamp II Manual 0 94 Parallax Inc 916 624 8333 BASIC Stamp II INPUT Make a pin an input usage INPUTpin Pin is 0 15 Make a pin an input The pin s output latch is unaffected...

Page 41: ...s the default A comparison is made between value andvalue0 if the result is true 0 is written into variable If that comparison was false another comparison is made between value and value1 if the resu...

Page 42: ...Lookup a variable according to an index usage LOOKUP index value0 value1 value2 valueN variable If index 0 then value0 will be written to variable If index 1 then value1 will be written to variable I...

Page 43: ...SIC Stamp II Manual 0 94 Parallax Inc 916 624 8333 Page 43 BASIC Stamp II LOW Make a pin an output and have it output 0 usage LOW pin Pin is 0 15 Make the pin an output and change its output latch to...

Page 44: ...a short period usage NAP x Enter low power mode for a short period When the period is over the I O s will go high z for 18ms and execution will continue at the next instruction The x values for NAP a...

Page 45: ...ASIC Stamp II Manual 0 94 Parallax Inc 916 624 8333 Page 45 BASIC Stamp II OUTPUT Make a pin an output usage OUTPUT pin Pin is 0 15 The pin will be made an output The pin s output latch is not affecte...

Page 46: ...Page 46 BASIC Stamp II Manual 0 94 Parallax Inc 916 624 8333 BASIC Stamp II PAUSE Pause for x milliseconds x 0 to 65535 usage PAUSE x A delay of x milliseconds will occur...

Page 47: ...a timed pulse usage PULSIN pin state variable Pin will be placed in input mode A pulse of state will be awaited and measured with 2 s resolution and the result will be written intovariable If an overf...

Page 48: ...SIC Stamp II PULSOUT Output a timed pulse usage PULSOUT pin period Pin will be made an output opposite of it s OUTx value for period 2 s Pin will be left in output mode with OUTx state Period may be a...

Page 49: ...n 8 bit value 0 255 which specifies the duty cycle Cycles is the number of 256 pin update periods which take 1ms When done pin will be placed in input mode to allow the voltage to remain until another...

Page 50: ...SIC Stamp II Manual 0 94 Parallax Inc 916 624 8333 BASIC Stamp II RANDOM Pseudo randomly iterate a word variable usage RANDOM wordvariable wordvariable will be iterated 16 times to potentially change...

Page 51: ...5V supply towards ground yielding a span of 3 6 volts For example to convert a potentiometer setting to a number Connect the pot as shown below Make the pin high for 1 ms then do RCTIME The resistor...

Page 52: ...e 52 BASIC Stamp II Manual 0 94 Parallax Inc 916 624 8333 BASIC Stamp II READ Read a byte from the EEPROM usage READ location variable Location is 0 2047 Variable will receive the byte read from locat...

Page 53: ...tamp II RETURN Return from a subroutine usage RETURN The execution point is set to the instruction after the GOSUB that got into the subroutine executing the RETURN If a RETURN is executed without a c...

Page 54: ...lax Inc 916 624 8333 BASIC Stamp II REVERSE Reverse a pin s input output direction usage REVERSE pin Pin is 0 15 The pin will be changed from an input to an output or from an output to an input The st...

Page 55: ...or the internal serial port pin 2 RX If a regular I O pin is used then the input will be on a TTL level pin If the RX pin is used then the input will be on a pseudo RS232 pin The difference is this On...

Page 56: ...value which specifies baud rate parity mode and true inverted input Bits 0 12 of baudmode are the serial bit period expressed in micro seconds 20 Bit 13 2000 is 0 for 8 bit no parity 1 for 7 bit pari...

Page 57: ...for bytearray string bytearray is termi nated by 0 WAITSTR bytearray L Wait for bytearray string of length L WAIT value value Wait for up to a six byte sequence DEC variable Input decimal value DEC1...

Page 58: ...value SBIN1 SBIN16 variable Input signed binary value of fixed length IBIN variable Input indicated binary value i e 1101 IBIN1 IBIN16 variable Input indicated binary value of fixed length ISBIN varia...

Page 59: ...utput will be on a pseudo RS232 pin The difference is this On a TTL level pin 0 15 the signals sent are 0 to 5 volts Serial communication with TTL signals should work well for most applications certai...

Page 60: ...utput 3313 2000 300 baud 7 bit parity true data driven output 3313 4000 300 baud 8 bit no parity inverted data driven output 3313 6000 300 baud 7 bit parity inverted data driven output 3313 8000 300 b...

Page 61: ...SIC Stamp II milliseconds and may be up to 65535 approximately 65 seconds A timeout value and label are only applicable if flow control is being used Outputdata follows the DEBUG formatting convention...

Page 62: ...a input Cpin is the clock output Mode is 0 for msb first pre clock 1 for lsb first pre clock 2 for msb first post clock or 3 for lsb first post clock Variable receives the shifted in data Bits is an o...

Page 63: ...s Dpin is the data output Cpin is the clock output Mode is 0 for lsb first or 1 for msb first Data is a value to be shifted out Bits is an optional bit count Values from 1 16 can be given 8 is the def...

Page 64: ...low power mode and keep I O s updated Every 2 3 seconds the I O s will go high z for 18ms Approximately 50 a average cur rent will be consumed When x seconds have been accrued in SLEEP mode execution...

Page 65: ...lax Inc 916 624 8333 Page 65 BASIC Stamp II STOP Stop execution usage STOP Execution is frozen but low power mode is not entered This is like END except that the I O s never go high z they remain driv...

Page 66: ...Inc 916 624 8333 BASIC Stamp II TOGGLE Make a pin an output and toggle its output state usage TOGGLE pin Pin is 0 15 The pin will be made an output and its output state 0 or 1 will be toggled output o...

Page 67: ...SIC Stamp II Manual 0 94 Parallax Inc 916 624 8333 Page 67 BASIC Stamp II WRITE Write a byte into the EEPROM usage WRITE location byte Location is 0 2047 Byte is 0 255 Byte will be written into locati...

Page 68: ...ommand is a key 0 15 is 1 16 or command see table below Cycles is an optional number which overrides the default of two this should only be used with dim and bright commands X 10 Command symbol Value...

Reviews: