BASIC Stamp II The following section deals with the BASIC Stamp II. In the following pages, you’ll find installation instructions, programming procedures, PBASIC2 command definitions, and several application notes. 2 Parallax, Inc. • BASIC Stamp Programming Manual 1.
BASIC Stamp II System Requirements To program the BASIC Stamp II, you’ll need the following computer system: • IBM PC or compatible computer • 3.5-inch disk drive • Serial port • 128K of RAM • MS-DOS 2.0 or greater If you have the BASIC Stamp II carrier board, you can use a 9-volt battery as a convenient means to power the BASIC Stamp. You can also use a 5-15 (5-40 volts on BS2-IC rev. d) volt power supply, but you should be careful to connect the supply to the appropriate part of the BASIC Stamp.
BASIC Stamp II Connecting to the PC To program a BASIC Stamp II, you’ll need to connect it to your PC and then run the editor software. In this section, it’s assumed that you have a BS2-IC and its corresponding carrier board (shown below). To connect the BASIC Stamp II to your PC, follow these steps: 1) Plug the BS2-IC onto the carrier board. The BS2-IC plugs into a 24-pin DIP socket, located in the center of the carrier.
BASIC Stamp II Pin TX 1 24 PWR RX 2 23 GND ATN 3 22 RES GND 4 21 +5V P0 5 20 P15 P1 6 19 P14 P2 7 18 P13 P3 8 17 P12 P4 9 16 P11 P5 10 15 P10 P6 11 14 P9 P7 12 13 P8 Name Description Comments 1 2 3 4 TX RX ATN GND Serial output Serial input Active-high reset Serial ground Connect to pin 2 of PC serial DB9 (RX) * Connect to pin 3 of PC serial DB9 (TX) * Connect to pin 4 of PC serial DB9 (DTR) * Connect to pin 5 of PC serial DB9 (GND) * 5 6 7 8 9 10 11
BASIC Stamp II Starting the Editor With the BASIC Stamp II connected and powered, insert the BASIC Stamp diskette and then enter the BASIC Stamp II directory by typing the following command from the DOS prompt: CD STAMP2 Once in the BASIC Stamp II directory, you can run the BASIC Stamp II editor/downloader software by typing the following command: STAMP2 The software will start running after several seconds.
BASIC Stamp II Entering & Editing Programs We’ve tried to make the editor as intuitive as possible: to move up, press the up arrow; to highlight one character to the right, press shiftright arrow; etc. Most functions of the editor are easy to use. Using single keystrokes, you can perform the following common functions: • Load, save, and run programs. • Move the cursor in increments of one character, one word, one line, one screen, or to the beginning or end of a file.
BASIC Stamp II Left arrow Right arrow Move left one character Move right one character Up arrow Down arrow Ctrl-Left Ctrl-Right Move up one line Move down one line Move left to next word Move right to next word Home End Page Up Page Down Ctrl-Page Up Ctrl-Page Down Move to beginning of line Move to end of line Move up one screen Move down one screen Move to beginning of file Move to end of file Shift-Left Shift-Right Shift-Up Shift-Down Shift-Ctrl-Left Shift-Ctrl-Right Highlight one character to the
BASIC Stamp II The following list is a summary of the PBASIC instructions used by the BASIC Stamp II. ◆ This symbol indicates new or greatly improved instructions (compared to the BASIC 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. GOSUBs may be nested up to four levels deep, and you may have up to 255 GOSUBs in your program. RETURN Return from subroutine. LOOPING FOR...
BASIC Stamp II PULSOUT Output a timed pulse by inverting a pin for some time (resolution of 2 µs). 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.
BASIC Stamp II 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 PBASIC 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.
BASIC Stamp II BS2 Hardware Figure H-1 is a schematic diagram of the BASIC Stamp II (BS2). In this section we’ll describe each of the major components and explain its function in the circuit. Figure H-1 Schematic Stamp IIII(BS2-IC (BS2-ICrevA) rev. A) SchematicDiagram Diagram of of the the BASIC BASIC Stamp +5V (24) U4 BS2 components 5V Reg.
BASIC Stamp II PBASIC2 Interpreter Chip (U1) The brain of the BS2 is a custom PIC16C57 microcontroller (U1). U1 is permanently programmed with the PBASIC2 instruction set. When you program the BS2, you are telling U1 to store symbols, called tokens, in EEPROM memory (U2). When your program runs, U1 retrieves tokens from memory (U2), interprets them as PBASIC2 instructions, and carries out those instructions. U1 executes its internal program at 5 million instructions per second.
BASIC Stamp II When a pin is an output, it is internally connected to ground or +5V through a very efficient CMOS switch. If it is lightly loaded (< 1mA), the output voltage will be within a few millivolts of the power supply rail (ground for 0; +5V for 1). Pins can sink as much as 25mA (outputting 0) and source up to 20 mA (outputting 1). Each of the two eightpin ports should not carry more than a total of 50mA (sink) or 40mA (source). Pins P0 through P7 make up one port; P8 through P15 the other.
BASIC Stamp II When the supply voltage is above 4V, U3 allows its output to be pulled high by a 4.7k resistor to +5V, which also puts a high on U1’s MCLR input. U1 starts its internal program at the beginning, which in turn starts your PBASIC2 program from the beginning. Power Supply (U4) The previous discussion of the reset circuit should give you some idea of how important a stable power supply is to correct operation of the BS2.
BASIC Stamp II leaves its output in the 1 state (-12V). To begin a transmission, it outputs a 0 (+12V) for one bit time (the baud rate divided into 1 second; e.g., bit time for 2400 baud = 1/2400 = 416.6µs). You can see how the BS2 takes advantage of these characteristics in the design of its serial interface. NPN transistor Q1 serves as a serial line receiver. When SIN is negative, Q1 is switched off, so the 4.7k resistor on its collector puts a high on pin RA2 of U1, the PBASIC2 interpreter chip.
BASIC Stamp II PC-to-BS2 Connector Hookup Figure H-2 shows how a DB9 programming connector for the BS2 is wired. This connector allows the PC to reset the BS2 for programming, download programs, and receive Debug data from the BS2. An additional pair of connections, pins 6 and 7 of the DB9 socket, lets the STAMP2 host software identify the port to which the BS2 is connected.
BASIC Stamp II BS2 Memory Organization The BS2 has two kinds of memory; RAM for variables used by your program, and EEPROM for storing the program itself. EEPROM may also be used to store long-term data in much the same way that desktop computers use a hard drive to hold both programs and files. An important distinction between RAM and EEPROM is this: • RAM loses its contents when the BS2 loses power; when power returns, all RAM locations are cleared to 0s.
BASIC Stamp II Table M-1. BS2 Memory Map Stamp II I/O and Variable Space Word Name INS OUTS DIRS W0 W1 W2 W3 W4 W5 W6 W7 W8 W9 W10 W11 W12 Byte Name INL INH OUTL OUTH DIRL DIRH Nibble Names INA, INB, INC, IND OUTA, OUTB, OUTC, OUTD DIRA, DIRB, DIRC, DIRD B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11 B12 B13 B14 B15 B16 B17 B18 B19 B20 B21 B22 B23 B24 B25 Bit Names IN0 - IN7, IN8 - IN15 OUT0 - OUT7, OUT8 - OUT15 DIR0 - DIR7, DIR8 - DIR15 Special Notes Input pins; word, byte, nibble and bit addressable.
BASIC Stamp II tains the states of the 16 output latches. DIRS controls the direction (input or output) of each of the 16 pins. If you are new to devices that can change individual pins between input and output, the INS/OUTS/DIRS trio may be a little confusing, so we’ll walk through the possibilities. A 0 in a particular DIRS bit makes the corresponding pin, P0 through P15, an input. So if bit 5 of DIRS is 0, then P5 is an input.
BASIC Stamp II Figure M-1. Interaction of DIRS, INS and OUTS The DIRS register controls which I/O pins are inputs and which are outputs. When set to input (0), the corresponding bit in the OUTS register is disconnected and ignored. When set to output (1), the corresponding bit in the OUTS register is connected. NOTE: “X” indicates state could be a 1 or a 0 and does not affect other elements. “?” indicates state is unknown and could change erratically.
BASIC Stamp II Using the names listed above, you can access any piece of any I/O variables. And as we’ll see in the next section, you can use modifiers to access any piece of any variable. Predefined “Fixed” Variables As table M-1 shows, the BS2’s memory is organized into 16 words of 16 bits each. The first three words are used for I/O. The remaining 13 words are available for use as general purpose variables.
BASIC Stamp II does have predefined variables that you can use without declaring them first (see previous section), the preferred way to set up variables is to use the directive VAR. The syntax for VAR is: symbol VAR size where: • Symbol is the name by which you will refer to the variable. Names must start with a letter, can contain a mixture of letters, numbers, and underscore (_) characters, and must not be the same as PBASIC keywords or labels used in your program.
BASIC Stamp II If you assign a value to a variable that exceeds its size, the excess bits will be lost. For example, suppose you use the nibble variable cat from the example above and write cat = 91 (%1011011 binary), what will cat contain? It will hold only the lowest 4 bits of 91—%1011 (11 decimal). You can also define multipart variables called arrays. An array is a group of variables of the same size, and sharing a single name, but broken up into numbered cells.
BASIC Stamp II A word of caution about arrays: If you’re familiar with other BASICs and have used their arrays, you have probably run into the “subscript out of range” error. Subscript is another term for the index value. It’s ‘out of range’ when it exceeds the maximum value for the size of the array. For instance, in the example above, myBytes is a 10-cell array. Allowable index numbers are 0 through 9. If your program exceeds this range, PBASIC2 will not respond with an error message.
BASIC Stamp II ‘ Example 2 (null-terminated string): myText var byte(10) ‘ An array to hold the string. myText(0) = “H”:myText(1) = “E” myText(2) = “L”:myText(3) = “L” myText(4) = “0”:myText(5) = 0 ‘ Store “HELLO” in first 5 cells... ‘ Put null (0) after last character. debug str myText ‘ Show “HELLO” on the PC screen. (*Note to experienced programmers: Counted strings normally store the count value in their 0th cell. This kind of string won’t work with the STR prefix of Debug and Serout.
BASIC Stamp II Table M-3 lists all the variable modifiers. PBASIC2 lets you apply these modifiers to any variable name, including fixed variables and I/O variables, and to combine them in any fashion that makes sense. For example, it will allow: rhino eye var var word rhino.highbyte.lownib.bit1 ‘ A 16-bit variable. ‘ A bit. Table M-3.
BASIC Stamp II The commonsense rule for combining modifiers is that they must get progressively smaller from left to right. It would make no sense to specify, for instance, the low byte of a nibble, because a nibble is smaller than a byte! And just because you can stack up modifiers doesn’t mean that you should unless it is the clearest way to express the location of the part you want get at. The example above might be improved: rhino eye var var word rhino.bit9 ‘ A 16-bit variable. ‘ A bit.
BASIC Stamp II What if you use something other than a “low” modifier, say myBytes.highnib()? That will work, but its only effect will be to start the nibble array with the high nibble of myBytes(0). The nibbles you address with this nib array will all be contiguous—one right after the other—as in the previous example. myBytes var byte(10) myBytes(0) = $AB myBytes(1) = $CD debug hex ? myBytes.highnib(0) debug hex ? myBytes.highnib(1) ‘ Define 10-byte array.
BASIC Stamp II (1) It does not correlate the names of your variables to their locations. The Stamp software arranges variables in descending order of size, starting with words and working downward to bits. But there’s no way to tell from the memory map exactly which variable is located where. (2) Fixed variables like B3 and W1 and any aliases you give them do not show up on the memory map as memory used. The Stamp software ignores fixed variables when it arranges automatically allocated variables in memory.
BASIC Stamp II For example: 99 %1010 $FE “A” decimal binary hex ASCII code for A (65) You can assign names to constants using the CON directive. Once created, named constants may be used in place of the numbers they represent. For example: cheers con 3 ‘ Number of cheers. FOR count = 1 to cheers GOSUB makeCheers NEXT ... That code would work exactly the same as the previous FOR/NEXT loops. The Stamp host software would substitute the number 3 for the constant name cheers throughout your program.
BASIC Stamp II Now, assuming that you used the constant cheers wherever your program needed ‘the number of cheers,’ your upgrade would be complete. You can take this idea a step further by defining constants with expressions—groups of math and/or logic operations that the Stamp host software solves (evaluates) at compile time (the time right after you press ALT-R and before the BS2 starts running your program). For example, suppose the “Cheers” program also controls a pump to fill glasses with champagne.
BASIC Stamp II BS2 EEPROM Data Storage When you press ALT-R (run), your program is loaded into the BS2’s EEPROM starting at the highest address (2047) and working downward. Most programs don’t use the entire EEPROM, so PBASIC2 lets you store data in the unused lower portion of the EEPROM. Since programs are stored from the top of memory downward, your data is stored in the bottom of memory working upward. If there’s an overlap, the Stamp host software will detect it and display an error message.
BASIC Stamp II The first Data directive will start at 0 and increment the pointer: 1, 2, 3, 4, 5. The second Data directive will pick up the pointer value of 5 and work upward from there. As a result, the first 10 bytes of EEPROM will contain: Address: 0 Contents: 72 1 69 2 76 3 76 4 79 5 104 6 101 7 108 8 108 9 111 ...and the constants table1 and table2 will be equal to 0 and 5, respectively. A common use for Data is to store strings; sequences of bytes representing text.
BASIC Stamp II table1 table2 data data 13,26,117,0,19,56 (20) ‘ Place bytes into EEPROM. ‘ Move pointer ahead by 20. The value in parentheses tells Data to move its pointer, but not to store anything in those bytes. The bytes at the addresses starting at table2 could therefore contain leftover data from previous programs. If that’s not acceptable, you can tell Data to fill those bytes up with a particular value: table2 data 0(20) ‘ Fill 20 bytes with 0s.
BASIC Stamp II BS2 Runtime Math and Logic The BS2, like any computer, excels at math and logic. However, being designed for control applications, the BS2 does math a little differently than a calculator or spreadsheet program. This section will help you understand BS2 numbers, math, and logic. Number Representations In your programs, you may express a number in various ways, depending on how the number will be used and what makes sense to you.
BASIC Stamp II After the download is complete and the BS2 starts executing your program—this is referred to as “runtime.” At runtime the BS2 processes math and logic operations involving variables, or any combination of variables and constants. Because compile-time and runtime expressions appear similar, it can be hard to tell them apart.
BASIC Stamp II The BS2 solves math problems in the order they are written—from left to right. The result of each operation is fed into the next operation. So to compute 12+3*2/4, the BS2 goes through a sequence like this: 12 + 3 = 5 5 * 2 = 10 10 / 4 = 2 the answer is 2 Note that because the BS2 performs integer math (whole numbers only) that 10 / 4 results in 2, not 2.5. We’ll talk more about integers in the next section.
BASIC Stamp II Integer Math The BS2 performs all math operations by the rules of positive integer math. That is, it handles only whole numbers, and drops any fractional portions from the results of computations. Although the BS2 can interpret two’s complement negative numbers correctly in Debug and Serout instructions using modifiers like SDEC (for signed decimal), in calculations it assumes that all values are positive.
BASIC Stamp II 16-bit Workspace Most of the descriptions that follow say something like ‘computes (some function) of a 16-bit value.’ This does not mean that the operator does not work on smaller byte or nibble values. It just means that the computation is done in a 16-bit workspace. If the value is smaller than 16 bits, the BS2 pads it with leading 0s to make a 16-bit value. If the 16-bit result of a calculation is to be packed into a smaller variable, the higherorder bits are discarded (truncated).
BASIC Stamp II Unary (one-argument) Operators Six Unary Operators are listed and explained below. Table M-5. Unary Operators Operator Description ABS Returns absolute value SQR Returns square root of value DCD 2n-power decoder NCD Priority encoder of a 16-bit value SIN Returns two’s compliment sine COS Returns two’s compliment cosine ABS Converts a signed (two’s complement) 16-bit number to its absolute value.
BASIC Stamp II debug SQR 100 debug SQR 99 ' Display square root of 100 (10). ' Display of square root of 99 (9 due to truncation) DCD 2n-power decoder of a four-bit value. DCD accepts a value from 0 to 15, and returns a 16-bit number with that bit number set to 1. For example: w1 = DCD 12 debug bin ? w1 ' Set bit 12. ' Display result (%0001000000000000) NCD Priority encoder of a 16-bit value.
BASIC Stamp II SIN Returns the two’s complement, 8-bit sine of an angle specified as an 8bit (0 to 255) angle. To understand the BS2 SIN operator more completely, let’s look at a typical sine function. By definition: given a circle with a radius of 1 unit (known as a unit circle), the sine is the y-coordinate distance from the center of the circle to its edge at a given angle. Angles are measured relative to the 3-o'clock position on the circle, increasing as you go around the circle counterclockwise.
BASIC Stamp II Binary (two-argument) Operators Sixteen Binary Operators are listed and explaned below. Table M-6.
BASIC Stamp II w1 = -1575 w2 = 976 w1 = w1 + w2 debug sdec ? w1 ' Add the numbers. ' Show the result (-599). Subtracts variables and/or constants, returning a 16-bit result. Works exactly as you would expect with unsigned integers from 0 to 65535. If the result is negative, it will be correctly expressed as a signed 16-bit number. For example: w1 = 1000 w2 = 1999 w1 = w1 - w2 debug sdec ? w1 ' Subtract the numbers. ' Show the result (-999).
BASIC Stamp II // Returns the remainder left after dividing one value by another. Some division problems don’t have a whole-number result; they return a whole number and a fraction. For example, 1000/6 = 166.667. Integer math doesn’t allow the fractional portion of the result, so 1000/6 = 166. However, 166 is an approximate answer, because 166*6 = 996. The division operation left a remainder of 4. The // (double-slash) returns the remainder of a given division operation.
BASIC Stamp II w1 = $FDE8 w2 = w1 ** w1 debug hex ? w2 ' Multiply $FDE8 by itself ' Return high 16 bits. */ Multiplies variables and/or constants, returning the middle 16 bits of the 32-bit result. This has the effect of multiplying a value by a whole number and a fraction. The whole number is the upper byte of the multiplier (0 to 255 whole units) and the fraction is the lower byte of the multiplier (0 to 255 units of 1/256 each).
BASIC Stamp II Its logic is, ‘if value is less than limit, then make value = limit; if value is greater than or equal to limit, leave value alone.’ MIN works in positive math only; its comparisons are not valid when used on two’s complement negative numbers, since the positive-integer representation of a number like -1 ($FFFF or 65535 in unsigned decimal) is larger than that of a number like 10 ($000A or 10 decimal). Use MIN only with unsigned integers.
BASIC Stamp II DIG Returns the specified decimal digit of a 16-bit positive value. Digits are numbered from 0 (the rightmost digit) to 4 (the leftmost digit of a 16bit number; 0 to 65535). Example: w1 = 9742 debug ? w1 DIG 2 for b0 = 0 to 4 debug ? w1 DIG b0 next ' Show digit 2 (7) ' Show digits 0 through 4 of 9742. << Shifts the bits of a value to the left a specified number of places. Bits shifted off the left end of a number are lost; bits shifted into the right end of the number are 0s.
BASIC Stamp II REV Returns a reversed (mirrored) copy of a specified number of bits of a value, starting with the rightmost bit (lsb). For instance, %10101101 REV 4 would return %1011, a mirror image of the first four bits of the value. Example: debug bin ? %11001011 REV 4 ' Mirror 1st 4 bits (%1101) & Returns the bitwise AND of two values.
BASIC Stamp II ^ Returns the bitwise XOR of two values. Each bit of the values is subject to the following logic: 0 XOR 0 = 0 0 XOR 1 = 1 1 XOR 0 = 1 1 XOR 1 = 0 The result returned by ^ will contain 1s in any bit positions in which one or the other (but not both) input values contain 1s. Example: debug bin ? %00001111 ^ %10101001 ' Show XOR result (%10100110) Page 246 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
BASIC Stamp II Branch BRANCH offset, [address0, address1, ...addressN] Go to the address specified by offset (if in range). • Offset is a variable/constant that specifies which of the listed address to go to (0—N). • Addresses are labels that specify where to go.
BASIC Stamp II goto nextPick two: debug "Branched to 'two.'",cr,cr goto nextPick Page 248 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
BASIC Stamp II Button BUTTON pin, downstate, delay, rate, bytevariable, targetstate, address Debounce button input, perform auto-repeat, and branch to address if button is in target state. Button circuits may be active-low or activehigh. • Pin is a variable/constant (0–15) that specifies the I/O pin to use. This pin will be made an input. • Downstate is a variable/constant (0 or 1) that specifies which logical state occurs when the button is pressed.
BASIC Stamp II immediately appears on the screen. If you hold the key down, there’s a delay, then a rapid-fire stream of characters appears on the screen. Button’s auto-repeat function can be set up to work much the same way. Button is designed to be used inside a program loop. Each time through the loop, Button checks the state of the specified pin. When it first matches downstate, Button debounces the switch.
BASIC Stamp II Count COUNT pin, period, variable Count the number of cycles (0-1-0 or 1-0-1) on the specified pin during period number of milliseconds and store that number in variable. • Pin is a variable/constant (0–15) that specifies the I/O pin to use. This pin will be placed into input mode by writing a 0 to the corresponding bit of the DIRS register. • Period is a variable/constant (1 to 65535) specifying the time in milliseconds during which to count.
BASIC Stamp II cycles var word ' Variable to store counted cycles. loop: debug cls,"How many times can you press the button in 1 second?",cr pause 1000: debug "Ready, set... ":pause 500:debug "GO!",cr count 7,1000,cycles debug cr,"Your score: ", DEC cycles,cr pause 3000 debug "Press button to go again." hold: if IN7 = 1 then hold goto loop Page 252 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
BASIC Stamp II Debug DEBUG outputData{,outputData...} Display variables and messages on the PC screen within the STAMP2 host program. • OutputData consists of one or more of the following: text strings, variables, constants, expressions, formatting modifiers, and control characters Explanation Debug provides a convenient way for your programs to send messages to the PC screen during programming.
BASIC Stamp II x var DEBUG dec ? 2*(x-1) byte: x = 65 ' Show decimal result with "2*(x-1) = " The Debug window would display "2*(x-1) = 128." If you omit the ?, the display would be just “128.” If you tell Debug to display a value without formatting it as a number, you get the ASCII character equivalent of the value: x var byte: x = 65 DEBUG x ' Show x as ASCII. Since x = 65, and 65 is the ASCII character code for the letter A (see appendix), the Debug window would show A.
BASIC Stamp II carrier board or the serial cable to temporarily disconnect pin 3 of the BS2-IC (pin 4 of the DB-9 connector). The reason is that the STAMP2 host software uses this line to reset the BS2 for programming, while terminal software uses the same line to signal “ready” for serial communication. If you make this modification, be sure to provide a way to reconnect pin 3 of the BS2-IC to pin 4 of the DB-9 connector for reprogramming.
BASIC Stamp II Table I-1. Debug Modifiers Modifier ASC? DEC {1..5} SDEC {1..5} HEX {1..4} SHEX {1..4} IHEX {1..4} ISHEX {1..4} BIN {1..16} SBIN {1..16} IBIN {1..16} ISBIN {1..16} STR bytearray STR bytearray\n REP byte\n Effect Displays "variablename = 'character'" + carriage return; where character is an ASCII character.
BASIC Stamp II DTMFout DTMFOUT pin,{ontime,offtime,}{,tone...} Generate dual-tone, multifrequency tones (DTMF, i.e., telephone “touch” tones). • Pin is a variable/constant (0–15) that specifies the I/O pin to use. This pin will be put into output mode temporarily during generation of tones. After tone generation is complete, the pin is left in input mode, even if it was previously an output. • Ontime is an optional entry; a variable or constant (0 to 65535) specifying a duration of the tone in milliseconds.
BASIC Stamp II a noisy phone line or radio link, you could use the optional ontime and offtime values: DTMFOUT 0,500,100,[6,2,4,8,3,3,3] ' Call Parallax, slowly. In that instruction, ontime is set to 500 ms (1/2 second) and offtime to 100 ms (1/10th second). Technical Background The BS2’s controller is a purely digital device. DTMF tones are analog waveforms, consisting of a mixture of two sine waves at different audio frequencies.
BASIC Stamp II Figure I-3 Interfacing to the Telephone Line connect switch (or relay contacts) phone line (red and green) 600-600Ω transformer (JC: 117760) 10Ω (both) 270V “Sidactor” (DK: P3000AA61-ND) 1k 0.1µF I/O pin 0.001µF 3.9V zeners (both) DK: 1N5228BCT-ND Parts Sources Digi-Key (DK), 1-800-344-4539 or 218-681-6674 Jameco (JC), 1-800-831-4242 or 415-592-8097 digits fit within a nibble (four bits), the program below packs two DTMF digits into each byte of three EEPROM data tables.
BASIC Stamp II End END End the program, placing the BS2 in a low-power mode. Explanation End puts the BS2 into its inactive, low-power mode. In this mode the BS2’s current draw (exclusive of loads driven by the I/O pins) is approximately 50µA. End keeps the BS2 inactive until the reset button is pushed or the power is cycled off and back on. Just as during Sleep intervals, pins will retain their input or output settings after the BS2 is deactivated by End.
BASIC Stamp II For...Next FOR variable = start to end {STEP stepVal} ... NEXT Create a repeating loop that executes the program lines between For and Next, incrementing or decrementing variable according to stepVal until the value of the variable passes the end value. • Variable is a bit, nib, byte or word variable used as a counter. • Start is a variable or constant that specifies the initial value of the variable. • End is a variable or constant that specifies the end value of the variable.
BASIC Stamp II If you want For...Next to count by some amount other than 1, you can specify a stepVal. For example, change the previous example to count down by 3: reps var nib FOR reps = 10 to 1 STEP 3 debug dec ? reps NEXT ' Counter for the FOR/NEXT loop. ' Repeat with reps = 10, 7...1. ' Each rep, show values of reps. Note that even though you are counting down, stepVal is still positive. For...Next takes its cue from the relationship between start and end, not the sign of stepVal.
BASIC Stamp II capacity of a 16-bit number. When the value rolls over to 464, it passes the test “Is w1 > 65500?” used by Next to determine when to end the loop. Demo Program Here’s an example that uses a For...Next loop to churn out a series of sequential squares (numbers 1, 2, 3, 4... raised to the second power) by using a variable to set the For...Next stepVal, and incrementing stepVal within the loop. Sir Isaac Newton is generally credited with the discovery of this technique. square stepSize loop.
BASIC Stamp II Freqout FREQOUT pin, duration, freq1{,freq2} Generate one or two sine-wave tones for a specified duration. • Pin is a variable/constant (0–15) that specifies the I/O pin to use. This pin will be put into output mode during generation of tones and left in that state after the instruction finishes. • Duration is a variable/constant specifying the length in milliseconds (1 to 65535) of the tone(s). • Freq1 is a variable/constant specifying frequency in hertz (Hz, 0 to 32767) of the first tone.
BASIC Stamp II Figure I-4 Driving an Audio Amplifier 1k 1k I/O pin 0.1µF 0.01µF Amplifier (e.g., Radio Shack 277-1008C) Driving a Speaker 10µF (both) I/O pin + C1 + C2 ≥40Ω Speaker (or 8Ω in series with 33Ω resistor) Notes: C1 may be omitted for piezo speakers C2 is optional, but reduces high-frequency noise the first frequency is the musical note itself, while the second is 8 Hz lower. When sines mix, sum and difference frequencies are generated.
BASIC Stamp II Gosub GOSUB addressLabel Store the address of the next instruction after Gosub, then go to the point in the program specified by addressLabel. • AddressLabel is a label that specifies where to go. Explanation Gosub is a close relative of Goto. After Gosub, the program executes code beginning at the specified address label. (See the entry on Goto for more information on assigning address labels) Unlike Goto, Gosub also stores the address of the instruction immediately following itself.
BASIC Stamp II Demo Program This program is a guessing game that generates a random number in a subroutine called pickAnumber. It is written to stop after three guesses. To see a common bug associated with Gosub, delete or comment out the line beginning with Stop after the For/Next loop. This means that after the loop is finished, the program will wander into the pickAnumber subroutine.
BASIC Stamp II Goto GOTO addressLabel Go to the point in the program specified by addressLabel. • AddressLabel is a label that specifies where to go. Explanation Programs execute from the top of the page (or screen) toward the bottom, and from left to right on individual lines; just the same way we read and write English. Goto is one of the instructions that can change the order in which a program executes by forcing it to go to a labeled point in the program.
BASIC Stamp II High HIGH pin Make the specified pin output high (write 1s to the corresponding bits of both DIRS and OUTS). • Pin is a variable/constant (0–15) that specifies the I/O pin to use. Explanation In order for the BS2 to actively output a 1 (a +5-volt level) on one of its pins, two conditions must be satisfied: (1) The corresponding bit of the DIRS variable must contain a 1 in order to connect the pin’s output driver. (2) The corresponding bit of the OUTS variable must contain a 1.
BASIC Stamp II If...Then IF condition THEN addressLabel Evaluate condition and, if true, go to the point in the program marked by addressLabel. • Condition is a statement, such as “x = 7” that can be evaluated as true or false. • AddressLabel is a label that specifies where to go in the event that the condition is true. Explanation If...Then is PBASIC’s decision maker. It tests a condition and, if that condition is true, goes to a point in the program specified by an address label. The condition that If...
BASIC Stamp II redirected the program to the label after Then, “isLess.” If you change “aNumber = 99” to “aNumber = 100” the other message, “greater than or equal to 100,” will appear instead. The condition “aNumber < 100” is false if aNumber contains 100 or more. The values compared in the If...
BASIC Stamp II false. The following If...Thens are equivalent: IF x <> 100 THEN notEqual IF NOT x=100 THEN notEqual ' Goto notEqual if x is not 100. ' Goto notEqual if x is not 100. The operators AND, OR, and XOR join the results of two conditions to produce a single true/false result. AND and OR work the same as they do in everyday speech. Run the example below once with AND (as shown) and again, substituting OR for AND: b1 = 5 b2 = 9 IF b1 = 5 AND b2 = 10 THEN True debug "Statement was not true.
BASIC Stamp II Table I-2. Effects of the Logical Operators Used by If...Then Condition A false true NOT A true false Condition A false false true true Condition B false true false true A AND B false false false true Condition A false false true true Condition B false true false true A OR B false true true true Condition A false false true true Condition B false true false true A XOR B false true true false Unlike some versions of the If...Then instruction, PBASIC’s If...
BASIC Stamp II Internal Workings and Potential Bugs Internally, the BS2 defines “false” as 0 and “true” as any value other than 0. Consider the following instructions: flag flag = 1 var bit IF flag THEN isTrue debug "false" stop isTrue: debug "true" stop Since flag is 1, If...Then would evaluate it as true and print the message “true” on the screen. Suppose you changed the If...Then instruction to read “IF NOT flag THEN isTrue.” That would also evaluate as true.
BASIC Stamp II divisible by another if the remainder from division, determined by the // operator, is 0.) If a number is divisible by 3, then it is printed, otherwise, the program generates another random number. The program counts how many numbers it prints, and quits when this number reaches 10. sample var word samps var nib mul3: random sample IF NOT sample//3 = 0 THEN mul3 debug dec sample," is divisible by 3.",cr samps = samps + 1 IF samps = 10 THEN done goto mul3 ' Random number to be tested.
BASIC Stamp II Input INPUT pin Make the specified pin an input (write a 0 to the corresponding bit of DIRS). • Pin is a variable/constant (0–15) that specifies the I/O pin to use. Explanation There are several ways to make a pin an input. When a program begins, all of the BS2’s pins are inputs. Input instructions (Pulsin, Serin) automatically change the specified pin to input and leave it in that state. Writing 0s to particular bits of the variable DIRS makes the corresponding pins inputs.
BASIC Stamp II state by writing a low (0) to bit 7 of OUTS and changing the pin to output. INPUT 7 debug "State of pin 7: ", bin IN7,cr OUT7 = 0 debug "After 0 written to OUT7: ",bin IN7,cr output 7 debug "After pin 7 changed to output: ",bin IN7 ' Make pin 7 an input. ' Write 0 to output latch. ' Make pin 7 an output. 2 Parallax, Inc. • BASIC Stamp Programming Manual 1.
BASIC Stamp II Lookdown LOOKDOWN value,{comparisonOp,}[value0, value1,...valueN],resultVariable Compare a value to a list of values according to the relationship specified by the comparison operator. Store the index number of the first value that makes the comparison true into resultVariable. If no value in the list makes the comparison true, resultVariable is unaffected. • Value is a variable or constant to be compared to the values in the list.
BASIC Stamp II Debug prints, “Value matches item 5 in list” because the value (17) matches item 5 of [26,177,13,1,0,17,99]. Note that index numbers count up from 0, not 1; that is in the list [26,177,13,1,0,17,99], 26 is item 0. What happens if the value doesn’t match any of the items in the list? Try changing “value = 17” to “value = 2.” Since 2 is not on the list, Lookdown does nothing. Since result contained 15 before Lookdown executed, Debug prints “Value matches item 15 in list.
BASIC Stamp II Lookdown with Variables and Comparison Operators The examples above show Lookdown working with lists of constants, but it also works with variables.
BASIC Stamp II Demo Program This program uses Lookdown to determine the number of decimal digits in a number. The reasoning is that numbers less than 10 have one digit; greater than or equal to 10 but less than 100 have two; greater than or equal to 100 but less than 1000 have three; greater than or equal to 1000 but less than 10000 have four; and greater than or equal to 10000 but less than 65535 (the largest number we can represent in 16bit math) have five.
BASIC Stamp II Lookup LOOKUP index, [value0, value1,...valueN], resultVariable Look up the value specified by the index and store it in a variable. If the index exceeds the highest index value of the items in the list, variable is unaffected. • Index is the item number (constant or variable) of the value to be retrieved from the list of values. • Value0, value1... make up a list of values (constants or variables) up to 16 bits in size.
BASIC Stamp II i frame var var nib byte rotate: for i = 0 to 3 LOOKUP i,["|/-\"],frame debug cls,frame pause 50 next goto rotate 2 Parallax, Inc. • BASIC Stamp Programming Manual 1.
BASIC Stamp II Low LOW pin Make the specified pin output low (write 1 to the corresponding bit of DIRS and 0 to the corresponding bit of OUTS). • Pin is a variable/constant (0–15) that specifies the I/O pin to use. Explanation In order for the BS2 to actively output a 0 (a 0-volt level) on one of its pins, two conditions must be satisfied: (1) The corresponding bit of the DIRS variable must contain a 1 in order to connect the pin’s output driver.
BASIC Stamp II Nap NAP period Enter sleep mode for a short period. Power consumption is reduced to about 50 µA assuming no loads are being driven. • Period is a variable/constant that determines the duration of the reduced power nap. The duration is (2^period) * 18 ms. (Read that as “2 raised to the power period, times 18 ms.”) Period can range from 0 to 7, resulting in the following nap lengths: Period 0 1 2 3 4 5 6 7 2period 1 2 4 8 16 32 64 128 Length of Nap 18.ms 36.ms 72.ms 144.ms 288.ms 576.ms 1152.
BASIC Stamp II I/O direction dictated by your program. If you plan to use End, Nap, or Sleep in your programs, make sure that your loads can tolerate these power outages. The simplest solution is often to connect resistors high or low (to +5V or ground) as appropriate to ensure a continuing supply of current during the reset glitch. The demo program can be used to demonstrate the effects of the Nap glitch with an LED and resistor as shown in figure I-7.
BASIC Stamp II Output OUTPUT pin Make the specified pin an output (write a 1 to the corresponding bit of DIRS). • Pin is a variable/constant (0–15) that specifies the I/O pin to use. Explanation There are several ways to make a pin an output. When a program begins, all of the BS2’s pins are inputs. Output instructions (Pulsout, High, Low, Serout, etc.) automatically change the specified pin to output and leave it in that state.
BASIC Stamp II Pause PAUSE milliseconds Pause the program (do nothing) for the specified number of milliseconds. • Milliseconds is a variable/constant specifying the length of the pause in ms. Pauses may be up to 65535 ms (65+ seconds) long. Explanation Pause delays the execution of the next program instruction for the specified number of milliseconds. For example: flash: low 0 PAUSE 100 high 0 PAUSE 100 goto flash This code causes pin 0 to go low for 100 ms, then high for 100 ms.
BASIC Stamp II Pulsin PULSIN pin, state, resultVariable Measure the width of a pulse in 2µs units. • Pin is a variable/constant (0–15) that specifies the I/O pin to use. This pin will be placed into input mode during pulse measurement and left in that state after the instruction finishes. • State is a variable or constant (0 or 1) that specifies whether the pulse to be measured begins with a 0-to-1 transition (1) or a 1-to0 transition (0).
BASIC Stamp II Figure I-8 shows how the state bit controls triggering of Pulsin. Figure I-8 PULSIN pin,0,variable PULSIN pin,1,variable triggered by 1-to-0 triggered by 0-to-1 stopped by 0-to-1 stopped by 1-to-0 measured in 2µs units and stored in variable measured in 2µs units and stored in variable Demo Program This program uses Pulsin to measure a pulse generated by discharging a 0.1µF capacitor through a 1k resistor as shown in figure I-9.
BASIC Stamp II Pulsout PULSOUT pin, time Output a pulse of 2µs to 131 ms in duration. • Pin is a variable/constant (0-15) that specifies the I/O pin to use. This pin will be placed into output mode immediately before the pulse and left in that state after the instruction finishes. • Time is a variable/constant (0-65535) that specifies the duration of the pulse in 2µs units. Explanation Pulsout combines several actions into a single instruction.
BASIC Stamp II both functions are rolled into the pin variables, such as “pin7.” So in the situation outlined above and shown in figure I-10, the BS1 would produce a single negative pulse and leave the pin output high when done.
BASIC Stamp II PWM PWM pin, duty, cycles Convert a digital value to analog output via pulse-width modulation. • Pin is a variable/constant (0-15) that specifies the I/O pin to use. This pin will be placed into output mode during pulse generation then switched to input mode when the instruction finishes. • Duty is a variable/constant (0-255) that specifies the analog output level (0 to 5V). • Cycles is a variable/constant (0-65535) specifying an approximate number of milliseconds of PWM output.
BASIC Stamp II repeat the PWM instruction to give the capacitor a fresh charge. Just as it takes time to discharge a capacitor, it also takes time to charge it in the first place. The PWM instruction lets you specify the charging time in terms of PWM cycles. Each cycle is a period of approximately 1ms. So to charge a capacitor for 5ms, you would specify 5 cycles in the PWM instruction. How do you determine how long to charge a capacitor? Use this ruleof-thumb formula: Charge time = 4 * R * C.
BASIC Stamp II How PWM is Generated The term “PWM” applies only loosely to the action of the BS2’s PWM instruction. Most systems that output PWM do so by splitting a fixed period of time into an on time (1) and an off time (0). Suppose the interval is 1 ms and the duty cycle is 100/255. Conventional PWM would turn the output on for 0.39 ms and off for 0.61 ms, repeating this process each millisecond.
BASIC Stamp II Random RANDOM variable Generate a pseudo-random number. • Variable is a byte or word variable whose bits will be scrambled to produce a random number. Explanation Random generates pseudo-random numbers ranging from 0 to 65535. They’re called “pseudo-random” because they appear random, but are generated by a logic operation that always produces the same result for a given input. For example: w1 = 0 RANDOM w1 ' Generate "random" number. debug dec ? w1 ' Clear word variable w1 to 0.
BASIC Stamp II for trials = 1 to 100 hold: RANDOM flip randomize. button 7,0,250,100,btn,0,hold branch coin,[head,tail] head: debug cr,"HEADS" heads = heads+1 goto theNext ' 100 tosses of the coin. ' While waiting for button, ' Wait for button. ' If 0 then head; if 1 then tail. ' Show heads. ' Increment heads counter. ' Next flip. tail: debug cr,"TAILS" ' Show tails. tails = tails+1 ' Increment tails counter. theNext: ' Next flip. next ' When done, show the total number of heads and tails.
BASIC Stamp II RCtime RCTIME pin, state, resultVariable Count time while pin remains in state—usually to measure the charge/ discharge time of resistor/capacitor (RC) circuit. • Pin is a variable/constant (0–15) that specifies the I/O pin to use. This pin will be placed into input mode and left in that state when the instruction finishes. • State is a variable or constant (1 or 0) that will end the RCtime period.
BASIC Stamp II Figure I-14 +5V +5V R C 220Ω 220Ω I/O pin I/O pin C R a use with state = 1 (preferred—see text) b use with state = 0 Before RCtime executes, the capacitor must be put into the state specified in the RCtime instruction. For example, with figure I-14a, the capacitor must be discharged until both plates (sides of the capacitor) are at 5V.
BASIC Stamp II In this formula ln is the natural logarithm; it’s a key on most scientific calculators. Let’s do some math. Assume we’re interested in a 10k resistor and 0.1µF cap. Calculate t: t = (10 x 103 ) x (0.1 x 10-6 ) = 1 x 10-3 The RC time constant is 1 x 10-3 or 1 millisecond. Now calculate the time required for this RC circuit to go from 5V to 1.5V (as in figure I-14a): In RCtime units of 2µs, that time (1.204 x 10-3) works out to 602 units. With a 10k resistor and 0.
BASIC Stamp II with R = 10k pot and C = 0.1µf. Connect the circuit to pin 7 and run the program. Adjust the pot and watch the value shown on the Debug screen change. result var word' Word variable to hold result. again: high 7 pause 1 RCTIME 7,1,result debug cls,dec result goto again ' Discharge the cap ' for 1 ms. ' Measure RC charge time. ' Show value on screen. Demo Program 2 This program illustrates the use of RCtime as a sort of fast stopwatch.
BASIC Stamp II Read READ location,variable Read EEPROM location and store value in variable. • Location is a variable/constant (0–2047) that specifies the EEPROM address to read from. • Variable holds the byte value read from the EEPROM (0–255). Explanation The EEPROM is used for both program storage (which builds downward from address 2047) and data storage (which builds upward from address 0). The Read instruction retrieves a byte of data from any EEPROM address.
BASIC Stamp II cont: debug char strAddr = strAddr+1 goto stringOut ' Show character on screen. ' Point to next character. ' Get next character. 2 Parallax, Inc. • BASIC Stamp Programming Manual 1.
BASIC Stamp II Return RETURN Return from a subroutine. Explanation Return sends the program back to the address (instruction) immediately following the most recent Gosub. If Return is executed without a prior Gosub to set the return address, a bug will result. For more thorough coverage of Gosub...Return, see the Gosub writeup. Demo Program This program demonstrates how Gosub and Return work, using Debug messages to trace the program’s execution.
BASIC Stamp II Reverse REVERSE pin Reverse the data direction of the specified pin. • Pin is a variable/constant (0–15) that specifies the I/O pin to use. This pin will be placed into the opposite of its current input/ output mode by inverting the corresponding bit of the DIRS register. Explanation Reverse is convenient way to switch the I/O direction of a pin. If the pin is an input and you Reverse it, it becomes an output; if it’s an output, Reverse makes it an input.
BASIC Stamp II Figure I-16 +5V R1 220Ω LED pin 0 R2 220Ω Page 306 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
BASIC Stamp II Serin SERIN rpin{\fpin},baudmode,{plabel,}{timeout,tlabel,}[inputData] Receive asynchronous (e.g., RS-232) data. • Rpin is a variable/constant (0–16) that specifies the I/O pin through which the serial data will be received. This pin will switch to input mode and remain in that state after the instruction is completed. If Rpin is set to 16, the Stamp uses the dedicated serial-input pin (SIN), which is normally used by the STAMP2 host program.
BASIC Stamp II sequence of bytes; or ignore a specified number of bytes. These actions can be combined in any order in the inputData list. Explanation The BS2 can send and receive asynchronous serial data at speeds up to 50,000 bits per second. Serin, the serial-input instruction, can filter and convert incoming data in powerful ways. With all this power inevitably comes some complexity, which we’ll overcome by walking you through the process of setting up Serin and understanding its options.
BASIC Stamp II description and schematic. The SIN pin goes to a PC’s serial data-out pin on the DB9 connector built into BS2 carrier boards. The connector is wired to allow the STAMP2 host program to remotely reset the BS2 for programming, so it may have to be modified before it can be used with other software; see figure I-17.
BASIC Stamp II for byte-oriented data. Parity can detect some communication errors, but to use it you lose one data bit. This means that incoming data bytes transferred in 7E mode can only represent values from 0 to 127, rather than the 0 to 255 of 8N mode.
BASIC Stamp II The DEC modifier tells Serin to convert decimal numeric text into binary form and store the result in serData. Receiving “123” followed by a space or other nonnumeric text results in the value 123 being stored in serData. DEC is one of a family of conversion modifiers available with Serin; see table I-4 for a list. All of the conversion modifiers work similarly: they receive bytes of data, waiting for the first byte that falls within the range of symbols they accept (e.g.
BASIC Stamp II receives nine bytes through pin 1 at 2400 bps, N81/inverted and stores them in a 10-byte array: serString var byte(10) serString(9) = 0 SERIN 1,16780,[STR serString\9] debug str serString ' Make a 10-byte array. ' Put 0 in last byte. ' Get 9-byte string. ' Display the string. Why store only 9 bytes in a 10-byte array? We want to reserve space for the 0 byte that many BS2 string-handling routines regard as an end-ofstring marker.
BASIC Stamp II There are also Waitstr modifiers, which wait for a sequence that matches a string stored in an array variable. In the example below, we’ll capture a string with STR then have Waitstr look for an exact match: serString var byte(10) serString(9) = 0 debug "Enter password ending in !",cr serin 1,16780,[str serString\9\"!"] debug "Waiting for: ",str serString,cr SERIN 1,16780,[WAITSTR serString] debug "Password accepted.",cr ' Make a 10-byte array. ' Put 0 in last byte. ' Get the string.
BASIC Stamp II The unwanted x data is stored in yOffset, then replaced by the desired y data. This is a sneaky way to filter out a number of any size without using an extra variable. With a little creativity, you can combine the inputData modifiers to filter and extract almost any data. Using Parity and Handling Parity Errors Parity is an error-checking feature.
BASIC Stamp II badData. Note that a parity error takes precedence over other inputData specifications; as soon as an error is detected, Serin aborts and goes to the plabel routine. Setting a Serial Timeout In the examples above, the only way to end the Serin instruction (other than RESET or power-off) is to give Serin the serial data it wants. If no serial data arrives, the program is stuck. However, you can tell the BS2 to abort Serin if it doesn’t receive data within a specified number of milliseconds.
BASIC Stamp II badData: debug cls, "parity error" goto again Controlling Data Flow When you design an application that requires serial communication between BS2s, you have to work within these limitations: • When the BS2 is sending or receiving data, it can’t execute other instructions. • When the BS2 is executing other instructions, it can’t send or receive data. • The BS2 executes 3000 to 4000 instructions per second and there is not serial buffer in the BS2 as there is in PCs.
BASIC Stamp II Inverted Noninverted Go 1 0 Stop 0 1 Here’s an example that demonstrates fpin flow control. It assumes that two BS2s are powered up and connected together as shown in figure I-20. ' SENDER: data out pin 1, flow control pin 0 ' Baudmode: 9600 N8 inverted Serout 1\0,16468,["HELLO!"] ' RECEIVER: data in pin 1, flow control pin 0 ' Baudmode: 9600 N8 inverted letta var byte again: Serin 1\0,16468,[letta] debug letta pause 1000 goto again ' Send the greeting. ' Get 1 byte. ' Display on screen.
BASIC Stamp II Serout SEROUT tpin,baudmode,{pace,}[outputData] SEROUT tpin\fpin,baudmode,{timeout,tlabel,}[outputData] Transmit asynchronous (e.g., RS-232) data. • Tpin is a variable/constant (0–16) that specifies the I/O pin through which the serial data will be sent. This pin will switch to output mode and will remain in that state after the instruction is completed. If Tpin is set to 16, the Stamp uses the dedicated serialoutput pin (SOUT), normally used by the STAMP2 host program.
BASIC Stamp II Tlabel indicates where the program should go in the event that permission to transmit data is not granted within the period specified by timeout. Explanation The BS2 can send and receive asynchronous serial data at speeds up to 50,000 bits per second. Serout, the serial-output instruction, can convert and format outgoing data in powerful ways.
BASIC Stamp II ware description and schematic. In order for SOUT to work at the proper voltage levels, there must be an RS-232 output signal connected to SIN, and that signal must be quiet (not transmitting data) when data is being sent through SOUT. For more information on using the carrier-board DB9 connector for serial communication, see the Serin listing and figure I-17. Figure I-22 Serial Timing and Mode (Baudmode) Asynchronous serial communication relies on precise timing.
BASIC Stamp II ferred in 7E mode can only represent values from 0 to 127, rather than the 0 to 255 of 8E mode. Serout’s “open” baudmodes are used only in special circumstances, usually networking applications. See the Network example below.
BASIC Stamp II modifiers that Serout understands. You can try these modifiers using Debug (which is actually just a special case of Serout configured specifically to send data to the STAMP2 host program). Literal Text and Compound OutputData Serout sends quoted text exactly as it appears in the outputData list: Serout 1,16468,["A"] Serout 1,16468,["HELLO"] ' Send byte value 65 ("A"). ' Send series of bytes, "HELLO".
BASIC Stamp II myText var byte(10) ' An array to hold the string. myText(0) = "H":myText(1) = "E" myText(2) = "L":myText(3) = "L" myText(4) = "0":myText(9) = 5 ' Store "HELLO" in first 5 cells... ' Put length (5) in last cell. Serout 1,16468,[STR myText\myText(9)] ' Send "HELLO" Note that Serout’s string capabilities work only with strings in RAM, not EEPROM.
BASIC Stamp II checking to see whether the receiving device was ready for it. If the receiver wasn’t ready, the data was sent anyway, and lost. With flow control, the serial receiver can tell Serout when to send data. BS2 flow control works on a byte-by-byte basis; no matter how many bytes Serout is supposed to send, it will look for permission to send before each byte. If permission is denied, Serout will wait until it is granted.
BASIC Stamp II This is to ensure that the sender sees a stop signal (0 for inverted comms) when the receiver is being programmed. Flow-control Timeout Flow control solves one problem but can create another—if the receiver isn’t connected, Serout may never get permission to send. The program will be stuck in Serout indefinitely. To prevent this, Serout allows you to specify how long it should wait for permission, from 0 to 65535 ms.
BASIC Stamp II Since open baudmodes only drive to one state, they need a resistor to pull the network into the other state, as shown in the table above and in figure I-23.
BASIC Stamp II ' Net #2: This BS2 waits for the word "ping" (plus LF/CR) ' then pauses 2 seconds and sends the word "pong" (LF/CR) ' and loops. b_mode con 32852 ' Baudmode: 9600 noninverted, open, 8N again: serin 0,b_mode,[wait ("ping",10,13)] pause 2000 serout 0,b_mode,["pong",10,13] goto again The result of the two programs is that a monitoring PC would see the words “ping” and “pong” appear on the screen at 2-second intervals, showing that the pair of BS2s is sending and receiving on the same lines.
BASIC Stamp II Shiftin SHIFTIN dpin,cpin,mode,[result{\bits}{,result{\bits}...}] Shift data in from a synchronous-serial device. • Dpin is a variable/constant (0–15) that specifies the I/O pin that will be connected to the synchronous-serial device’s data output. This pin’s I/O direction will be changed to input and will remain in that state after the instruction is completed.
BASIC Stamp II used by controller peripherals like ADCs, DACs, clocks, memory devices, etc. Trade names for synchronous-serial protocols include SPI and Microwire. At their heart, synchronous-serial devices are essentially shift-registers—trains of flip-flops that pass data bits along in a bucket-brigade fashion to a single data-output pin. Another bit is output each time the appropriate edge (rising or falling, depending on the device) appears on the clock line.
BASIC Stamp II data this will give us; each bit will be the inverse of the previous one. If the first bit is 1, the sequence will be 10101010101... Connect the flipflop as shown in figure I-25b and run the following program: setup: if IN0 = 1 then continue pulsout 1,10 ' Force FF to start ' sequence with data=1. continue: SHIFTIN 0,1,msbpre,[b1] debug "Pre-clock: ",bin8 b1,cr SHIFTIN 0,1,msbpost,[b1] debug "Post-clock: ",bin8 b1,cr ' Shiftin msb-first, pre-clock. ' Show the result in binary.
BASIC Stamp II Demo Program See listing 2 of BS2 application note #2 Using Shiftin and Shiftout, or try the example shown in the explanation above. 2 Parallax, Inc. • BASIC Stamp Programming Manual 1.
BASIC Stamp II Shiftout SHIFTOUT dpin,cpin,mode,[data{\bits}{,data{\bits}...}] Shift data out to a synchronous-serial device. • Dpin is a variable/constant (0–15) that specifies the I/O pin that will be connected to the synchronous-serial device’s data input. This pin’s I/O direction will be changed to output and will remain in that sate after the instruction is completed. • Cpin is a variable/constant (0–15) that specifies the I/O pin that will be connected to the synchronous-serial device’s clock input.
BASIC Stamp II ters—trains of flip-flops that pass data bits along in a bucket-brigade fashion to a single data-output pin. Another bit is input each time the appropriate edge (rising or falling, depending on the device) appears on the clock line. BS2 application note #2 explains shift-register operation in detail. A single Shiftout instruction causes the following sequence of events: Makes the clock pin (cpin) output low.
BASIC Stamp II Sleep SLEEP seconds Put the BS2 into low-power sleep mode for a specified number of seconds. • Seconds is a variable/constant (1-65535) that specifies the duration of sleep in seconds. Explanation Sleep allows the BS2 to turn itself off, then turn back on after a programmed period of time. The length of Sleep can range from 2.3 seconds to slightly over 18 hours. Power consumption is reduced to about 50 µA, assuming no loads are being driven.The resolution of the Sleep instruction is 2.
BASIC Stamp II restores the I/O directions dictated by your program. If you plan to use End, Nap, or Sleep in your programs, make sure that your loads can tolerate these periodic power outages. The simplest solution is often to connect resistors high or low (to +5V or ground) as appropriate to ensure a continuing supply of current during the reset glitch. Demo Program This program demonstrates both Sleep’s timing characteristics and the periodic glitch discussed above.
BASIC Stamp II Stop STOP Stop program execution. Explanation Stop prevents the BS2 from executing any further instructions until it is reset. The following actions will reset the BS2: pressing and releasing the RESET button on the carrier board, taking the RES pin low then high, by downloading a new program, or turning the power off then on. Stop differs from End in two respects: • Stop does not put the BS2 into low-power mode.
BASIC Stamp II Toggle TOGGLE pin Invert the state of a pin. • Pin is a variable/constant (0–15) that specifies the I/O pin to use. The state of the corresponding bit of the OUTS register is inverted and the pin is put into output mode by writing a 1 the corresponding bit of the DIRS register. Explanation Toggle inverts the state of an I/O pin, changing 0 to 1 and 1 to 0.
BASIC Stamp II OUT2 = IN2 TOGGLE 2 ' Make output driver match pin state. ' Then toggle. If you change the previous example to copy IN2 to OUT2 before Toggling, you’ll see that the state of the pin does change. Demo Program Connect LEDs to pins 0 through 3 as shown in figure I-28 and run the program below. The Toggle instruction will treat you to a light show. You may also run the demo without LEDs. The debug window will show you the states of pins 0 through 3.
BASIC Stamp II Write WRITE address,byte Write a byte of data to the EEPROM. • Address is a variable/constant specifying the EEPROM address (0—2047) to write to. • Byte is a data byte to be written into EEPROM. Explanation The EEPROM is used for both program storage (which builds downward from address 2047) and data storage (which may use any EEPROM byte not used for program storage).
BASIC Stamp II name DATA (n) This directive allocates n bytes of EEPROM starting at the address name and extending to address name + (n-1). If you restrict Writes to this range of addresses, you’ll be fine. If your program grows to the point that it overlaps the addresses allocated, the STAMP2 host program will generate an error message and refuse to download it. See the section BS2 EEPROM Data Storage for more information on the Data directive.
BASIC Stamp II pause 2000: debug cls ' Wait 2 seconds, then clear screen. for EEaddr = log to endLog ' Retrieve each sample from EEPROM. read EEaddr,result ' Read back a byte debug "Reading ", dec result,tab," at ", dec EEaddr,cr next ' Do until all samples retrieved. stop 2 Parallax, Inc. • BASIC Stamp Programming Manual 1.
BASIC Stamp II Xout XOUT mpin,zpin,[house\keyOrCommand{\cycles}{,house\keyOrCommand{\cycles}...}] Send an X-10 powerline control command (through the appropriate powerline interface). • Mpin is the I/O pin (0-15) that outputs X-10 signals (modulation) to the powerline-interface device. This pin is placed into output mode. • Zpin is the I/O pin (0-15) that inputs the zero-crossing signal from the powerline-interface device. This pin will be placed into input mode.
BASIC Stamp II and a standard modular phone-base connector (6P4C type). Connections are as follows: PL-513 or TW-523 1 2 3 4 BS2 zPin* GND GND mPin * This pin should also be connected to +5V through a 10k resistor. Here are the Xout command codes and their functions: Command unitOn unitOff unitsOff lightsOn dim bright *Code %10010 %11010 %11100 %10100 %11110 %10110 Function Turn on the currently selected unit. Turn off the currently selected unit. Turn off all modules w/ this house code.
BASIC Stamp II Note that to complete the attention-getting code houseA\unit1 we tacked on the normally optional cycles entry \2 to complete the command before beginning the next one. Always specify two cycles in multiple commands unless you’re adjusting the brightness of a lamp module. Here is an example of a lamp-dimming instruction: zPin mPin houseA unit1 con con con con 0 1 0 0 XOUT mPin,zPin,[houseA\unit1] XOUT mPin,zPin,[houseA\unitOff\2,houseA\dim\10] ' Zpin is P0. ' Mpin is P1.
1: X-10 Control BASIC Stamp II Application Notes Introduction. This application note shows how to use the new Xout command to remotely control X-10® lamp and appliance modules. Background. Home automation—the management of lights and appliances with a computer—promises to increase security, energy efficiency, and convenience around the house.
BASIC Stamp II Application Notes From a more technical standpoint, X-10 signals are digital codes imposed on a 120-kHz carrier that is transmitted during zero crossings of the AC line. To send X-10 commands, a controller must synchronize to the AC line frequency with 50-microsecond precision, and transmit an 11-bit code sequence representing the button pressed. A company named X-10 owns a patent on this system.
BASIC Stamp II Application Notes 1: X-10 Control color codes can vary in phone cables, so be sure to follow the numbers imprinted next to the modular jack on the PL-513 or TW-523 unit. The program listing shows how to send X-10 commands through this hookup. The listing is self-explanatory, and the procedures are simple, as long as you keep some ground rules in mind: • House codes A through P are represented as values from 0 to 15 in the Xout command.
BASIC Stamp II Application Notes Shack. However, relatively few of these carry the PL-513 and TW-523. Advanced Services Inc., a home-automation outlet, sells every conceivable sort of X-10 hardware, including the PL-513 and TW-523 (starting at around $20 at the time of this writing). You may contact them at 800263-8608 or 508-747-5598. Program listing. This program may be downloaded from our Internet ftp site at ftp.parallaxinc.com. The ftp site may be reached directly or through our web site at http://www.
BASIC Stamp II Application Notes ' ON to dimmed OFF in 19 steps. Because dimming is relative to ' the current state of the lamp, the only guaranteed way to set a ' predefined brightness level is to turn the dimmer fully OFF, then ' ON, then dim to the desired level. Otherwise, the final setting of ' the module will depend on its initial brightness level. xout mPin,zPin,[houseA\Unit2] ' Talk to Unit 2. ' This example shows how to combine X-10 instructions into a ' single line.
BASIC Stamp II Application Notes Page 350 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
2: Using Shiftin & Shiftout BASIC Stamp II Application Notes Introduction. This application note shows how to use the new Shiftin and Shiftout instructions to efficiently interface the BASIC Stamp II to synchronous serial peripheral chips. Background. Many of the most exciting peripheral chips for microcontrollers are available only with synchronous-serial interfaces. These go by various names, like SPI, Microwire, three- or four-wire interface, but they are essentially the same in operation.
BASIC Stamp II Application Notes flop is described as “latching” Data onto Q. Parallel latches, like the one shown in figure 1, allow several bits to be simultaneously latched onto a set of outputs. This is one of the ways that a computer addresses multiple devices on a single parallel data bus—it puts the data on the bus, then triggers one device’s Clock. The data is latched into the destination device only; other devices ignore the data until their Clock lines are triggered.
2: Using Shiftin & Shiftout BASIC Stamp II Application Notes Now you understand the communications hardware used in synchronous serial peripherals; it’s basically just a collection of shift registers, latches and other logic. The Stamp II’s built-in Shiftout and Shiftin instructions provided general-purpose tools for working with this kind of hardware. Let’s look at some examples.
BASIC Stamp II Application Notes 2: Using Shiftin & Shiftout Shiftout requires just five pieces of information to do its job: • The pin number of the data connection. • The pin number of the shift-clock connection. • The order in which the bits should be sent—least-significant bit (lsb) first or most-significant bit (msb) first. For the ’595, we chose msb first, since the msb of the output is farthest down the shift register from the data input.
BASIC Stamp II Application Notes 2: Using Shiftin & Shiftout Shiftout, plus one more, the relationship of valid data to clock pulses. Some devices latch bits onto the serial data output on the rising edge of the clock line. Output bits remain valid until the next rising edge. In these cases, your program must specify post-clock input for the Shiftin mode. When bits are latched on the falling edge of the clock, specify preclock input. With pre-clock input, we sometimes encounter a chicken-and-egg problem.
BASIC Stamp II Application Notes Custom Shift Routines. The key to successful use of the Shift instructions is obtaining, reading, and understanding the manufacturer’s specification sheets. In addition to providing the data required to fill in the parameters for the Shift instructions, the data sheets document configuration bits, operating modes, internal register arrangements, and lots of other valuable data. Sources.
BASIC Stamp II Application Notes 2: Using Shiftin & Shiftout ' lines of the '595, pauses, then increments counter and repeats. ' The data is shifted msb first so that the most-significant bit is ' shifted to the end of the shift register, pin QH, and the least' significant bit is shifted to QA. Changing 'msbfirst' to 'lsbfirst' ' causes the data to appear backwards on the outputs of the '595.
BASIC Stamp II Application Notes ' LISTING 3. BIDIRECTIONAL COMMUNICATION WITH LTC1298 ' Program: LTC1298.BS2 (LTC1298 analog-to-digital converter) ' This program demonstrates use of the Shiftout and Shiftin instructions ' to communicate with an LTC1298 serial ADC. Shiftout is used to ' send setup data to the ADC; Shiftin to capture the results of the ' conversion. The comments in this program concentrate on explaining ' the operation of the Shift instructions.
BASIC Stamp II Application Notes 3: Phoneline Interface Introduction. This application note shows how to interface the BS2 to the phone line in applications that use the DTMFout instruction. Background. The BS2 instruction DTMFout generates dual-tone, multifrequency signals—the same musical beeps used to dial the phone, activate pagers, and access repeaters in ham-radio applications.
BASIC Stamp II Application Notes applications using the BS2. It’s based on a circuit presented in Encyclopedia of Electronic Circuits, Volume 5, by Graf and Sheets (TAB/McGraw Hill, 1995; ISBN 0-07-011077-8). We’ve filled in specific component values and sources, added parts for coupling the BS2, and tested the circuit’s ability to dial the phone. How it works.
3: Phoneline Interface BASIC Stamp II Application Notes numbers inside the square brackets are the numbers to dial. Values of 0-9 represent those same buttons on the phone keypad; 10 is the star (*) key; 11 is the pound sign (#); and 12 through 15 are additional tones that aren’t meant for phone-subscriber use. They’re included primarily for non-phone DTMF applications like remote controls and ham-radio purposes. You may specify values as literal numbers, as we did above, or as variables.
BASIC Stamp II Application Notes Page 362 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
Appendix A ASCII Chart Control Codes Name/Function null start of heading start of text end of text end of xmit enquiry acknowledge bell backspace horizontal tab line feed vertical tab form feed carriage return shift out shift in data line escape device control 1 device control 2 device control 3 device control 4 non acknowledge synchronous idle end of xmit block cancel end of medium substitute escape file separator group separator record separator unit separator Printing Characters *Char Code Char Code
Appendix A Page 364 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
Appendix B Reserved Words The following table shows the reserved words for each stamp module. BASIC STAMP I AND B0..B13 BIT0..BIT15 BRANCH BSAVE BUTTON DEBUG DIR0..DIR7 DIRS EEPROM END FOR GOSUB GOTO HIGH IF INPUT LET LOOKDOWN LOOKUP LOW MAX MIN N300 N600 N1200 N2400 NAP NEXT ON300 ON600 ON1200 ON2400 OR OT300 OT600 OT1200 OT2400 OUTPUT PAUSE PIN0..PIN7 PINS PORT POT PULSIN PULSOUT PWM RANDOM READ REVERSE SERIN SEROUT SLEEP SOUND STEP SYMBOL T300 T600 T1200 T2400 THEN TOGGLE W0..
Appendix B Page 366 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
Appendix C BASIC Stamp I and Stamp II Conversions INTRODUCTION .................................................................... 371 TYPOGRAPHICAL CONVENTIONS ................................................ 371 HOW TO USE THIS APPENDIX .................................................... 374 COMMAND AND DIRECTIVE DIFFERENCES ..................................... 375 RAM SPACE AND REGISTER ALLOCATION ...................................... 376 BASIC Stamp I ................................................
BASIC Stamp I and Stamp II Conversions END ................................................................................. 396 BASIC Stamp I .................................................................................396 BASIC Stamp II ................................................................................396 EXPRESSIONS...................................................................... 397 BASIC Stamp I .................................................................................
Appendix C LOW ................................................................................. 413 BASIC Stamp I .................................................................................413 BASIC Stamp II ................................................................................413 NAP ................................................................................. 414 BASIC Stamp I .................................................................................414 BASIC Stamp II .........
BASIC Stamp I and Stamp II Conversions SERIN ............................................................................... 429 BASIC Stamp I .................................................................................429 BASIC Stamp II ................................................................................429 SERIN Baudmode Conversion ....................................................430 SEROUT .............................................................................
Appendix C INTRODUCTION The BASIC Stamp I and BASIC Stamp II have many differences in both hardware and software. While it is trivial to recognize the differences in the Stamp hardware, the modifications to the PBASIC command structure are intricate and not always obvious. This appendix describes the Stamp I and Stamp II PBASIC differences in a detailed manner to aid in the conversion of programs between the two modules.
BASIC Stamp I and Stamp II Conversions 1. First do this... 2. Next do this... The most important steps in conversion will be listed in a numeric sequence within the conversion section. The order of the numbered steps may be important in some situations and unimportant in others; it is best to follow the order as closely as possible. Tips which are not vital to the conversion are listed within the conversion section and are preceded by bullets as shown above.
Appendix C CONVERSION: BS1 Q BS2 1. First do this... ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 2. Next do this... • You might like to know this... • You might want to try this... The following symbols appear within command syntax listings or within the text describing them. UPPER CASE All command names will be shown is upper case lettering within the command syntax line.
BASIC Stamp I and Stamp II Conversions #..# Double periods between numbers indicate that a contiguous range of numbers are allowed for the given argument. Wherever a range of numbers are shown it usually indicates the valid range which a command expects to see. If a number is given which is outside of this range the Stamp will only use the lowest bits of the value which correspond to the indicated range. For example, if the range 0..
Appendix C COMMAND AND DIRECTIVE DIFFERENCES Many enhancements to the Stamp I command structure were made in the Stamp II. Commands have also been added, replaced or removed. The following table shows the differences between the two modules. BASIC Stamp I BASIC Stamp II Comments BRANCH BSAVE BUTTON BRANCH Syntax Modifications Removed DEBUG EEPROM END (Expressions) FOR...NEXT GOSUB GOTO HIGH IF...
BASIC Stamp I and Stamp II Conversions RAM SPACE AND REGISTER ALLOCATION BASIC STAMP I The RAM space in the BASIC Stamp I consists of eight 16-bit words. Each word has a unique, predefined name as shown in the table below. Each word consists of two 8-bit bytes which have unique, predefined names. Additionally the first two words, PORT and W0, can be accessed as individual bits. The first word, named PORT, is reserved to allow access and control over the 8 I/O pins on the Stamp I.
Appendix C • CONSTANTVALUE is a valid number in decimal, hexidecimal, binary or ascii. Stamp I I/O and Variable Space Word Name Byte Name Bit Names Special Notes PORT PINS DIRS PIN0 - PIN7 DIR0 - DIR7 W0 B0 B1 B2 B3 B4 B5 B6 B7 B8 B9 B10 B11 B12 B13 BIT0 - BIT7 BIT8 - BIT15 W1 W2 W3 W4 W5 W6 I/O pins; bit addressable. I/O pin direction control; bit addressable. Bit addressable. Bit addressable. Used by GOSUB instruction. Used by GOSUB instruction.
BASIC Stamp I and Stamp II Conversions The other thirteen words are general purpose registers for use by the PBASIC program. There are two methods of referencing these registers within the Stamp II as follows: 1. They may be referenced via their direct name or by defining symbols as aliases. - OR 2. They may be referenced by defining variables of specific types (byte, word, etc.). The software will automatically assign variables to registers in an efficient manner.
Appendix C To define a variable of a specific type, use the following format. variablename VAR [ type{(arraysize)} | previousvariable{.modifier{.modifier...}} ] Example: LoopCounter LoopCounter2 FirstBit VAR WORD VAR BYTE(2) 'defines LoopCounter as a word. 'defines LoopCounter2 as an array of 'two bytes. VAR LoopCounter.LOWBIT 'defines FirstBit as the lowest bit 'within the variable LoopCounter.
BASIC Stamp I and Stamp II Conversions • CONSTANTNAME is a series of characters (letters, numbers and underscores but not starting with a number) up to 32 characters in length. • CONSTANTEXPRESSION is a numerical expression in decimal, hexidecimal, binary or ascii using only numbers and the +, -, *, /, &, |, ^, << or >> operators. NOTE: Parentheses are not allowed and expressions are always computed using 16-bits.
Appendix C SYMBOL CONVERSION: BS1 R BS2 1. Remove the ‘SYMBOL’ directive from variable or constant declarations. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 2.
BASIC Stamp I and Stamp II Conversions BS2 to BS1 Register Allocation Conversion Stamp II Variable Type / Register Name Stamp I Register Name INS PINS OUTS PINS DIRS DIRS WORD W0..W6 BYTE B0..B13 NIB B0..B13* BIT BIT0..BIT15** * There are no registers on the Stamp I which are nibble addressable. The best possible solution is to place one or two nibble variables within a byte register and modify the code accordingly.
Appendix C BRANCH BASIC STAMP I BRANCH index,(label0, label1,... labeln) • INDEX is a constant or a bit, byte or word variable. • LABEL0..LABELN are valid labels to jump to according to the value of INDEX. BASIC STAMP II BRANCH index,[label0, label1,... labeln] • INDEX is a constant, expression or a bit, nibble, byte or word variable. • LABEL0..LABELN are valid labels to jump to according to the value of INDEX. CONVERSION: BS1 R BS2 1.
BASIC Stamp I and Stamp II Conversions BSAVE BASIC STAMP I BSAVE • This is a compiler directive which causes the Stamp I software to create a file containing the tokenized form or the associated source code. BASIC STAMP II NO EQUIVELANT COMMAND CONVERSION: No conversion possible. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ Page 384 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
Appendix C BUTTON BASIC STAMP I BUTTON pin, downstate, delay, rate, workspace, targetstate, label • PIN is a constant or a bit, byte or word variable in the range 0..7. • DOWNSTATE is a constant or a bit, byte or word variable in the range 0..1. • DELAY is a constant or a bit, byte or word variable in the range 0..255. • RATE is a constant or a bit, byte or word variable in the range 0..255. • WORKSPACE is a byte or word variable. • TARGETSTATE is a constant or a bit, byte or word variable in the range 0..
BASIC Stamp I and Stamp II Conversions • LABEL is a valid label to jump to in the event of a button press. CONVERSION: BS1 R BS2 1. PIN may be a constant or a bit, nibble, byte or word variable in the range 0..15. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 2. Any or all arguments other than LABEL may be nibble variables for efficiency.
Appendix C COUNT BASIC STAMP I NO EQUIVELANT COMMAND BASIC STAMP II COUNT pin, period, result • PIN is a constant, expression or a bit, nibble, byte or word variable in the range 0..15. • PERIOD is a constant, expression or a bit, nibble, byte or word variable in the range 0..65535. • RESULT is a bit, nibble, byte or word variable. CONVERSION: No conversion possible. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ C Parallax, Inc.
BASIC Stamp I and Stamp II Conversions DEBUG BASIC STAMP I DEBUG outputdata{,outputdata...} • OUTPUTDATA is a text string, bit, byte or word variable (no constants allowed). • If no formatters are specified DEBUG defaults to “variablename = value” + carriage return. FORMATTERS: (The following formatting characters may precede the variable name) # $ % @ displays value in decimal followed by a space. displays “variablename = $value ” + carriage return; where value is in hexidecimal.
Appendix C ASC? value Displays “variablename = ‘character’ ” + carriage return; where character is an ascii character. STR bytearray Displays values as an ascii string until a value of 0 is reached. STR bytearray\n Displays values as an ascii string for n bytes. REP value\n Displays value n times. DEC{1..5} value Displays value in decimal, optionally limited or padded for 1 to 5 digits. SDEC{1..5} value Displays value in signed decimal, optionally limited or padded for 1 to 5 digits.
BASIC Stamp I and Stamp II Conversions IBIN{1..16} value Displays value in binary preceded by a “%” and optionally limited or padded for 1 to 16 digits. ISBIN{1..16} value Displays value in signed binary preceded by a “%” and optionally limited or padded for 1 to 16 digits. Value must not be less than a word variable. SPECIAL SYMBOLS: (The following symbols can be included in the output data) BELL Causes the computer to beep. BKSP Causes the cursor to backup one space.
Appendix C CONVERSION: BS1 Q BS2 1. Remove any ‘DEC?’ formatters preceding variables. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 2. Replace all ‘DEC’ formatters with ‘#’. 3. Replace all ‘HEX?’ formatters with ‘$’. 4. Replace all ‘BIN?’ formatters with ‘%’. 5. Replace all ‘ASC?’ formatters with ‘@’. 6. Delete any ‘?’ formatting characters. 7. Signs, type indicators, strings and digit limitation formatters are not available in the Stamp I.
BASIC Stamp I and Stamp II Conversions DATA BASIC STAMP I EEPROM {location,}(data{,data...}) • LOCATION is in the range 0..255. • DATA is a constant in the range 0..255. No variables are allowed. BASIC STAMP II {pointer} DATA {@location,} {WORD} {data}{(size)} {, { WORD} {data}{(size)}...} • POINTER is an optional undefined constant name or a bit, nibble, byte or word variable which is assigned the value of the first memory location in which data is written.
Appendix C Example: BS1: EEPROM 100, (255, 128, 64, 92) BS2: DATA @100, 255, 128, 64, 92 CONVERSION: BS1 Q BS2 1. If a POINTER constant is specified, remove it and set it equal to the value of the first location using a Stamp I assign statement. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 2. Replace the DATA directive with the EEPROM directive. 3. If LOCATION is specified, remove the at sign, ‘@’, immediately before it. 4.
BASIC Stamp I and Stamp II Conversions DTMFOUT BASIC STAMP I NO EQUILEVANT COMMAND BASIC STAMP II DTMFOUT pin, {ontime, offtime,}[key{,key...}] • PIN is a constant, expression or a bit, nibble, byte or word variable in the range 0..15. • ONTIME and OFFTIME are constants, expressions or bit, nibble, byte or word variables in the range 0..65535. • KEY is a constant, expression or a bit, nibble, byte or word variable in the range 0..15. CONVERSION: No conversion possible.
Appendix C EEPROM (See DATA) C Parallax, Inc. • BASIC Stamp Programming Manual 1.
BASIC Stamp I and Stamp II Conversions END BASIC STAMP I END • 20uA reduced current (no loads). BASIC STAMP II END • 50uA reduced current (no loads). CONVERSION: No conversion necessary. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ Page 396 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
Appendix C EXPRESSIONS BASIC STAMP I {-} value ?? value {?? value...} • Stamp I expressions are only allowed within an assignment statement. See the LET command for more detail. • VALUE is a constant or a bit, byte or word variable. • ?? is +,-,*,**,/,//,MIN,MAX,&,1,^,&/,|/,^/. BASIC STAMP II {?} value ?? value {?? {?} value} • Stamp II expressions are allowed in place of almost any argument in any command as well as within an assignment statement. • ? is SQR, ABS, ~, -, DCD, NCD, COS, SIN.
BASIC Stamp I and Stamp II Conversions CONVERSION: BS1 Q BS2 1. Remove any unary operator other than minus (-) and modify the equation as appropriate, if possible. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 2. The binary operator can not be */, DIG, <<, >> or REV. 3. VARIABLE and VALUE must not be a nibble variable. Example: BS2: Result = ~%0001 + 16 BS1: b0 = %1110 + 16 Page 398 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
Appendix C FOR...NEXT BASIC STAMP I FOR variable = start TO end {STEP {-} stepval}...NEXT {variable} • Up to 8 nested FOR...NEXT loops are allowed. • VARIABLE is a bit, byte or word variable. • START is a constant or a bit, byte or word variable. • END is a constant or a bit, byte or word variable. • STEPVAL is a constant or a bit, byte or word variable. • VARIABLE (after NEXT) must be the same as VARIABLE (after FOR). BASIC STAMP II FOR variable = start TO end {STEP stepval}...
BASIC Stamp I and Stamp II Conversions 2. Remove the VARIABLE name after the NEXT statement if given. The variable is always assumed to be from the most recent FOR statement and is not allowed in the Stamp II. • VARIABLE, START, END and STEPVAL may be a nibble variable for efficiency. • Up to 16 nested FOR...NEXT statements may be used. Example: BS1: FOR B0 = 10 TO 1 STEP -1 {code inside loop} NEXT B0 BS2: FOR LoopCount = 10 TO 1 STEP 1 {code inside loop} NEXT CONVERSION: BS1 Q BS2 1.
Appendix C FREQOUT BASIC STAMP I SOUND pin, (note, duration {,note, duration...}) • PIN is a constant or a bit, byte or word variable in the range of 0..7. • NOTE is a constant or a bit, byte or word variable in the range of 0..255 representing frequencies in the range 94.8 Hz to 10,550 Hz. • DURATION is a constant or a bit, byte or word variable in the range of 1..255 specifying the duration in 12 ms units.
BASIC Stamp I and Stamp II Conversions • PIN may be in the range 0..15. Example: BS1: SOUND 1, (92, 128, 75, 25) BS2: FREQOUT 1, 1536, 333 FREQOUT 1, 300, 226 CONVERSION: BS1 Q BS2 1. Change command name ‘FREQOUT’ to ‘SOUND’. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 2. PIN must be in the range 0..7. 3. Insert an open parenthesis just before the MILLISECONDS argument. 4.
Appendix C GOSUB BASIC STAMP I GOSUB label • Up to 16 GOSUBs allowed per program. • Up to 4 nested GOSUBs allowed. • Word W6 is modified with every occurrence of GOSUB. BASIC STAMP II GOSUB label • Up to 255 GOSUBs allowed per program. • Up to 4 nested GOSUBs allowed. CONVERSION: BS1 R BS2 • Up to 255 GOSUBs can be used in the program.
BASIC Stamp I and Stamp II Conversions GOTO BASIC STAMP I GOTO label BASIC STAMP II GOTO label CONVERSION: No conversion necessary. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ Page 404 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
Appendix C HIGH BASIC STAMP I HIGH pin • PIN is a constant, expression or a bit, byte or word variable in the range 0..7. BASIC STAMP II HIGH pin • PIN is a constant, expression or a bit, nibble, byte or word variable in the range 0..15. CONVERSION: BS1 R BS2 • PIN may be a constant, expression or a bit, nibble, byte or word variable in the range 0..15.
BASIC Stamp I and Stamp II Conversions IF...THEN BASIC STAMP I IF variable ?? value {AND/OR variable ?? value...} THEN label • VARIABLE is a bit, byte or word variable. No constants are allowed. • ?? is =, <>, >, <, >=, <=. • VALUE is a constant or a bit, byte, or word variable. • LABEL is a location to branch to if the result is true.
Appendix C INPUT BASIC STAMP I INPUT pin • PIN is a constant, expression or a bit, byte or word variable in the range 0..7. BASIC STAMP II INPUT pin • PIN is a constant, expression or a bit, nibble, byte or word variable in the range 0..15. CONVERSION: BS1 R BS2 • PIN may be a nibble variable in the range 0..15.
BASIC Stamp I and Stamp II Conversions LET BASIC STAMP I {LET} variable = {-} value ?? value {?? value...} • VARIABLE is a bit, byte or word variable. • VALUE is a constant or a bit, byte or word variable. • ?? is +,-,*,**,/,//,MIN,MAX,&,1,^,&/,|/,^/. BASIC STAMP II variable = {?} value ?? value {?? {?} value} • VARIABLE is a bit, nibble, byte or word variable. • ? is SQR, ABS, ~, -, DCD, NCD, COS, SIN. • VALUE is a constant or a bit, nibble, byte or word variable.
Appendix C 2. The binary operator can not be */, DIG, <<, >> or REV. 3. VARIABLE and VALUE must not be a nibble variable. Example: BS2: Result = ~%0001 + 16 BS1: b0 = %1110 + 16 C Parallax, Inc. • BASIC Stamp Programming Manual 1.
BASIC Stamp I and Stamp II Conversions LOOKDOWN BASIC STAMP I LOOKDOWN value, (value0, value1,... valueN), variable • VALUE is a constant or a bit, byte or word variable. • VALUE0, VALUE1, etc. are constants or a bit, byte or word variables. • VARIABLE is a bit, byte or word variable. BASIC STAMP II LOOKDOWN value, {??,} [value0, value1,... valueN], variable • VALUE is a constant, expression or a bit, nibble, byte or word variable. • ?? is =, <>, >, <, <=, =>. (= is the default). • VALUE0, VALUE1, etc.
Appendix C • None of the arguments may nibble variables. Example: BS2: LOOKDOWN ByteValue, [1, 2, 3, 4], Result BS1: LOOKDOWN b0, (1, 2, 3, 4), b1 C Parallax, Inc. • BASIC Stamp Programming Manual 1.
BASIC Stamp I and Stamp II Conversions LOOKUP BASIC STAMP I LOOKUP index, (value0, value1,... valueN), variable • INDEX is a constant or a bit, byte or word variable. • VALUE0, VALUE1, etc. are constants or a bit, byte or word variables. • VARIABLE is a bit, byte or word variable. BASIC STAMP II LOOKUP index, [value0, value1,... valueN], variable • INDEX is a constant, expression or a bit, nibble, byte or word variable. • VALUE0, VALUE1, etc.
Appendix C LOW BASIC STAMP I LOW pin • PIN is a constant or a bit, byte or word variable in the range 0..7. BASIC STAMP II LOW pin • PIN is a constant, expression or a bit, nibble, byte or word variable in the range 0..15. CONVERSION: BS1 R BS2 • PIN may be a constant or a bit, nibble, byte or word variable in the range 0..15.
BASIC Stamp I and Stamp II Conversions NAP BASIC STAMP I NAP period • PERIOD is a constant or a bit, byte or word variable in the range 0..7 representing 18ms intervals. • Current is reduced to 20uA (assuming no loads). BASIC STAMP II NAP period • PERIOD is a constant, expression or a bit, nibble, byte or word variable in the range 0..7 representing 18ms intervals. • Current is reduced to 50uA (assuming no loads). CONVERSION: No conversion necessary.
Appendix C OUTPUT BASIC STAMP I OUTPUT pin • PIN is a constant or a bit, byte or word variable in the range 0..7. BASIC STAMP II OUTPUT pin • PIN is a constant, expression or a bit, nibble, byte or word variable in the range 0..15. CONVERSION: BS1 R BS2 • PIN may be a constant or a bit, nibble, byte or word variable in the range 0..15. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ CONVERSION: BS1 Q BS2 1.
BASIC Stamp I and Stamp II Conversions PAUSE BASIC STAMP I PAUSE milliseconds • MILLISECONDS is a constant or a bit, byte or word variable in the range 0..65535. BASIC STAMP II PAUSE milliseconds • MILLISECONDS is a constant, expression or a bit, nibble, byte or word variable in the range 0..65535. CONVERSION: No conversion necessary. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ Page 416 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
Appendix C POT (See RCTIME) C Parallax, Inc. • BASIC Stamp Programming Manual 1.
BASIC Stamp I and Stamp II Conversions PULSIN BASIC STAMP I PULSIN pin, state, variable • PIN is a constant, expression or a bit, byte or word variable in the range 0..7. • STATE is a constant, expression or a bit, byte or word variable in the range 0..1. • VARIABLE is a bit, byte or word variable. • Measurements are in 10uS intervals and the instruction will time out in 0.65535 seconds.
Appendix C CONVERSION: BS1 Q BS2 • None of the arguments may be a nibble variable. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ • PIN must be in the range 0..7. • Returned value is 5 times more than in the Stamp I counterpart. Example: BS2: PULSIN 15, 1, Result BS1: PULSIN 7, 1, W0 C Parallax, Inc. • BASIC Stamp Programming Manual 1.
BASIC Stamp I and Stamp II Conversions PULSOUT BASIC STAMP I PULSOUT pin, time • PIN is a constant or a bit, byte or word variable in the range 0..7. • TIME is a constant or a bit, byte or word variable in the range 0..65535 representing the pulse width in 10uS units. BASIC STAMP II PULSOUT pin, period • PIN is a constant, expression or a bit, nibble, byte or word variable in the range 0..15. • PERIOD is a constant, expression or a bit, nibble, byte or word variable in the range 0..
Appendix C PWM BASIC STAMP I PWM pin, duty, cycles • PIN is a constant or a bit, byte or word variable in the range 0..7. • DUTY is a constant or a bit, byte or word variable in the range 0..255. • CYCLES is a constant or a bit, byte or word variable in the range 0..255 representing the number of 5ms cycles to output. BASIC STAMP II PWM pin, duty, cycles • PIN is a constant, expression or a bit, nibble, byte or word variable in the range 0..15.
BASIC Stamp I and Stamp II Conversions CONVERSION: BS1 Q BS2 1. CYCLES = CYCLES / 5. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ • PIN must be in the range 0..7 and must not be a nibble variable. Example: BS2: PWM 15, 5, 20 BS1: PWM 7, 5, 4 Page 422 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
Appendix C RANDOM BASIC STAMP I RANDOM variable • VARIABLE is a byte or word variable in the range 0..65535. BASIC STAMP II RANDOM variable • VARIABLE is a byte or word variable in the range 0..65535. CONVERSION: BS1 R BS2 • The numbers generated for any given input will not be the same on the Stamp II as in the Stamp I.
BASIC Stamp I and Stamp II Conversions RCTIME BASIC STAMP I POT pin, scale, bytevariable • PIN is a constant or a bit, byte or word variable in the range 0..7. • SCALE is a constant or a bit, byte or word variable in the range 0..255. • BYTEVARIABLE is a byte variable. BASIC STAMP II RCTIME pin, state, variable • PIN is a constant, expression or a bit, nibble, byte or word variable in the range 0..15. • STATE is a constant, expression or a bit, nibble, byte or word variable in the range 0..1.
Appendix C PAUSE delay ; where DELAY is an appropriate time in milliseconds to allow the capacitor to; fully discharge. You may have to try different DELAY values to find an optimal; value. 3. Change the command’s name from ‘POT’ to ‘RCTIME’. 4. Replace the SCALE argument with a STATE argument; our example requires a 1. • PIN may be a nibble variable in the range 0..15. CONVERSION: BS1 Q BS2 1. Modify the circuit connected to PIN to look similar to the following diagram.
BASIC Stamp I and Stamp II Conversions 5. Replace the STATE argument with a SCALE argument. 6. Make VARIABLE a byte variable. • PIN must be in the range 0..7 and must not be a nibble variable. Page 426 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
Appendix C READ BASIC STAMP I READ location, variable • LOCATION is a constant or a bit, byte or word variable in the range 0..255. • VARIABLE is a bit, byte or word variable. BASIC STAMP II READ location, variable • LOCATION is a constant, expression or a bit, nibble, byte or word variable in the range 0..2047. • VARIABLE is a bit, nibble, byte or word variable. CONVERSION: BS1 R BS2 • LOCATION and VARIABLE may be a nibble variable for efficiency.
BASIC Stamp I and Stamp II Conversions REVERSE BASIC STAMP I REVERSE pin • PIN is a constant or a bit, byte or word variable in the range 0..7. BASIC STAMP II REVERSE pin • PIN is a constant, expression or a bit, nibble, byte or word variable in the range 0..15. CONVERSION: BS1 R BS2 • PIN may be a constant, expression or a bit, nibble, byte or word variable in the range 0..15.
Appendix C SERIN BASIC STAMP I SERIN pin, baudmode {,(qualifier {,qualifier...} ) } {,{#} variable...} • PIN is a constant or a bit, byte or word variable in the range 0..7. • BAUDMODE is a constant or a bit, byte or word variable in the range 0..7 or a symbol with the following format: [T|N][2400|1200|600|300]. • QUALIFIERs are optional constants or a bit, byte or word variables which must be received in the designated order for execution to continue. • VARIABLE is a bit, byte or word variable.
BASIC Stamp I and Stamp II Conversions formatters. Additionally, the following formatters are available: STR bytearray\L{\E} input a string into bytearray of length L with optional endcharacter of E. (0’s will fill remaining bytes). SKIP L input and ignore L bytes. WAITSTR bytearray{\L} Wait for bytearray string (of L length, or terminated by 0 if parameter is not specified and is 6 bytes maximum). WAIT Wait for up to a six-byte sequence. (value {,value...}) CONVERSION: BS1 R BS2 1.
Appendix C be encased in brackets, “[“ and “]”. If QUALIFIERS are present, insert the modifier “WAIT” immediately before the open parenthesis before the first QUALIFIER. 3. Replace any optional “#” formatters with the equivalent “DEC” formatter. • RPIN = PIN and may be in the range 0..16 • BAUDMODE may be any bit period in between 300 baud and 50000 baud and can be calculated using the following formula: INT(1,000,000/Baud Rate) - 20.
BASIC Stamp I and Stamp II Conversions 7. If QUALIFIERS are specified within a WAIT modifier, remove the word “WAIT”. 8. IF QUALIFIERS are specified within a WAITSTR modifier, replace the word “WAITSTR” with an open parenthesis, “(“. Convert the bytearray into a constant text or number sequence separated by commas if necessary (remove the length specifier “\L” if one exists) and insert a close parenthesis, “)”, immediately afterward. 9.
Appendix C SEROUT BASIC STAMP I SEROUT pin, baudmode, ( {#} data {, {#} data...} ) • PIN is a constant or a bit, byte or word variable in the range 0..7. • BAUDMODE is a constant or a bit, byte or word variable in the range 0..15 or a symbol with the following format: {O}[T|N][2400|1200|600|300]. • DATA is a constant or a bit, byte or word variable. • # will convert binary numbers to ascii text equivalents up to 5 digits in length.
BASIC Stamp I and Stamp II Conversions • OUTPUTDATA is a set of constants, expressions and variable names separated by commas and optionally proceeded by the formatters available in the DEBUG command. CONVERSION: BS1 R BS2 1. BAUDMODE is a constant or a bit, nibble, byte or word variable equal to the bit period of the baud rate plus three control bits which specify 8-bit/7-bit, True/Inverted and Driven/Open output.
Appendix C • TPIN = PIN and may be in the range 0..16. • BAUDMODE may be any bit period in between 300 baud and 50000 baud and can be calculated using the following formula: INT(1,000,000/Baud Rate) - 20. • The optional formatter may include any valid formatter for the DEBUG command. Example: BS1: SEROUT 3, T2400, (“Start”, #B0, B1) BS2: SEROUT 3, 396, [“Start”, DEC FirstByte, SecondByte] CONVERSION: BS1 Q BS2 1. PIN = TPIN and must be in the range 0..7.
BASIC Stamp I and Stamp II Conversions Example: BS2: SEROUT 15, 3313, 1000, TimedOut, [“Start”, DEC FirstByte, SecondByte] BS1: SEROUT 7, T300, (“Start”, #B0, B1) Page 436 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
Appendix C SHIFTIN BASIC STAMP I NO EQUIVELANT COMMAND BASIC STAMP II SHIFTIN dpin, cpin, mode, [result{\bits} { ,result{\bits}... }] • DPIN is a constant, expression or a bit, nibble, byte or word variable in the range 0..15 specifying the data pin. • CPIN is a constant, expression or a bit, nibble, byte or word variable in the range 0..15 specifying the clock pin. • MODE is a constant, symbol, expression or a bit, nibble, byte or word variable in the range 0..4 specifying the bit order and clock mode.
BASIC Stamp I and Stamp II Conversions May be converted to the following code: Value CLK DATA VAR CON CON BYTE 0 1 'Result of shifted data 'Clock pin is pin 0 'Data pin is pin 1 DIRS = %0000000000000001 as input 'Set Clock pin as output and Data pin SHIFTIN DATA, CLK, MSBPRE, [Value\8] CONVERSION: BS1 Q BS2 • Code such as the following: ○ ○ ○ ○ ○ ○ Value ○ ○ ○ ○ ○ ○ ○ VAR ○ ○ ○ ○ ○ ○ BYTE DIRS = %0000000000000001 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 'Result of
Appendix C SHIFTOUT BASIC STAMP I NO EQUIVELANT COMMAND BASIC STAMP II SHIFTOUT dpin, cpin, mode, [data{\bits} {, data{\bits}... }] • DPIN is a constant, expression or a bit, nibble, byte or word variable in the range 0..15 specifying the data pin. • CPIN is a constant, expression or a bit, nibble, byte or word variable in the range 0..15 specifying the clock pin. • MODE is a constant, symbol, expression or a bit, nibble, byte or word variable in the range 0..1 specifying the bit order.
BASIC Stamp I and Stamp II Conversions May be converted to the following code: Value CLK DATA VAR CON CON BYTE 0 1 'Value to be shifted out 'Clock pin is pin 0 'Data pin is pin 1 DIRS = %0000000000000011 'Set Clock and Data pins as 'outputs Value = 125 SHIFTOUT DATA, CLK, MSBFIRST, [Value\8] CONVERSION: BS1 Q BS2 Code such as the following: ○ ○ ○ ○ ○ ○ ○ ○ ○ Value CLK DATA ○ ○ ○ ○ VAR CON CON ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ BYTE 0 1 DIRS = %0000000000000011 ○ 'Note that value is still
Appendix C SLEEP BASIC STAMP I SLEEP seconds • SECONDS is a constant or a bit, byte or word variable in the range 1..65535 specifying the number of seconds to sleep. BASIC STAMP II SLEEP seconds • SECONDS is a constant, expression or a bit, nibble, byte or word variable in the range 0..65535 specifying the number of seconds to sleep. CONVERSION: No conversion necessary. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ C Parallax, Inc.
BASIC Stamp I and Stamp II Conversions SOUND (See FREQOUT) Page 442 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
Appendix C STOP BASIC STAMP I NO EQUIVELANT COMMAND BASIC STAMP II STOP • Execution is frozen, such as with the END command, however, low-power mode is not entered and the I/O pins never go into high impedance mode.
BASIC Stamp I and Stamp II Conversions TOGGLE BASIC STAMP I TOGGLE pin • PIN is a constant or a bit, byte or word variable in the range 0..7. BASIC STAMP II TOGGLE pin • PIN is a constant, expression or a bit, nibble, byte or word variable in the range 0..15. CONVERSION: BS1 R BS2 • PIN may be a nibble variable and may be in the range 0..15.
Appendix C WRITE BASIC STAMP I WRITE location, data • LOCATION is a constant or a bit, byte or word variable in the range 0..255. • DATA is a constant or a bit, byte or word variable. BASIC STAMP II WRITE location, data • LOCATION is a constant, expression or a bit, nibble, byte or word variable in the range 0..2047. • DATA is a constant, expression or a bit, nibble, byte or word variable. CONVERSION: BS1 R BS2 • LOCATION and DATA may be a nibble variable for efficiency.
BASIC Stamp I and Stamp II Conversions XOUT BASIC STAMP I NO EQUIVELANT COMMAND BASIC STAMP II XOUT mpin, zpin, [house\keyorcommand{\cycles} {, house\keyorcommand{\cycles}... }] • MPIN is a constant, expression or a bit, nibble, byte or word variable in the range 0..15 specifying the modulation pin. • ZPIN is a constant, expression or a bit, nibble, byte or word variable in the range 0..15 specifying the zero-crossing pin.
BASIC Stamp I Schematic Appendix D D Parallax, Inc. • BASIC Stamp Programming Manual 1.
Schematics BASIC Stamp II Schematic Page 448 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.