Page 1
® ® BASIC Stamp Programming Manual Version 2.0c...
Page 2
Warranty Parallax warrants its products against defects in materials and workmanship for a period of 90 days. If you discover a defect, Parallax will, at its option, repair, replace, or refund the purchase price. Simply call our sales department for an RMA number, write it on the label and return the product with a description of the problem.
Free on Parallax CD (Documentation -> Educational Curriculum section) and web site (Downloads section), or for purchase in print In addition, there are hundreds of great examples available on the Parallax CD and web site (www.parallaxinc.com). Also, Nut & Volts Magazine (www.nutsvolts.com / 1-800-783-4624) is a national electronic hobbyist's...
Page 8
Prefix magazine that features monthly articles featuring the BASIC Stamps. This is an excellent resource for beginners and experts alike! For a sample of the BASIC Stamp articles, visit their web site. Packing List The BASIC Stamps are available in many different forms. You may have received them in a Starter Kit in a special limited-time package or individually.
Welcome to the wonderful world of BASIC Stamp microntrollers. BASIC Stamp microcontrollers have been in use by engineers and hobbyists since we first introduced them in 1992. As of July 2000, Parallax customers have put more than 200,000 BASIC Stamp modules into use. Over this eight- year period, the BASIC Stamp line of controllers has evolved into five models and many physical package types, explained below.
Page 11
1: Introduction to the BASIC Stamps The BASIC Stamp 1 is available in the above three physical packages. The BASIC Stamp 1 Rev. D (simply called the Rev. D), see Figure 1.1, includes prototyping area suitable for soldering electronic components. The BS1-IC (Figure 1.2) uses surface mount components to fit in a small 14-pin SIP package.
Introduction to the BASIC Stamps BASIC Stamp 2 Figure 1.4: BASIC Stamp 2 SOUT (Rev. E) (BS2-IC) BS2-IC .62“ (16 mm) 2.0“ (51 mm) Figure 1.5: OEM BASIC Stamp 2 (Rev. A) (27290 or 27291) OEM BASIC Stamp 2 (c) 1999 Rev A XTAL 0.1“...
Page 13
1: Introduction to the BASIC Stamps Table 1.2: BASIC Stamp 2 Pin Name Description Descriptions. Serial Out: connects to PC serial port RX pin (DB9 pin 2 / DB25 SOUT pin 3) for programming. Serial In: connects to PC serial port TX pin (DB9 pin 3 / DB25 pin 2) for programming.
0.1“ (2.54 mm) 0.25“ (6 mm) The BASIC Stamp 2e is available in the above two physical packages. The BS2e-IC (Figure 1.6) uses surface mount components to fit in a small 24- pin DIP package. The OEMBS2e (Figure 1.7) features an easier-to-trace layout meant to aid customers who wish to integrate the BASIC Stamp 2e circuit directly into their design (as a lower-cost solution).
Page 15
1: Introduction to the BASIC Stamps Table 1.3: BASIC Stamp 2e Pin Name Description Descriptions. Serial Out: connects to PC serial port RX pin (DB9 pin 2 / DB25 SOUT pin 3) for programming. Serial In: connects to PC serial port TX pin (DB9 pin 3 / DB25 pin 2) for programming.
Introduction to the BASIC Stamps BASIC Stamp 2sx Figure 1.8: BASIC Stamp 2sx (Rev. SOUT B) (BS2sx-IC) BS2SX-IC .62“ (16 mm) 2.0“ (51 mm) Figure 1.9: OEM BASIC Stamp 2sx (Rev. A) (27294) (c) 2000 Rev A XTAL 0.1“ (2.54 mm) 0.25“...
Page 17
1: Introduction to the BASIC Stamps Table 1.4: BASIC Stamp 2sx Pin Name Description Descriptions. Serial Out: connects to PC serial port RX pin (DB9 pin 2 / DB25 SOUT pin 3) for programming. Serial In: connects to PC serial port TX pin (DB9 pin 3 / DB25 pin 2) for programming.
Page 19
1: Introduction to the BASIC Stamps Table 1.5: BASIC Stamp 2p Pin Name Description Descriptions. Serial Out: connects to PC serial port RX pin (DB9 pin 2 / DB25 SOUT pin 3) for programming. Serial In: connects to PC serial port TX pin (DB9 pin 3 / DB25 pin 2) for programming.
Introduction to the BASIC Stamps Development Boards We provide a number of development boards to make using the BASIC Stamps more convenient. Below is a short description of the boards and their intended use. Please refer to the development board’s documentation (if any) for more details.
1: Introduction to the BASIC Stamps BASIC Stamp 2 Carrier Board (Rev. B) The BASIC Stamp 2 Carrier Board (also called the BS2 Carrier Board) is designed to accommodate the BS2-IC, BS2e-IC and BS2sx-IC modules. The BASIC Stamp 2 Carrier Board provides ample prototyping space for simple or moderate circuits.
Introduction to the BASIC Stamps BASIC Stamp Super Carrier (Rev. A) The BASIC Stamp Super Carrier board is designed to accommodate the BS1-IC, BS2-IC, BS2e-IC and BS2sx-IC modules. This board provides ample prototyping space for simple or moderate circuits. Figures 1.14 and 1.15 show the board with the BS1-IC or BS2-IC properly inserted into the sockets.
Introduction to the BASIC Stamps Board of Education (Rev. B) The Board of Education is designed to accommodate the BS2-IC, BS2e-IC and BS2sx-IC modules. This board provides a small breadboard for quickly prototyping simple or moderate circuits. Figure 1.17 shows the board with the BS2-IC properly inserted into the socket.
1: Introduction to the BASIC Stamps (Rev. C) BASIC Stamp Activity Board The BASIC Stamp Activity Board (sometimes called BSAC) is designed to accommodate the BS1-IC, BS2-IC, BS2e-IC, BS2sx-IC and BS2p24-IC modules. This board provides a number of prewired components for quick prototyping of common, simple circuits.
Page 26
Introduction to the BASIC Stamps find additional information on the board and source code for the BS1 and BS2 on the Parallax CD. Figure 1.19: BASIC Stamp Rev C Stamp Activity Board Activity Board (shown with BS2-IC (c)1998 Aout properly inserted). Note, the X8 jumper should be in the "2"...
1: Introduction to the BASIC Stamps Guidelines and Precautions When using the BASIC Stamp, or any IC chip, please follow the guidelines below. Be alert to static sensitive devices and static-prone situations. The BASIC Stamp, like other IC’s, can be damaged by static discharge that...
Page 28
BASIC Stamp Programming Connections: Parallax, Inc. suggests using the cables provided in the BASIC Stamp Starter Kit for programming the BASIC Stamps. When those cables are not available, you may create your own by duplicating the following diagrams in your cables and circuits.
Page 29
1: Introduction to the BASIC Stamps still will not be able to communicate with the BASIC Stamp. It is vital that you check your connections with a meter and verify the pin numbering to avoid problems like this. 1 VIN 25 GND 2 VSS 3 PC0...
Page 30
Introduction to the BASIC Stamps Page 28 • BASIC Stamp Programming Manual 2.0b • www.parallaxinc.com...
2: Quick Start Guide Quick Start Introduction This chapter is a quick start guide to connecting the BASIC Stamp to the PC and programming it. Without even knowing how the BASIC Stamp functions, you should be able to complete the exercise below. This exercise assumes you have a BASIC Stamp and one of the development boards shown in Chapter 1.
Page 32
BS2p Stamp2p.exe Stampw.exe (v1.1+) a) If using the Parallax CD, go to the Software -> BASIC Stamp -> Windows section (or the DOS section) to locate and run the software). b) If using the Windows software, it may prompt you with a list of serial ports.
Page 33
2: Quick Start Guide 5) Enter the following two lines of PBASIC code in the editor window (change the "BS2" to the proper name of your module, as indicated below): ' { $STAMP BS2 } DEBUG "Hello World!" a) Note: The above code is written for a BASIC Stamp 2. Change the "BS2"...
1 available serial port (1 available parallel port for BS1). (Note: though it is suggested that the BASIC Stamp Editor be installed on your hard drive, it is not required. The software may be run right off the Parallax CD). To install the BASIC Stamp Editor: NSTALLING THE SOFTWARE Insert the Parallax CD into the CD-ROM drive.
Page 36
Using the BASIC Stamp Editor Software Interface (Windows) This section describes the Windows version of the BASIC Stamp Editor. See the "Software Interface (DOS)" section for information on using the DOS version. The Windows version supports multiple BASIC Stamp modules and is recommended for most tasks. The BASIC Stamp Windows Editor, shown in Figure 3.1 was designed to be easy to use and mostly intuitive.
Page 37
3: Using the BASIC Stamp Editor has never been saved to disk will default to “Untitled#”; where # is an automatically generated number. A user can switch between source code files by simply pointing and clicking on a file’s tab. Figure 3.2: Example Editor tabs.
Page 38
BS2e, BS2sx or BS2p, enter one of the following lines into your code, respectively. ‘ { $STAMP BS2e } 'This indicates to use the BASIC Stamp 2e ‘ { $STAMP BS2sx } 'This indicates to use the BASIC Stamp 2sx ‘...
Page 39
BASIC Stamp for a single application. Each of the files within the project is downloaded into a separate "program slot". Only the BASIC Stamp 2e, 2sx and 2p modules support projects (multiple program slots).
Page 40
Using the BASIC Stamp Editor ‘ { $STAMP BS2e, file2, file3, …, file8 } Use this form of the STAMP directive if a project, consisting of multiple files, is desired. This directive must be entered into the first program (to be downloaded into program slot 0) and not in any of the other files in the project.
Page 41
3: Using the BASIC Stamp Editor indicating that there are two unrelated files open "Sample.bsx" and "NextProgram.bsx" and each will be downloaded into program slot 0. Go back to the first program and enter the STAMP directive using the project format. Use "NextProgram" as the File2 argument. For example: ' { $STAMP BS2sx, NextProgram.bsx } Then tokenize the code by pressing F7 or selecting Check Syntax...
Page 42
Using the BASIC Stamp Editor Table 3.2: Project Download Download Mode Function Modes. This mode will cause only the source code files that were modified since the last download to be downloaded next time. If no files have been modified since the last download, or the Modified (default) entire project has just been loaded into the editor, all the files will be downloaded next time.
Page 43
3: Using the BASIC Stamp Editor The following tables list the available keyboard shortcuts within the BASIC Stamp Windows Editor. Table 3.3: Shortcut Keys for File File Functions Functions (Windows editor). Shortcut Key Function Ctrl+O Open a source code file into the Editor window. Ctrl+S Save current source code file to disk.
Page 44
Each of the files within the project must be downloaded into a separate "program slot". Only the BASIC Stamp 2e, 2sx and 2p modules support projects (multiple program slots). Page 42 • BASIC Stamp Programming Manual 2.0b • www.parallaxinc.com...
Page 45
3: Using the BASIC Stamp Editor For BASIC Stamp projects (consisting of multiple programs), the BASIC Stamp DOS Editor must be used to individually load and download each of the files into the appropriate slot. Keep in mind that the DOS editor can only load up one source code file at a time.
Page 46
Using the BASIC Stamp Editor memory you have used and how much remains. (You may also press the space bar to cycle through similar maps of EEPROM program memory.) Two important points to remember about this map are, 1) it only indicates how your program will be downloaded to the BASIC Stamp;...
4: BASIC Stamp Architecture – Memory Organization This chapter provides detail on the architecture (RAM usage) and math functions of the BS1, BS2, BS2e, BS2sx and BS2p. The following icons will appear to indicate where there are differences between versions of the BASIC Stamp: One or more of these icons indicates the item applies only to the BS1, BS2, BS2e, BS2sx or BS2p, respectively.
Page 48
BASIC Stamp Architecture – Memory Organization You may assign other names (symbols) to these RAM registers as shown in section "Defining and Using Variables", below. When the BS1 is powered up, or reset, all memory locations are cleared to 0, so all pins are inputs (DIRS = %00000000). Also, if the PBASIC program sets all the I/O pins to outputs (DIRS = %11111111), then they will initially output low, since the output latch (PINS) is cleared to all zeros upon power-up or reset, as well.
Page 49
4: BASIC Stamp Architecture – Memory Organization the BASIC Stamp cannot change its state. A pin that is an output is set to the state indicated by the corresponding bit of the OUTS register. When the BASIC Stamp is powered up, or reset, all memory locations are cleared to 0, so all pins are inputs (DIRS = %0000000000000000).
Page 50
BASIC Stamp Architecture – Memory Organization circuit connected the I/O pin to ground, the corresponding bit of INS would be low. If a pin was set to an output mode and the pin's state was set to a high level (within OUTS), the corresponding bit of INS would be high.
4: BASIC Stamp Architecture – Defining Variables byte). Unlike I/O variables, there’s no reason that your program variables have to be stuck in a specific position in the BASIC Stamp’s physical memory. A byte is a byte regardless of its location. And if a program uses a mixture of variables of different sizes, it can be a pain in the neck to logically dole them out or allocate storage.
Page 52
BASIC Stamp Architecture – Defining Variables See Appendix B for a list of PBASIC keywords. PBASIC does not distinguish between upper and lower case, so the names MYVARIABLE, myVariable, and MyVaRiAbLe are all equivalent. For the BS1, the RegisterName is one of the predefined "fixed" variable names, such as W0, W1, B0, B1, etc.
4: BASIC Stamp Architecture – Defining Arrays The above example will create a bit-sized variable called Mouse, and nibble-sized variable called Cat, a byte-size variable called Dog and a word-sized variable called Rhino. Unlike in the BS1, these variable declarations don't point to a specific location in RAM. Instead, we only specified the desired size for each variable;...
Page 54
BASIC Stamp Architecture – Defining Arrays MyBytes BYTE(10) ' Define 10-byte array. Index ' Define normal nibble variable. FOR Index = 0 TO 9 ' Repeat with Index= 0,1,2...9 MyBytes(Index) = Index * 13 ' Write index*13 to each cell of array. NEXT FOR Index = 0 TO 9 ' Repeat with Index= 0,1,2...9...
4: BASIC Stamp Architecture – Aliases and Modifiers This feature is how the "string" capabilities of the DEBUG and SEROUT command expect to work. A string is simply a byte array used to store text. See the "Displaying Strings (Byte Arrays)" section in the DEBUG command description for more information.
Page 56
BASIC Stamp Architecture – Aliases and Modifiers Table 4.3: BS2, BS2e, BS2sx and Symbol Definition BS2p Variable Modifiers. LOWBYTE low byte of a word HIGHBYTE high byte of a word BYTE0 byte 0 (low byte) of a word BYTE1 byte 1 (high byte) of a word LOWNIB low nibble of a word or byte HIGHNIB...
Page 57
4: BASIC Stamp Architecture – Aliases and Modifiers If you looked closely at that example, you probably thought it was a misprint. Shouldn’t MyBytes.LOWNIB(1) give you the low nibble of byte 1 of the array rather than the high nibble of byte 0? Well, it doesn’t. The modifier changes the meaning of the index value to match its own size.
BASIC Stamp Architecture – Constants and Expressions The BS2e, BS2sx and BS2p have some additional RAM called Scratch Pad RAM. The BS2e and BS2sx have are 64 bytes of Scratch Pad RAM (0 – 63) RAM. CRATCH and the BS2p has 128 bytes of Scratch Pad RAM (0 – 127). Scratch Pad RAM can only be accessed with the GET and PUT commands (see the GET and PUT command descriptions for more information) and cannot have variable names assigned to it.
Page 59
4: BASIC Stamp Architecture – Constants and Expressions You can assign names to constants in a similar fashion to how variables are declared. On a BS1, it is identical to variable declarations and on the other BASIC Stamps you use the CON directive. Here is the syntax: SYMBOL Name = ConstantValue...
Page 60
BASIC Stamp Architecture – Constants and Expressions help, but you might accidentally change some 3s that weren’t numbers of cheers, too. However, if you made smart use of a named constant, all you would have to do is change 3 to 5 in one place, the constant's declaration: SYMBOL Cheers ‘...
4: BASIC Stamp Architecture – Number Representations The BASIC Stamp, like any computer, excels at math and logic. However, UNTIME ATH AND OGIC being designed for control applications, the BASIC Stamp does math a little differently than a calculator or spreadsheet program. This section will help you understand BASIC Stamp numbers, math, and logic.
BASIC Stamp Architecture – Order of Operations On the BS2, BS2e, BS2sx and BS2p, not all of the math or logic operations HEN IS UNTIME in a program are solved by the BASIC Stamp. The editor software solves operations that define constants before the program is downloaded to the BASIC Stamp.
Page 63
4: BASIC Stamp Architecture – Order of Operations You may recall that the order in which you do a series of additions and subtractions doesn’t affect the result. The expression 12+7-3+22 works out the same as 22-3+12+7. However, when multiplication or division are involved, it’s a different story;...
BASIC Stamp Architecture – Math and Operators right. If you wanted to be even more specific, you could write 12 + ((3*2)/4). When there are parentheses within parentheses, the BASIC Stamp works from the innermost parentheses outward. Parentheses placed within parentheses are called nested parentheses. The BASIC Stamp performs all math operations by the rules of positive NTEGER integer math.
4: BASIC Stamp Architecture – Math and Operators 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 BASIC Stamp 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 higher- order bits are discarded (truncated).
BASIC Stamp Architecture – ABS, COS, DCD, ~, - The Absolute Value operator (ABS) converts a signed (two’s complement) : ABS BSOLUTE ALUE 16-bit number to its absolute value. The absolute value of a number is a positive number representing the difference between that number and 0. For example, the absolute value of -99 is 99.
4: BASIC Stamp Architecture – NCD, SIN -- or -- Result WORD Result = 99 ' Put -99 (2's complement format) into Result. DEBUG SDEC ? Result ' Display it on the screen as a signed #. Result = - Result ' Negate the value DEBUG SDEC ? Result ' Display it on the screen as a signed #.
BASIC Stamp Architecture – SQR To convert brads to degrees, multiply by 180 then divide by 128. To convert degrees to brads, multiply by 128, then divide by 180. Here’s a small program that demonstrates the SIN operator: Degr WORD ' Define variables.
4: BASIC Stamp Architecture – +, -, * The Addition operator (+) adds 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 of addition is larger than 65535, the carry bit will be lost.
BASIC Stamp Architecture – **, */ than 65535, the excess bits will be lost. Multiplication of signed variables will be correct in both number and sign, provided that the result is in the range -32767 to +32767. SYMBOL Value1 = SYMBOL Value2 = Value1= 1000...
4: BASIC Stamp Architecture – / 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). The */ (star- slash) instruction gives you an excellent workaround for the BASIC Stamp's integer-only math.
BASIC Stamp Architecture – //, MIN A workaround to the inability to divide signed numbers is to have your program divide absolute values, then negate the result if one (and only one) of the operands was negative. All values must lie within the range of -32767 to +32767.
4: BASIC Stamp Architecture – MAX Value MIN Limit Where Value is a constant or variable value to perform the MIN function upon and Limit is the minimum value that Value is allowed to be. Its logic is, ‘if Value is less than Limit, then make result = Limit; if Value is greater than or equal to Limit, make result = Value.’...
BASIC Stamp Architecture – DIG, <<, >> 65535+1 MAX 65535 will result in 0 because of the way fixed-size integers wrap around. SYMBOL Value1 = W0 SYMBOL Value2 = W1 FOR Value1= 0 TO 100 STEP 10 ' Walk value of Value1 from 0 to 100. Value2 = Value1 MAX 50 ' Use MAX to clamp at 50.
4: BASIC Stamp Architecture – REV, &, | value right n number of times has the same effect as dividing that number by 2 to the n power. For instance 100 >> 3 (shift the bits of the decimal number 100 right three places) is equivalent to 100 / 2 .
BASIC Stamp Architecture – ^ 0 OR 0 = 0 0 OR 1 = 1 1 OR 0 = 1 1 OR 1 = 1 The result returned by | will contain 1s in any bit positions in which one or the other (or both) input values contain 1s.
4: BASIC Stamp Architecture – &/, |/, ^/ The And Not operator (&/) returns the bitwise AND NOT of two values. : &/ Each bit of the values is subject to the following logic: 0 AND NOT 0 = 0 0 AND NOT 1 = 0 1 AND NOT 0 = 1 1 AND NOT 1 = 0...
Page 78
BASIC Stamp Architecture – ^/ 0 XOR NOT 0 = 1 0 XOR NOT 1 = 0 1 XOR NOT 0 = 0 1 XOR NOT 1 = 1 The result returned by ^/ will contain 1s in any bit positions in which the first value and second values are equal.
5: BASIC Stamp Command Reference This chapter provides detail on all the available PBASIC instructions for the BS1, BS2, BS2e, BS2sx and BS2p. The following icons will appear to indicate where there are differences between versions of the BASIC Stamp: One or more of these icons indicates the item applies only to the BS1, BS2, BS2e, BS2sx or BS2p, respectively.
Page 80
BASIC Stamp Command Reference RAM ACCESS Read Scratch Pad RAM byte into variable. Write byte into Scratch Pad RAM. NUMERICS Optional instruction perform variable manipulation, such as A=5, B=A+2, etc. This instruction is not required and only exists on the BASIC Stamp 1.
Page 81
5: BASIC Stamp Command Reference IOTERM Activates specified I/O pin group. POLLIN Specify pin and state for a polled-interrupt. POLLOUT Specify pin and state for output upon a polled- interrupt. POLLMODE Specifies the polled-interrupt mode. ASYNCHRONOUS SERIAL I/O SERIN Input data in an asynchronous serial stream. Output data in an asynchronous serial stream.
Page 82
BASIC Stamp Command Reference SOUND SOUND Generate tones or white noise. FREQOUT Generate one or two sine waves of specified frequencies. DTMFOUT Generate DTMF telephone tones. POWER CONTROL Nap for a short period. Power consumption is reduced. Sleep for 1-65535 seconds. Power consumption is SLEEP reduced.
5: BASIC Stamp Command Reference - AUXIO AUXIO BS2e BS2sx BS2p AUXIO Function Switch from control of main I/O pins to auxiliary I/O pins (on the BS2p40 only). Quick Facts Table 5.1: AUXIO Quick Facts. BS2p 0 – 15 (just like main I/O, but after AUXIO command, all references affect I/O pin IDs physical pins 21 –...
Page 84
AUXIO - BASIC Stamp Command Reference Demo Program (AUX_MAIN_TERM.bsp) ' This program demonstrates the use of the AUXIO, MAINIO and IOTERM commands to NOTE: This is written for the BS2p ' affect I/O pins in the auxiliary and main I/O groups. but its effects can only be seen on the 40-pin version: the BS2p40.
5: BASIC Stamp Command Reference - BRANCH BRANCH BS2e BS2sx BS2p BRANCH Offset, ( Address0, Address1, ...AddressN ) BRANCH Offset, [ Address0, Address1, ...AddressN ] Function Go to the address specified by offset (if in range). • Offset is a variable/constant/expression (0 – 255) that specifies the NOTE: Expressions are not allowed as arguments on the BS1.
Page 86
BRANCH - BASIC Stamp Command Reference Demo Program (BRANCH.bas) This program shows how the value of Idx controls the destination of the BRANCH instruction. '{$STAMP BS1} ‘STAMP directive (specifies a BS1) SYMBOL Start: FOR Idx = 0 to 3 DEBUG “Idx: “, #Idx BRANCH Idx, (Case0, Case1, Case2) ‘If Idx = 0..2 branch to specified label GOTO Start...
5: BASIC Stamp Command Reference - BUTTON BUTTON BS2e BS2sx BS2p BUTTON Pin, DownState, Delay, Rate, Workspace, TargetState, Address Function Debounce button input, perform auto-repeat, and branch to address if button is in target state. Button circuits may be active-low or active-high. NOTE: Expressions are not •...
Page 88
BUTTON - BASIC Stamp Command Reference demonstration of switch bounce, see the demo program for the Count instruction.) BUTTON also lets PBASIC react to a button press the way your computer keyboard does to a key press. When you press a key, a character immediately appears on the screen.
Page 89
5: BASIC Stamp Command Reference - BUTTON Demo Program (BUTTON.bas) Connect the active-low circuit shown in Figure 5.1 to pin P0 of the BS1. When you press the button, the Debug screen will display an asterisk (*). Feel free to modify the program to see the effects of your changes on the way BUTTON responds.
5: BASIC Stamp Command Reference - COUNT COUNT BS2e BS2sx BS2p COUNT Pin, Period, Variable Function Count the number of cycles (0-1-0 or 1-0-1) on the specified pin during the Period time frame and store that number in Variable. • Pin is a variable/constant/expression (0 – 15) that specifies the I/O pin to use.
Page 92
COUNT - BASIC Stamp Command Reference If you use COUNT on slowly changing analog waveforms like sine waves, you may find that the value returned is higher than expected. This is because the waveform may pass through the BASIC Stamp’s 1.4-volt logic threshold slowly enough that noise causes false counts.
5: BASIC Stamp Command Reference - DATA DATA BS2e BS2sx BS2p (See EEPROM) {Symbol} DATA DataItem {, DataItem…} Function Write data to the EEPROM during program download. • Symbol is an optional, unique symbol name that will be automatically defined as a constant equal to the location number of the first data item.
Page 94
DATA - BASIC Stamp Command Reference DATA 72, 69, 76, 76, 79 DATA 104, 101, 108, 108, 111 The first DATA directive will start at location 0 and increment the pointer for each data value it stores (1, 2, 3, 4 and 5). The second DATA directive will start with the pointer value of 5 and work upward from there.
Page 95
5: BASIC Stamp Command Reference - DATA program can then use the MyNumbers constant as a reference to the start of the data within a READ or WRITE command. Each DATA directive can have a unique symbol preceding it, allowing you to reference the data defined at different locations.
Page 96
DATA - BASIC Stamp Command Reference A common use for DATA is to store strings; sequences of bytes RITING TEXT STRINGS representing text. PBASIC converts quoted text like "A" into the corresponding ASCII character code (65 in this case). To make data entry easier, you can place quotes around a whole chunk of text used in a DATA directive, and PBASIC will understand it to mean a series of bytes (see the last line of code below).
Page 97
5: BASIC Stamp Command Reference - DATA Result WORD DATA word 1125 READ 0, Result.LOWBYTE READ 1, Result.HIGHBYTE DEBUG DEC Result This code would write the low-byte and high-byte of the number 1125 into locations 0 and 1 during download. When the program runs, the two READ commands will read the low-byte and high-byte out of EEPROM (reconstructing it in a word-size variable) and then display the value on the screen.
Page 98
DATA - BASIC Stamp Command Reference DATA "the character at the EEPROM location pointed to by it, and", CR DATA "prints it to the screen until if finds a byte with a value", CR DATA "of 255.", CR, CR, 255 '-----Main Routine----- Main: FOR PhraseNum = 1 TO 6...
5: BASIC Stamp Command Reference - DEBUG DEBUG BS2e BS2sx BS2p DEBUG OutputData {, OutputData} Function Display information on the PC screen within the BASIC Stamp editor program. This command can be used to display text or numbers in various formats on the PC screen in order to follow program flow (called debugging) or as part of the functionality of the BASIC Stamp application.
Page 100
DEBUG - BASIC Stamp Command Reference DEBUG can also print and format numbers (values) from both constants and variables. The formatting methods for DEBUG are very different for the BS1, than for any other BASIC Stamp. Please read the appropriate sections, below, carefully.
Page 101
5: BASIC Stamp Command Reference - DEBUG Two pre-defined symbols, CR and CLS, can be used to send a carriage- CLS (BS1). SING return or clear-screen command to the Debug Terminal. The CR symbol will cause the Debug Terminal to start a new line and the CLS symbol will cause the Debug Terminal to clear itself and place the cursor at the top-left corner of the screen.
Page 102
DEBUG - BASIC Stamp Command Reference DEBUG Expressions are allowed within the DEBUG command arguments as well. XPRESSIONS IN COMMANDS In the above code, DEBUG DEC x+25 would yield "95" and DEBUG DEC x*10/2-3 would yield "322". Table 5.5: DEBUG Formatters. Formatter Description Displays "symbol = x"...
Page 103
5: BASIC Stamp Command Reference - DEBUG Signed numbers are preceded with a space ( ) or a minus sign (-) to ISPLAYING SIGNED VS UNSIGNED NUMBERS indicate a positive or negative number, respectively. Normally, any number displayed by the BASIC Stamp is shown in its unsigned (positive) form without any indicator.
Page 104
DEBUG - BASIC Stamp Command Reference BYTE BYTE x = 100 y = 250 DEBUG DEC ? x ' Show decimal value of x DEBUG DEC ? y ' Show decimal value of y The display would look something like this: x = 100 y = 250 The ? formatter always displays data in the form "symbol = value"...
Page 105
5: BASIC Stamp Command Reference - DEBUG Using DEC4 in the same code would display "0165". DEC3 would display "165". What would happen if we used DEC2? Regardless of the number, the BASIC Stamp will ensure that it is always the exact number of digits you specified.
Page 106
DEBUG - BASIC Stamp Command Reference To specify a fixed-width format for the STR formatter, use the form STR IXED WIDTH STRINGS x\n; where x is the byte array and n is the number of characters to print. Changing the DEBUG line in the example above to: DEBUG STR x\2 would display "AB"...
Page 107
5: BASIC Stamp Command Reference - DEBUG received, the Debug Terminal wraps back around to the opposite side of the screen. The Clear Right control character clears the characters that appear to the right of, and on, the cursor's current position. The cursor is not moved by this action.
Page 108
DEBUG - BASIC Stamp Command Reference in terms of function (on a BS2). The DEBUG line actually takes less program space, and is obviously easier to type. You may view DEBUG's output using a terminal program set to the above parameters, but you may have to modify either your carrier board or the serial cable to temporarily disconnect pin 3 of the BASIC Stamp (pin 4 of the DB-9 connector).
5: BASIC Stamp Command Reference - DTMFOUT DTMFOUT BS2e BS2sx BS2p DTMFOUT Pin, {OnTime, OffTime,} [ Tone {, Tone…} ] Function Generate dual-tone, multifrequency tones (DTMF, i.e., telephone “touch” tones). • Pin is a variable/constant/expression (0 – 15) that specifies the I/O pin to use.
Page 110
OnTime and OffTime values: DTMFOUT 0, 500, 100, [ 6, 2, 4, 8, 3, 3, 3] ' Call Parallax, slowly. In this example, on a BS2 the OnTime is set to 500 ms (1/2 second) and OffTime to 100 ms (1/10th second).
Page 111
5: BASIC Stamp Command Reference - DTMFOUT The BASIC Stamp controller is a purely digital device. DTMF tones are ECHNICAL ACKGROUND analog waveforms, consisting of a mixture of two sine waves at different audio frequencies. So how does a digital device generate analog output? The BASIC Stamp creates and mixes the sine waves mathematically, then uses the resulting stream of numbers to control the duty cycle of a very fast pulse-width modulation (PWM) routine.
Page 112
Information DATA $15,$20,$55,$51,$21,$2F ' Phone: 1-520-555-1212 '-----Main Routine----- FOR Phone = 0 TO 2 ' For each phone #, get location of # in EEPROM. LOOKUP Phone,[Parallax,ParallaxFax,Information],EEloc Dial: READ EEloc,EEByte ' Retrieve byte from EEPROM. FOR HiLo = 0 to 1 ' Dial upper and lower digits.
5: BASIC Stamp Command Reference - EEPROM EEPROM BS2e BS2sx BS2p EEPROM {Location,} ( DataItem {, DataItem,…} ) (See DATA) Function Write data to the EEPROM during program download. • Location is an optional variable/constant (0 – 255) that specifies the starting location in the EEPROM at which data should be stored.
Page 114
EEPROM - BASIC Stamp Command Reference subsequent EEPROM directives start with the pointer value left by the previous EEPROM directive. For example, if the program contains: EEPROM (72, 69, 76, 76, 79) EEPROM (104, 101, 108, 108, 111) The first EEPROM directive will start at location 0 and increment the pointer for each data value it stores (1, 2, 3, 4 and 5).
Page 115
5: BASIC Stamp Command Reference - EEPROM EEPROM (72, 69, 76, 76, 79) EEPROM ("H", "E", "L", "L", "O") EEPROM ("HELLO") All three lines of code, above, will result in the numbers 72, 69, 76, 76, and 79 being stored into EEPROM upon downloading. These numbers are simply the ASCII character codes for "H", "E", "L", "L", and "O", respectively.
Page 116
EEPROM - BASIC Stamp Command Reference Demo Program (EEPROM.bas) This program stores a couple of text strings into EEPROM with the EEPROM directive and then sends them, one character at a time via the SEROUT command. This is a good demonstration of how to save program space by storing large amounts of data in EEPROM directly, rather than embedding the data into SEROUT commands.
5: BASIC Stamp Command Reference - END BS2e BS2sx BS2p Function End the program, placing the BASIC Stamp into low-power mode indefinitely. This is equivalent to having a program that does not loop continuously; once the BASIC Stamp reaches the end of the PBASIC program, it enters low-power mode indefinitely.
5: BASIC Stamp Command Reference – FOR…NEXT FOR…NEXT BS2e BS2sx BS2p FOR Counter = StartValue TO EndValue {STEP {-} StepValue} … NEXT {Counter} FOR Counter = StartValue TO EndValue {STEP StepValue} … NEXT Function Create a repeating loop that executes the program lines between FOR and NEXT, incrementing or decrementing Counter according to StepValue until the value of the Counter variable passes the EndValue.
Page 120
FOR…NEXT - BASIC Stamp Command Reference Explanation FOR...NEXT loops let your program execute a series of instructions for a FOR…NEXT. IMPLEST FORM OF specified number of repetitions (called iterations). By default, each time through the loop, the counter variable is incremented by 1. It will NOTE: On the BS1, the loop will continue until Counter has gone...
Page 121
5: BASIC Stamp Command Reference – FOR…NEXT Stamps do this automatically when the StartValue is greater than the EndValue. Examples of both are shown below: SYMBOL Reps = ' Counter for the FOR/NEXT loop. FOR Reps = 3 TO 1 STEP -1 ' Repeat with Reps = 3, 2, 1.
Page 122
FOR…NEXT - BASIC Stamp Command Reference Reps BYTE ' Counter for the FOR/NEXT loop. StartVal BYTE EndVal BYTE NOTE: The increment/decrement StartVal = 1 ' Initialize StartVal to 1 direction of the FOR…NEXT loop EndVal = 3 ' Initialize EndVal to 3 cannot be changed on the BS1.
Page 123
5: BASIC Stamp Command Reference – FOR…NEXT NOTE: For BS1's, change line 1 to Reps WORD ' Counter for the loop. SYMBOL Reps = W0 FOR Reps = 0 TO 65535 STEP 3000 ' Each loop add 3000. and line 3 to DEBUG DEC ? Reps ' Show reps in debug window.
Page 124
FOR…NEXT - BASIC Stamp Command Reference Reps BYTE ' Counter for the loop. FOR Reps = 10 to 300 ' Each loop add 1. DEBUG DEC ? Reps ' Show reps in debug window. NEXT Reps still rolls over to 0, as before, however, this time it is outside the range of 10 to 255.
5: BASIC Stamp Command Reference – FREQOUT FREQOUT BS2e BS2sx BS2p (See SOUND) FREQOUT Pin, Period, Freq1 {, Freq2} Function Generate one or two sine-wave tones for a specified period. • Pin is a variable/constant/expression (0 – 15) that specifies the I/O pin to use.
Page 126
FREQOUT - BASIC Stamp Command Reference FREQOUT 2, 1000, 2500, 3000 This will generate a 2500 Hz and 3000 Hz tone (on the BS2) for 1 second. The frequencies will mix together for a chord- or bell-like sound. To generate a silent pause, specify frequency value(s) of 0. Figure 5.4: Example RC filter Driving an Audio Amplifier circuits for driving an audio amplifier...
Page 127
5: BASIC Stamp Command Reference – FREQOUT '{$STAMP BS2} 'STAMP directive (specifies a BS2) BYTE ' Counter for position in tune. WORD ' Frequency of note for FREQOUT. 2092 ' C note 2348 ' D note 2636 ' E note 3136 ' G note ' Silent pause (rest).
5: BASIC Stamp Command Reference – GET BS2e BS2sx BS2p GET Location, Variable Function Read value from Scratch Pad RAM Location and store in Variable. • Location is a variable/constant/expression (0 – 63 for Bs2e and BS2sx and 0 – 127 for BS2p) that specifies the Scratch Pad RAM location to read from.
Page 130
GET - BASIC Stamp Command Reference contains the current program slot that will be used for the READ and WRITE commands. See the demo program below for an example of use. Demo Program (GETPUT1.bsx) ' This example demonstrates the use of the GET and PUT commands. First, location 63 NOTE: This is written for the BS2sx ' is read using GET to display the currently running program number.
5: BASIC Stamp Command Reference – GOSUB GOSUB BS2e BS2sx BS2p GOSUB Address Function Store the address of the next instruction after GOSUB, then go to the point in the program specified by Address; with the intention of returning to the stored address.
Page 132
GOSUB - BASIC Stamp Command Reference Try the example below: GOSUB Hello DEBUG "How are you?" Hello: DEBUG "Hello my friend.", CR RETURN The above code will start out by GOSUB'ing to the section of code beginning with the label Hello. It will print "Hello my friend." on the screen then RETURN to the line after the GOSUB…...
Page 133
5: BASIC Stamp Command Reference – GOSUB Demo Program (GOSUB.bas) ' 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.
Page 134
GOSUB - BASIC Stamp Command Reference FOR Rounds = 1 TO 3 ' Go three rounds. DEBUG CLS,"Pick a number from 1 to 10", CR GOSUB PickANumber ' Get a random number, 1-10. PAUSE 2000 ' Dramatic pause. DEBUG "My number was: ", DEC MyNum ' Show the number.
5: BASIC Stamp Command Reference – GOTO GOTO BS2e BS2sx BS2p GOTO Address Function Go to the point in the program specified by Address. • Address is a label that specifies where to go. Quick Facts Table 5.15: GOTO Quick Facts. BS1, BS2, BS2e, BS2sx and BS2p Max.
5: BASIC Stamp Command Reference – HIGH HIGH BS2e BS2sx BS2p HIGH Pin Function Make the specified pin output high. NOTE: Expressions are not • Pin is a variable/constant/expression (0 – 15) that specifies which allowed as arguments on the BS1. I/O pin to set high.
Page 138
HIGH - BASIC Stamp Command Reference Demo Program (HIGH.bs2) ' This simple program sets I/O pin 0 high for 1/2 second and low for 1/2 second NOTE: This is written for the BS2 ' in an endless loop. but can be used for the BS1, BS2e, '{$STAMP BS2} 'STAMP directive (specifies a BS2) BS2sx and BS2p also.
5: BASIC Stamp Command Reference – I2CIN I2CIN BS2e BS2sx BS2p I2CIN Pin, SlaveID, Address {\LowAddress}, [InputData] Function Receive data from a device using the I C protocol. • Pin is a variable/constant/expression (0 or 8) that specifies which I/O pins to use. I C devices require two I/O pins to communicate.
Page 140
I2CIN - BASIC Stamp Command Reference Explanation The I C protocol is a form of synchronous serial communication developed by Phillips Semiconductors. It only requires two I/O pins and both pins can be shared between multiple I C devices. The I2CIN command allows the BASIC Stamp to receive data from an I C device.
Page 141
5: BASIC Stamp Command Reference – I2CIN Value BYTE(13) I2CIN 0, $A1, 0, [Value] 'receive the ASCII value for "V" I2CIN 0, $A1, 0, [DEC Value] 'receive the number 3. I2CIN 0, $A1, 0, [HEX Value] 'receive the number $3A. I2CIN 0, $A1, 0, [BIN Value] 'receive the number %101.
Page 142
I2CIN - BASIC Stamp Command Reference Table 5.18: I2CIN Special Special Formatter Action Formatters. Input a character string of length L into an array. If specified, an STR ByteArray \L {\E} end character E causes the string input to end before reaching length L.
Page 143
5: BASIC Stamp Command Reference – I2CIN Every I C transmission session begins with a Start Condition and ends TART AND ONDITIONS AND CKNOWLEDGMENTS with a Stop Condition. Additionally, immediately after every byte is transmitted, an extra clock cycle is used to send or receive an acknowledgment signal (ACK).
Page 144
I2CIN - BASIC Stamp Command Reference WORD 'Index variable for address Check 'Index for checking returned values Result BYTE(16) '16-byte array for returned value WriteToEEPROM: DEBUG "Writing...", CR PAUSE 2000 FOR Idx = 0 TO 2047 STEP 16 'For all 2K locations, I2COUT 0, $A0+((Idx>>8)*2), Idx, [REP Idx>>4\16] 'Write 16 bytes at once PAUSE 5 DEBUG "Addr: ", DEC4 Idx, "-", DEC4 Idx+15, "...
5: BASIC Stamp Command Reference – I2COUT I2COUT BS2e BS2sx BS2p I2COUT Pin, SlaveID, Address {\LowAddress}, [OutputData] Function Send data to a device using the I C protocol. • Pin is a variable/constant/expression (0 or 8) that specifies which I/O pins to use. I C devices require two I/O pins to communicate.
Page 146
I2COUT - BASIC Stamp Command Reference Explanation The I C protocol is a form of synchronous serial communication developed by Phillips Semiconductors. It only requires two I/O pins and both pins can be shared between multiple I C devices. The I2COUT command allows the BASIC Stamp to send data to an I C device.
Page 147
5: BASIC Stamp Command Reference – I2COUT Value BYTE Value = 65 I2COUT 0, $A0, 0, [Value] 'send the ASCII value for "A" I2COUT 0, $A0, 0, [REP Value\5] 'send the ASCII value for "A" five times, ie: "AAAAA" I2COUT 0, $A0, 0, [DEC Value] 'send two characters, "6"...
Page 148
I2COUT - BASIC Stamp Command Reference you wish to communicate with. The lowest bit indicates whether this is a write operation (0) or a read operation (1). Figure 5.10 shows this format. Figure 5.10: SlaveID Format. The second byte, immediately following the SlaveID, is the Address. It indicates the 8-bit address (within the device) you would like to send data Some devices require more than 8 bits of address.
Page 149
5: BASIC Stamp Command Reference – I2COUT Every I C transmission session begins with a Start Condition and ends TART AND ONDITIONS AND CKNOWLEDGMENTS with a Stop Condition. Additionally, immediately after every byte is transmitted, an extra clock cycle is used to send or receive an acknowledgment signal (ACK).
Page 150
I2COUT - BASIC Stamp Command Reference DEBUG "Writing...", CR PAUSE 2000 FOR Idx = 0 TO 2047 STEP 16 'For all 2K locations, I2COUT 0, $A0+((Idx>>8)*2), Idx, [REP Idx>>4\16] 'Write 16 bytes at once PAUSE 5 DEBUG "Addr: ", DEC4 Idx, "-", DEC4 Idx+15, " Value: ", DEC3 Idx>>4 & $FF, CR NEXT PAUSE 2000 ReadFromEEPROM:...
Page 151
5: BASIC Stamp Command Reference – IF…THEN IF…THEN BS2e BS2sx BS2p IF Condition THEN Address Function Evaluate Condition and, if it is true, go to the point in the program marked by Address. • Condition is a statement, such as “x = 7” that can be evaluated as true or false.
Page 152
IF…THEN - BASIC Stamp Command Reference constants, or expressions. The following example is an IF…THEN command with a simple condition: IF…THEN IF 10 < 200 THEN Loop SIMPLE FORM OF This code will compare the number 10 to the number 200. If 10 is less than 200, the condition is true.
Page 153
5: BASIC Stamp Command Reference – IF…THEN IF -99 < 100 THEN IsLess DEBUG "Greater than or equal to 100" IsLess: DEBUG "Less than 100" Although –99 is obviously less than 100, the program will say it is greater. The problem is that –99 is internally represented as the two’s complement value 65437, which (using unsigned math) is greater than 100.
Page 154
IF…THEN - BASIC Stamp Command Reference counterpart: If one condition or the other (but not both) is true, then the statement is true. Table 5.24 below summarizes the effects of the conditional logic operators. NOTE: On the BS1, parentheses are not allowed within arguments. As with math, you can alter the order in which comparisons and logical operations are performed by using parentheses.
Page 155
5: BASIC Stamp Command Reference – IF…THEN IF NOT x = 100 then NoCent GOSUB Centennial ' IF x = 100 THEN GOSUB Centennial. NoCent: ' Program continues. Internally, the BASIC Stamp defines “false” as 0 and “true” as any value NTERNAL REPRESENTATION OF OOLEAN VALUES RUE VS...
Page 156
IF…THEN - BASIC Stamp Command Reference Demo Program (IFTHEN.bas) ' The program below generates a series of 16-bit random numbers and tests each to ' determine whether they're evenly divisible by 3. If a number is evenly 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.
5: BASIC Stamp Command Reference – INPUT INPUT BS2e BS2sx BS2p INPUT Pin Function Make the specified pin an input. • Pin is a variable/constant/expression (0 – 15) that specifies which NOTE: Expressions are not allowed as arguments on the BS1. The I/O pin to set to input mode.
Page 158
INPUT - BASIC Stamp Command Reference '{$STAMP BS1} 'STAMP directive (specifies a BS1) INPUT 7 ' Make I/O pin 7 an input. DEBUG "State of pin 7: ", #PIN7, CR PIN7 = 0 ' Write 0 to output latch. DEBUG "After 0 written to OUT7: ", #PIN7, CR OUTPUT 7 ' Make I/O pin 7 an output.
5: BASIC Stamp Command Reference – IOTERM IOTERM BS2e BS2sx BS2p IOTERM Port Function Switch control to main I/O pins or auxiliary I/O pins (on the BS2p40 only) depending on state of Port. • Port is a variable/constant/expression (0 – 1) that specifies which I/O port to use.
Page 160
IOTERM - BASIC Stamp Command Reference Note that the main I/O and auxiliary I/O pins are independent of each AND AUXILIARY PINS ARE INDEPENDENT AND UNAFFECTED BY other; the states of the main I/O pins remain unchanged while the CHANGES IN THE OPPOSITE GROUP program affects the auxiliary I/O pins, and vice versa.
5: BASIC Stamp Command Reference – LCDCMD LCDCMD BS2e BS2sx BS2p LCDCMD Pin, Command Function Send a command to an LCD display. • Pin is a variable/constant/expression (0 – 1 or 8 – 9) that specifies which I/O pins to use. The LCD requires, at most, seven I/O pins to operate.
Page 162
LCDCMD - BASIC Stamp Command Reference The above code will send the Scroll Left command (represented by the number 24) to the LCD whose enable pin is connected to I/O pin 1. This will cause the LCD display to scroll, or shift, the entire display one character to the left.
Page 163
5: BASIC Stamp Command Reference – LCDCMD shown above. This process is known as initializing the LCD and is the first thing your program should do upon starting up. The following code is a good example of LCD initialization. 'LCD's usually take more than 500 µs to power-up. This pause is InitLCD: PAUSE 1000 'to keep the BASIC Stamp from talking to the LCD too early.
Page 164
LCDCMD - BASIC Stamp Command Reference command and 64 is the location number. See the "Character Positioning" section, below, for more information. Table 5.27: Common LCD Command Description Commands. These are supported (in decimal) by LCDs with the Hitachi 44780 Do Nothing Don't perform any special operation.
Page 165
5: BASIC Stamp Command Reference – LCDCMD Table 5.28: All LCD Commands (for Command Code (in binary) Description advanced users). These are supported by LCDs with the Hitachi Clear entire display and move Clear Display 44780 controller. cursor home (address 0). Move cursor home and return Home Display display to home position.
Page 166
LCDCMD - BASIC Stamp Command Reference The number 128 tells the LCD we wish to move the cursor and 66 is the location number of the desired position. Similarly, sending just 128 (128 + 0) would move the cursor to the first character of the first line (the upper left character if the display is at the home position).
Page 167
5: BASIC Stamp Command Reference – LCDCMD Demo Program (LCDINIT.bsp) ' This program demonstrates initialization and printing on a 2 x 16 character LCD display. ' The set of "LCD constants", below, are provided as pre-defined and useful LCD commands, ' though only a few are actually used in this program.
Page 168
LCDCMD - BASIC Stamp Command Reference LCDCMD 1, FourBitMode 'Set buss to 4-bit mode LCDCMD 1, TwoLine5x8Font 'Set to 2-line mode with 5x8 font LCDCMD 1, DisplayOff 'Turn display off LCDCMD 1, DisplayOn 'Turn display on with blinking cursor LCDCMD 1, IncCrsr 'Set to auto-increment cursor (no display shift) LCDCMD 1, ClearDisplay 'Clear the display...
5: BASIC Stamp Command Reference – LCDIN LCDIN BS2e BS2sx BS2p LCDIN Pin, Command, [InputData] Function Receive data from an LCD display. • Pin is a variable/constant/expression (0 – 1 or 8 – 9) that specifies which I/O pins to use. The LCD requires, at most, seven I/O pins to operate.
Page 170
LCDIN - BASIC Stamp Command Reference The LCDIN command is used to send one instruction and then receive at LCDIN SIMPLE EXAMPLE least one data byte from the LCD's Character RAM or Display RAM. The following is an example of the LCDIN command: Char BYTE LCDIN 1, 128, [Char]...
Page 171
5: BASIC Stamp Command Reference – LCDIN Some possible uses of the LCDIN command are 1) in combination with the LCDOUT command to store and read data from the unused DRAM or CRAM locations (as extra variable space), 2) to verify that the data from a previous LCDOUT command was received and processed properly by the LCD, and 3) to read character data from CRAM for the purposes of modifying it and storing it as a custom character.
Page 172
LCDIN - BASIC Stamp Command Reference Table 5.31: LCDIN Special Special Formatter Action Formatters. Input a character string of length L into an array. If specified, an STR ByteArray \L {\E} end character E causes the string input to end before reaching length L.
5: BASIC Stamp Command Reference – LCDOUT LCDOUT BS2e BS2sx BS2p LCDOUT Pin, Command, [OutputData] Function Send data to an LCD display. • Pin is a variable/constant/expression (0 – 1 or 8 – 9) that specifies which I/O pins to use. The LCD requires, at most, seven I/O pins to operate.
Page 174
LCDOUT - BASIC Stamp Command Reference LCD's Character RAM or Display RAM. The following is an example of the LCDOUT command: LCDOUT 1, 1, ["Hello World!"] The above code will clear the LCD screen and then send "Hello World!" to the screen.
Page 175
5: BASIC Stamp Command Reference – LCDOUT Table 5.33: LCDOUT Conversion Conversion Type of Number Notes Formatters. Formatter DEC{1..5} Decimal, optionally fixed to 1 – 5 digits SDEC{1..5} Signed decimal, optionally fixed to 1 – 5 digits HEX{1..4} Hexadecimal, optionally fixed to 1 – 4 digits SHEX{1..4} Signed hexadecimal, optionally fixed to 1 –...
Page 176
LCDOUT - BASIC Stamp Command Reference Another use for the LCDOUT command is to access and create custom REATING CUSTOM CHARACTERS characters. The Hitachi 44780 controller has a built-in character set that is similar to the ASCII character set (at least for the first 128 characters). Most of these characters are stored in ROM and are not changeable, however, the first eight characters (ASCII 0 though 7) are programmable.
Page 177
5: BASIC Stamp Command Reference – LCDOUT row of data for the character 0. The LCDOUT command will write the first OutputData value (00) to this location, the second OutputData value (10) to location 1, etc. If we wanted this custom character to affect character 1, instead of 0, we'd have to adjust value of the "Move To..."...
Page 178
LCDOUT - BASIC Stamp Command Reference LCDCMD 1, WakeUp PAUSE 1 LCDCMD 1, FourBitMode 'Set buss to 4-bit mode LCDCMD 1, TwoLine5x8Font 'Set to 2-line mode with 5x8 font LCDCMD 1, DisplayOff 'Turn display off LCDCMD 1, DisplayOn 'Turn display on with blinking cursor LCDCMD 1, IncCrsr 'Set to auto-increment cursor (no display shift) LCDCMD 1, ClearDisplay...
5: BASIC Stamp Command Reference – LOOKDOWN LOOKDOWN BS2e BS2sx BS2p LOOKDOWN Target, ( Value0, Value1, ...ValueN ), Variable LOOKDOWN Target, {ComparisonOp} [ Value0, Value1, ...ValueN ], Variable Function Compare Target value to a list of values and store the index number of the first value that matches into Variable.
Page 180
LOOKDOWN - BASIC Stamp Command Reference SYMBOL Value = B0 SYMBOL Result = B1 Value = 17 Result = 15 LOOKDOWN Value, (26, 177, 13, 1, 0, 17, 99), Result DEBUG "Value matches item ", #Result, "in list" -- or -- Value VAR BYTE Result...
Page 181
5: BASIC Stamp Command Reference – LOOKDOWN LOOKDOWN Value, ["The quick brown fox"], Result DEBUG "Value matches item ", DEC Result, " in list" DEBUG prints, “Value matches item 16 in list” because the character at index item 16 is "f" in the phrase, “The quick brown fox”. The examples above show LOOKDOWN working with lists of constants, LOOKDOWN CAN USE VARIABLES...
Page 182
LOOKDOWN - BASIC Stamp Command Reference ComparisonOp Symbol Description Find the first value Target is equal to Table 5.36: LOOKDOWN <> Find the first value Target is not equal to Comparison Operators. > Find the first value Target is greater than <...
Page 183
5: BASIC Stamp Command Reference – LOOKDOWN below shows some sample, non-contiguous inputs and the corresponding outputs the BASIC Stamp needs to respond with: Table 5.37: Non-Contiguous Each of these values received Needs to result in each of these Number Example (inputs): values sent (outputs): So, if we receive the number 5, we need to output 16.
Page 184
LOOKDOWN - BASIC Stamp Command Reference Demo Program (LOOKDOWN.bas) ' This program uses LOOKDOWN followed by LOOKUP to map the numbers: ' 0, 10, 50, 64, 71 and 98 to 35, 40, 58, 62, 79, and 83, respectively. All other ' numbers are mapped to 255.
5: BASIC Stamp Command Reference – LOOKUP LOOKUP BS2e BS2sx BS2p LOOKUP Index, ( Value0, Value1, ...ValueN ), Variable LOOKUP Index, [ Value0, Value1, ...ValueN ], Variable Function Find the value at location Index and store it in Variable. If Index exceeds the highest index value of the items in the list, Variable is left unaffected.
Page 186
LOOKUP - BASIC Stamp Command Reference Index Result BYTE Index = 3 Result = 255 LOOKUP Index, [26, 177, 13, 1, 0, 17, 99], Result DEBUG "Item ", DEC Index, " is: ", DEC Result In this example, DEBUG prints “Item 3 is: 1.” Note that the first location HE INDEX NUMBER OF THE FIRST ITEM IS number is 0.
Page 187
5: BASIC Stamp Command Reference – LOOKUP LOOKUP LOOKDOWN A great use of LOOKUP is in combination with LOOKDOWN to "map" SING WITH " " CONTIGUOUS SETS OF non-contiguous sets of numbers together. For example, you may have an NUMBERS application where certain numbers are received by the BASIC Stamp and, in response, the BASIC Stamp needs to send a specific set of numbers.
Page 188
LOOKUP - BASIC Stamp Command Reference Demo Program (LOOKDOWN.bas) ' This program uses Lookup to create a debug-window animation of a spinning propeller. ' The animation consists of the four ASCII characters | / - \ which, when printed rapidly ' in order at a fixed location, appear to spin.
5: BASIC Stamp Command Reference – LOW BS2e BS2sx BS2p LOW Pin Function Make the specified pin output low. NOTE: Expressions are not • Pin is a variable/constant/expression (0 – 15) that specifies which allowed as arguments on the BS1. I/O pin to set low.
Page 190
LOW - BASIC Stamp Command Reference Demo Program (LOW.bs2) ' This simple program sets I/O pin 0 high for 1/2 second and low for 1/2 second NOTE: This is written for the BS2 ' in an endless loop. but can be used for the BS1, BS2e, BS2sx and BS2p also.
5: BASIC Stamp Command Reference – MAINIO MAINIO BS2e BS2sx BS2p MAINIO Function Switch from control of auxiliary I/O pins to main I/O pins (on the BS2p40 only). Quick Facts Table 5.40: MAINIO Quick Facts. BS2p 0 – 15 (just like auxiliary I/O, but after MAINIO command, all references I/O pin IDs affect physical pins 5 –...
Page 192
MAINIO - BASIC Stamp Command Reference Note that the main I/O and auxiliary I/O pins are independent of each AND AUXILIARY PINS ARE INDEPENDENT AND UNAFFECTED BY other; the states of the main I/O pins remain unchanged while the CHANGES IN THE OPPOSITE GROUP program affects the auxiliary I/O pins, and vice versa.
5: BASIC Stamp Command Reference – NAP BS2e BS2sx BS2p NAP Period Function Enter sleep mode for a short period. Power consumption is reduced as indicated in Table 5.41 assuming no loads are being driven. NOTE: Expressions are not • Period is a variable/constant/expression (0 – 7) that specifies the allowed as arguments on the BS1.
Page 194
NAP - BASIC Stamp Command Reference the actual timing to vary by as much as –50, +100 percent (i.e., a Period of 0, NAP can range from 9 to 36 ms). At room temperature with a fresh battery or other stable power supply, variations in the length of a NAP will be less than ±10 percent.
Page 195
5: BASIC Stamp Command Reference – NAP Figure 5.16: Example LED Circuit. Ω Demo Program (NAP.bs2) ' The program below lights an LED by placing a low on pin 0. This completes the circuit from NOTE: This is written for the BS2 ' +5V, through the LED and resistor, to ground.
5: BASIC Stamp Command Reference – OUTPUT OUTPUT BS2e BS2sx BS2p OUTPUT Pin Function Make the specified pin an output. NOTE: Expressions are not • Pin is a variable/constant/expression (0 – 15) that specifies which allowed as arguments on the BS1. I/O pin to set to output mode.
Page 198
OUTPUT - BASIC Stamp Command Reference OUTPUT 7 ' Make I/O pin 7 an output. DEBUG "After pin 7 changed to output: ", #PIN7 Demo Program (INPUT_OUTPUT.bs2) ' This program demonstrates how the input/output direction of a pin is determined by NOTE: This is written for the BS2 ' the corresponding bit of DIRS.
5: BASIC Stamp Command Reference – OWIN OWIN BS2e BS2sx BS2p OWIN Pin, Mode, [InputData] Function Receive data from a device using the 1-wire protocol. • Pin is a variable/constant/expression (0 – 15) that specifies which I/O pin to use. 1-wire devices require only one I/O pin (called DQ) to communicate.
Page 200
OWIN - BASIC Stamp Command Reference The Mode argument is used to control placement of reset pulses (and detection of presence pulses) and to designate byte vs. bit input and normal vs. high speed. Figure 5.17 shows the meaning of each of the 4 bits of Mode.
Page 201
5: BASIC Stamp Command Reference – OWIN FirstBit SecondBit VAR OWIN 0, 6, [FirstBit, SecondBit] In the code above, we chose the value "6" for Mode. This sets Bit transfer and Back-End Reset modes. Also, we could have chosen to make the FirstBit and SecondBit variables each a byte in size, but they still would only have received one bit each in the OWIN command (due to the Mode we chose).
Page 202
OWIN - BASIC Stamp Command Reference Conversion Type of Number Numeric Characters Accepted Notes Table 5.46: OWIN Conversion Formatter Formatters. Decimal, optionally limited to DEC{1..5} 0 through 9 1 – 5 digits Signed decimal, optionally SDEC{1..5} -, 0 through 9 limited to 1 –...
Page 203
5: BASIC Stamp Command Reference – OWIN The 1-wire protocol has a well-defined standard for transaction sequences. WIRE PROTOCOL FORMAT Every transaction sequence consists of four parts: 1) Initialization, 2) ROM Function Command, Memory Function Command, Transaction/Data. Additionally, the ROM Function Command and Memory Function Command are always 8 bits wide (1 byte in size) and is sent least-significant-bit (LSB) first.
Page 204
OWIN - BASIC Stamp Command Reference Command Value (in Hex) Action Table 5.47: 1-wire ROM Function Reads the 64-bit ID of the 1-wire device. This command Commands. Read ROM can only be used if there is a single 1-wire device on the line.
Page 205
5: BASIC Stamp Command Reference – OWIN The Demo Program uses a Dallas Semiconductor DS1820 Digital Thermometer device connected as follows. Note that the 4.7 k Ω pull-up resister is required for proper operation. Figure 5.20: DS1820 Circuit. NOTE: The 4.7 kΩ resister is DS1820 required for proper operation.
5: BASIC Stamp Command Reference – OWOUT OWOUT BS2e BS2sx BS2p OWOUT Pin, Mode, [OutputData] Function Send data to a device using the 1-wire protocol. • Pin is a variable/constant/expression (0 – 15) that specifies which I/O pin to use. 1-wire devices require only one I/O pin (called DQ) to communicate.
Page 208
OWOUT - BASIC Stamp Command Reference The Mode argument is used to control placement of reset pulses (and detection of presence pulses) and to designate byte vs. bit input and normal vs. high speed. Figure 5.21 shows the meaning of each of the 4 bits of Mode.
Page 209
5: BASIC Stamp Command Reference – OWOUT FirstBit SecondBit VAR FirstBit = 0 SecondBit = 1 OWOUT 0, 5, [FirstBit, SecondBit] In the code above, we chose the value "6" for Mode. This sets Bit transfer and Front-End Reset modes. Also, we could have chosen to make the FirstBit and SecondBit variables each a byte in size, but the BASIC Stamp would still only use the their lowest bit (BIT0) as the value to transmit in the OWOUT command (due to the Mode we chose).
Page 210
OWOUT - BASIC Stamp Command Reference Table 5.51: OWOUT Conversion Conversion Type of Number Notes Formatters. Formatter DEC{1..5} Decimal, optionally fixed to 1 – 5 digits SDEC{1..5} Signed decimal, optionally fixed to 1 – 5 digits HEX{1..4} Hexadecimal, optionally fixed to 1 – 4 digits SHEX{1..4} Signed hexadecimal, optionally fixed to 1 –...
Page 211
5: BASIC Stamp Command Reference – OWOUT Resting State Figure 5.22: OWOUT Reset and µ 15 - 60 s Presence Pulse. +5 (vdd) 0 (vss) Device’s BASIC Stamp’s Presence Reset Pulse Pulse µ µ Apx. 564 s 60 - 240 s driven by BASIC Stamp driven by 1-wire device This reset pulse is controlled by the lowest two bits of the Mode argument...
Page 212
OWOUT - BASIC Stamp Command Reference The third part, the Memory Function Command, allows the BASIC Stamp to address specific memory locations, or features, of the 1-wire device. Refer to the 1-wire device's data sheet for a list of the available Memory Function Commands.
Page 213
5: BASIC Stamp Command Reference – OWOUT Demo Program (I2C.bsp) ' This program demonstrates interfacing to a Dallas Semiconductor DS1820 1-wire Digital ' Thermometer chip using the BS2p's 1-wire commands. Connect the BS2p to the DS1820 ' as shown in the diagram in the OWIN or OWOUT command description. ' This code reads the Counts Remaing and Counts per Degree C registers in the DS1820 ' chip in order to provide a more accurate temperature reading (down to 1/100th of a ' degree).
5: BASIC Stamp Command Reference – PAUSE PAUSE BS2e BS2sx BS2p PAUSE Period Function Pause the program (do nothing) for the specified Period. NOTE: Expressions are not • Period is a variable/constant/expression (0 – 65535) that specifies allowed as arguments on the BS1. the duration of the pause.
5: BASIC Stamp Command Reference – POLLIN POLLIN BS2e BS2sx BS2p POLLIN Pin, State Function Specify a polled-input pin and active state. • Pin is a variable/constant/expression (0 – 15) that specifies the I/O pin to use. This I/O pin will be set to input mode. •...
Page 218
POLLIN - BASIC Stamp Command Reference This feature should not be confused with the concept of interrupts, as the BASIC Stamp does not support true interrupts. The following is an example of the POLLIN command: POLLIN SIMPLE EXAMPLE POLLIN 0, 1 POLLMODE 2 The POLLIN command in the above code will cause the BASIC Stamp to set I/O pin 0 to an input mode and get ready to poll it for a high (1) state.
Page 219
5: BASIC Stamp Command Reference – POLLIN continue to perform this operation, in-between each command in the loop, endlessly. It's important to note that, in this example, only the DEBUG and GOTO BASIC S " " TAMP REMEMBERS THE POLLING CONFIGURATION FOR commands are being executed over and over again.
Page 220
POLLIN - BASIC Stamp Command Reference pins 2 and 3 low. This works similar to a logical OR operation. The truth table below shows all the possible states of these two polled-input pins and the corresponding states the BASIC Stamp will set the polled-output pins to.
5: BASIC Stamp Command Reference – POLLMODE POLLMODE BS2e BS2sx BS2p POLLMODE Mode Function Specify a polled command mode. • Mode is a variable/constant/expression (0 – 15) that indicates the mode in which to process the polled command configuration. Quick Facts Table 5.55: POLLMODE Quick BS2p Facts.
Page 222
POLLMODE - BASIC Stamp Command Reference Table 5.56: POLLMODE Mode Mode Effect Values. Deactivate polling, clear polled-input and output configuration. Deactivate polling, save polled-input and output configuration. Activate polling with polled-output action (and polled-wait) only. Activate polling with polled-run action only. Activate polling with polled-output/polled-wait and polled-run actions.
Page 223
5: BASIC Stamp Command Reference – POLLMODE POLLIN 0, 1 POLLOUT 1, 0 POLLMODE 2 Loop: DEBUG "Looping…", CR GOTO Loop In this example, the first two lines configure I/O pin 0 as a polled-input (looking for a high state) and I/O pin 1 as a polled-output (going low if I/O pin 0 goes high, and vice versa).
Page 224
POLLMODE - BASIC Stamp Command Reference acts just like it did initially for the remainder of the program. The ability to temporarily disable polling, without changing the configuration, can be a powerful feature for certain "critical" parts of a program. The following example contains two programs.
Page 225
5: BASIC Stamp Command Reference – POLLMODE pin 0, but the polled-run activity is disabled and the BASIC Stamp endlessly runs the code in program 2's Loop routine. Demo Program (POLINOUT.bsp) ' This program demonstrates the POLLIN, POLLOUT and POLLMODE commands. It ' will watch for a high signal on I/O pin 0 and then will output the opposite signal on I/O pin 1 ' all while printing a message on the PC screen.
5: BASIC Stamp Command Reference – POLLOUT POLLOUT BS2e BS2sx BS2p POLLOUT Pin, State Function Specify a polled-output pin and active state. • Pin is a variable/constant/expression (0 – 15) that specifies the I/O pin to use. This I/O pin will be set to output mode. •...
Page 228
POLLOUT - BASIC Stamp Command Reference The POLLOUT command achieves one of three possible actions in POLLOUT SIMPLE EXAMPLE response to a polled-input event. This command works in conjunction with the POLLIN and POLLMODE commands. The following is an example of the POLLOUT command: POLLIN 0, 1 POLLOUT 1, 0 POLLMODE 2...
Page 229
5: BASIC Stamp Command Reference – POLLOUT INPUT 0 OUTPUT 1 Loop: OUT1 = ~IN0 DEBUG "Looping…", CR OUT1 = ~IN0 GOTO Loop In this example, we create the inverse relationship of input pin 0 and output pin 1 manually, in-between the DEBUG and GOTO lines. Though the effects are the same as when using the polling commands, this program actually takes a little longer to run and consumes 7 additional bytes of program (EEPROM) space.
Page 230
POLLOUT - BASIC Stamp Command Reference however, where the polled-output pins will latch the active state; they will change only once (when the poll state is reached) and stay in the new state until the PBASIC program tells it to change again. See the POLLMODE description for more information.
Page 231
5: BASIC Stamp Command Reference – POLLOUT vital that a large enough series resister (perhaps 100 ohms or greater) be inserted on that pin to protect the external device and the BASIC Stamp. Demo Program (POLINOUT.bsp) ' This program demonstrates the POLLIN, POLLOUT and POLLMODE commands. It ' will watch for a high signal on I/O pin 0 and then will output the opposite signal on I/O pin 1 ' all while printing a message on the PC screen.
5: BASIC Stamp Command Reference – POLLRUN POLLRUN BS2e BS2sx BS2p POLLRUN Slot Function Specify a program to run upon a polled-input event. • Slot is a variable/constant/expression (0 – 7) that specifies the program slot to run when a polled-input event occurs. Quick Facts Table 5.59: POLLRUN Quick Facts.
Page 234
POLLRUN - BASIC Stamp Command Reference POLLIN 0, 1 POLLRUN 1 POLLMODE 3 Loop: DEBUG "Waiting in Program Slot 0…", CR GOTO Loop The first line of the above code will set up I/O pin 0 as a polled-input pin looking for a high (1) state.
Page 235
5: BASIC Stamp Command Reference – POLLRUN Demo Program (POLLRUN0.bsp) ' This program demonstrates the POLLRUN command. It is intended to be downloaded ' to program slot 0, and the program called PROGRUN1.BSP should be downloaded to ' program slot 1. I/O pin 0 is set to watch for a high signal. Once the Loop routine ' starts running, the program constant prints it's program slot number to the screen.
5: BASIC Stamp Command Reference – POLLWAIT POLLWAIT BS2e BS2sx BS2p POLLWAIT Period Function Pause program execution, in a low-power mode, in units of Period until any polled-input pin reaches the desired poll state. • Period is a variable/constant/expression (0 – 8) that specifies the duration of the low-power state.
Page 238
POLLWAIT - BASIC Stamp Command Reference The POLLWAIT command is unique among the polling commands in that it actually causes execution to halt, until a polled-input pin event occurs. The Period argument is similar to that of the NAP command; using the values 0 to 7 specifies the duration of the low-power period.
Page 239
5: BASIC Stamp Command Reference – POLLWAIT to sleep for another 18 ms. If I/O pin 0 is high, it runs the next line of code, which toggles the state of I/O pin 1. Then the loop starts all over again.
5: BASIC Stamp Command Reference – POT BS2e BS2sx BS2p POT Pin, Scale, Variable (See RCTIME) Function Read a 5 k Ω to 50 k Ω potentiometer, thermistor, photocell, or other variable resistance. • Pin is a variable/constant (0 – 7) that specifies the I/O pin to use. This pin will be set to output mode initially, then to input mode.
Page 242
POT - BASIC Stamp Command Reference variable resistor affects the time it takes to discharge the capacitor from 5 volts to approximately 1.4 volts. The 16-bit reading is multiplied by (Scale/256), so a scale value of 128 would reduce the range by approximately 50%, a scale of 64 would reduce to 25%, and so on.
5: BASIC Stamp Command Reference – PULSIN PULSIN BS2e BS2sx BS2p PULSIN Pin, State, Variable Function Measure the width of a pulse on Pin described by State and store the result in Variable. NOTE: Expressions are not • Pin is a variable/constant/expression (0 – 15) that specifies the I/O allowed as arguments on the BS1.
Page 244
PULSIN - BASIC Stamp Command Reference "times out" and store 0 in Variable. This operation keeps your program from locking-up should the desired pulse never occur. Regardless of the size of Variable, PULSIN internally uses a 16-bit timer. OW THE RESULT IS REPORTED Unless the pulse widths are known to be short enough to fit in an 8-bit result, it is recommended using a word-sized variable.
5: BASIC Stamp Command Reference – PULSOUT PULSOUT BS2e BS2sx BS2p PULSOUT Pin, Period Function Generate a pulse on Pin with a width of Period. NOTE: Expressions are not • Pin is a variable/constant/expression (0 – 15) that specifies the I/O allowed as arguments on the BS1.
Page 246
PULSOUT - BASIC Stamp Command Reference 10k resistor sets the state on the pin. When PULSOUT executes, it turns on the output driver, allowing OUT7 (PIN7 on the BS1) to control the pin. Figure 5.26: Example Pulse Diagram. (instruction executes) PULSOUT 7,5 positive pulse Ω...
5: BASIC Stamp Command Reference – PUT BS2e BS2sx BS2p PUT Location, Value Function Put Value into Scratch Pad RAM Location. • Location is a variable/constant/expression (0 – 63: BS2e/BS2sx, 0 - 127: BS2p) that specifies the Scratch Pad RAM location to write to. •...
Page 248
PUT - BASIC Stamp Command Reference the current program slot that will be used for the READ and WRITE commands. Any values written to this location will be ignored. Demo Program (GETPUT1.bsx) ' This example demonstrates the use of the GET and PUT commands. First, location 63 NOTE: This is written for the BS2sx ' is read using GET to display the currently running program number.
5: BASIC Stamp Command Reference – PWM BS2e BS2sx BS2p PWM Pin, Duty, Cycles Function Convert a digital value to analog output via pulse-width modulation. • Pin is a variable/constant/expression (0 – 15) that specifies the I/O NOTE: Expressions are not allowed as arguments on the BS1.
Page 250
PWM - BASIC Stamp Command Reference use this formula: (Duty/255) * 5V. For example, if Duty is 100, (100/255) * 5V = 1.96V; PWM outputs a train of pulses whose average voltage is 1.96V. In order to convert PWM into an analog voltage we have to filter out the ILTERING THE SIGNAL pulses and store the average voltage.
Page 251
5: BASIC Stamp Command Reference – PWM voltage setting established by PWM. Keep in mind that leakage currents of up to 1 µA can flow into or out of this “disconnected” pin. Over time, these small currents will cause the voltage on the capacitor to drift. The same applies for leakage current from an op-amp’s input, as well as the capacitor’s own internal leakage.
Page 252
PWM - BASIC Stamp Command Reference Demo Program (PWM.bs2) ' Connect a voltmeter (such as a digital multimeter set to its voltage range) to the output of NOTE: This is written for the BS2 ' the circuit shown in the figure for the PWM command (in the manual). Run the program but can be used for the BS1, BS2e, ' and observe the readings on the meter.
5: BASIC Stamp Command Reference – RANDOM RANDOM BS2e BS2sx BS2p RANDOM Variable Function Generate a pseudo-random number. • Variable is a variable (usually a word) whose bits will be scrambled to produce a random number. Variable acts as RANDOM's input and its result output.
Page 254
RANDOM - BASIC Stamp Command Reference SYMBOL Result = W0 Result = 11000 ' Set initial "seed" value Loop: RANDOM Result ' Generate random number. DEBUG Result ' Show the result on screen. GOTO Loop -- or -- Result WORD Result = 11000 ' Set initial "seed"...
Page 255
5: BASIC Stamp Command Reference – RANDOM Figure 5.28: RANDOM Button Circuit. Ω 10 k PB Switch Demo Program (RANDOM.bas) ' Connect a button to I/O pin 7 as shown in the figure in the RANDOM command description ' (in the manual) and run this program. This program uses RANDOM to simulate a coin toss. ' After 100 trials, it reports the total number of heads and tails thrown.
Page 256
RANDOM - BASIC Stamp Command Reference Demo Program (RANDOM.bs2) ' Connect a button to I/O pin 7 as shown in the figure in the RANDOM command description NOTE: This is written for the BS2 ' (in the manual) and run this program. This program uses RANDOM to simulate a coin toss. but can be used for the BS2e, ' After 100 trials, it reports the total number of heads and tails thrown.
5: BASIC Stamp Command Reference – RCTIME RCTIME BS2e BS2sx BS2p (See POT) RCTIME Pin, State, Variable Function Measure time while Pin remains in State; usually to measure the charge/discharge time of resistor/capacitor (RC) circuit. • Pin is a variable/constant/expression (0 – 15) that specifies the I/O pin to use.
Page 258
RCTIME - BASIC Stamp Command Reference Figure 5.29 shows suitable RC circuits for use with RCTIME. The circuit in UITABLE IME CIRCUITS 5.29a is preferred, because the BASIC Stamp's logic threshold is approximately 1.5 volts. This means that the voltage seen by the pin will start at 5V then fall to 1.5V (a span of 3.5V) before RCTIME stops.
Page 259
5: BASIC Stamp Command Reference – RCTIME value called the RC time constant, or tau ( τ ) for short. Tau represents the time required for a given RC combination to charge or discharge by 63 percent of the total change in voltage that they will undergo. More importantly, the value τ...
Page 260
RCTIME - BASIC Stamp Command Reference Charge time = 4 x 220 x (0.1 x 10 ) = 88 x 10 So it takes only 88 µs for the cap to charge/discharge, meaning that the 1 ms charge/discharge time of the example is plenty. A final note about Figure 5.29: You may be wondering why the 220 Ω...
Page 261
5: BASIC Stamp Command Reference – RCTIME Figure 5.30: Relay circuit for Demo Program 2. relay coil Relay: 5Vdc reed relay with 20mA coil, eg., Radio Shack 275-232 Ω relay 10 k contacts Demo Program (RCTIME2.bs2) ' This program illustrates the use of RCTIME as a fast stopwatch. The program energizes ' a relay coil, then measures how long it takes for the relay contacts to close.
5: BASIC Stamp Command Reference – READ READ BS2e BS2sx BS2p READ Location, Variable Function Read value at Location in EEPROM and store the result in result in Variable. NOTE: Expressions are not • Location is a variable/constant/expression (0 – 255 on BS1, 0 – 2047 allowed as arguments on the BS1.
Page 264
READ - BASIC Stamp Command Reference The EEPROM is organized as a sequential set of byte-sized memory EADING WORD VALUES VS BYTE VALUES locations. The READ command only retrieves byte-sized values from EEPROM. This does not mean that you can't read word-sized values, however.
Page 265
5: BASIC Stamp Command Reference – READ location 255 holds the value 100, then your program can use locations 0–99 for data. On other BASIC Stamps, you'll need to view the Memory Map of the program before you download it, to determine the last EEPROM location used.
Page 266
READ - BASIC Stamp Command Reference StrAddr = Message 'Set address to start of Message. StringOut: READ StrAddr,Char 'Get a byte from EEPROM. IF Char <> 0 THEN Cont 'Not end? Continue. Stop 'Stop here when done. Cont: DEBUG Char 'Show character on screen.
5: BASIC Stamp Command Reference – RETURN RETURN BS2e BS2sx BS2p RETURN Function Return from a subroutine, assuming there was a previous GOSUB executed. Quick Facts Table 5.68: RETURN Quick Facts. BS1, BS2, BS2e, BS2sx and BS2p Maximum number of Unlimited.
Page 268
RETURN - BASIC Stamp Command Reference this time) and because there wasn't a previous place to return to, the BASIC Stamp will start the entire program over again. This would cause an endless loop. The important thing to remember here is to always make sure your program doesn't allow itself to "fall into"...
5: BASIC Stamp Command Reference – REVERSE REVERSE BS2e BS2sx BS2p REVERSE Pin Function Reverse the data direction of the specified pin. NOTE: Expressions are not • Pin is a variable/constant/expression (0 – 15) that specifies the I/O allowed as arguments on the BS1. pin to use.
Page 270
REVERSE - BASIC Stamp Command Reference Demo Program (REVERSE.bas) ' Connect the circuit shown in the REVERSE command description to I/O pin 0 and run this ' program. The LED will alternate between two states, dim and bright. The BASIC Stamp is ' using the REVERSE command to toggling I/O pin 0 between input and output states.
5: BASIC Stamp Command Reference – RUN BS2e BS2sx BS2p RUN Program Function Switches execution to another BASIC Stamp program (in a different program slot). • Program is a variable/constant/expression (0 – 7) that specifies the program slot to run. Quick Facts Table 5.69: RUN Quick Facts.
Page 272
RUN - BASIC Stamp Command Reference ' Download the following two lines into program slot 0 DEBUG "Hello " RUN 1 ' Download the following three lines into program slot 1 DEBUG "World!", CR PAUSE 0 RUN 0 The above two programs (assuming they have been downloaded into program slots 0 and 1, respectively) will display "Hello World!"...
Page 273
5: BASIC Stamp Command Reference – RUN DATA 200, 65, 23, 70, 90 ProgNum BYTE Value BYTE Index BYTE GET 63, ProgNum DEBUG "Program #", DEC ProgNum, CR FOR Index = 0 TO 4 READ ProgNum*5+Index, Value DEBUG DEC3 Value, " " NEXT DEBUG CR PAUSE 1000...
5: BASIC Stamp Command Reference – SERIN SERIN BS2e BS2sx BS2p SERIN Rpin, Baudmode, { (Qualifier),} {#} InputData SERIN Rpin {\Fpin}, Baudmode, {Plabel,} {Timeout, Tlabel,} [ InputData ] Function Receive asynchronous serial data (e.g., RS-232 data). • Rpin is a variable/constant/expression (0 – 16) that specifies the I/O NOTE: Expressions are not allowed as arguments on the BS1.
Page 276
SERIN - BASIC Stamp Command Reference corresponding value in a variable, wait for a fixed or variable sequence of bytes, or ignore a specified number of bytes. These actions can be combined in any order in the InputData list. Quick Facts Table 5.70: SERIN Quick Facts.
Page 277
5: BASIC Stamp Command Reference – SERIN RS-232 is the electrical specification for the signals that PC serial ports use. Unlike normal logic, where a 5 volts is a logic 1 and 0 volts is logic 0, RS- 232 uses -12 volts for logic 1 and +12 volts for logic 0. This specification allows communication over longer wire lengths without amplification.
Page 278
SERIN - BASIC Stamp Command Reference Figure 5.32 shows the pinouts of the two styles of PC serial ports and how to connect them to the BASIC Stamp's I/O pin (the 22K resister is not needed if connecting to the SIN pin). Though not normally needed, the figure also shows loop back connections that defeat hardware handshaking used by some PC software.
Page 279
24660 8276 *The BASIC Stamp 2 and BASIC Stamp 2e may have trouble synchronizing with the incoming serial stream at this rate and higher due to the lack of a hardware input buffer. Use only simple variables and no formatters to try to solve this problem.
Page 280
SERIN - BASIC Stamp Command Reference If you’re communicating with existing software or hardware, its speed(s) HOOSING THE PROPER BAUD MODE and mode(s) will determine your choice of baud rate and mode. In general, 7-bit/even-parity (7E) mode is used for text, and 8-bit/no-parity (8N) for byte-oriented data.
Page 281
5: BASIC Stamp Command Reference – SERIN communication) to interpret the values as necessary. In this case, perhaps we actually wanted SerData to end up with the value 1, rather than the ASCII code 49. The SERIN command provides a formatter, called the decimal formatter, which will interpret this for us.
Page 282
SERIN - BASIC Stamp Command Reference To further illustrate this, consider the following examples (assuming we’re using the same code example as above): 1) Serial input: ABC Result: The BASIC Stamp halts at the SERIN command, continuously waiting for decimal text. 2) Serial input: 123 (with no characters following it) Result: The BASIC Stamp halts at the SERIN command.
Page 283
5: BASIC Stamp Command Reference – SERIN available for the SERIN command. If not using a BS1, see the “Additional Conversion Formatters” section below for more information. The SERIN command can also be configured to wait for specified data SERIN SING TO WAIT FOR SPECIFIC DATA BEFORE PROCESSING...
Page 284
SERIN - BASIC Stamp Command Reference The BS1’s SERIN command is limited to above-mentioned features. If you are not using a BS1, please continue reading about the additional features below. The decimal formatter is only one of a whole family of conversion formatters available with SERIN on the BS2, BS2e, BS2sx and BS2p.
Page 285
5: BASIC Stamp Command Reference – SERIN Table 5.76: BS2, BS2e, BS2sx and Conversion Type of Number Numeric Characters Accepted Notes BS2p Conversion Formatters. Formatter Decimal, optionally limited to DEC{1..5} 0 through 9 1 – 5 digits Signed decimal, optionally SDEC{1..5} -, 0 through 9 limited to 1 –...
Page 286
SERIN - BASIC Stamp Command Reference Table 5.77: BS2, BS2e, BS2sx and Special Formatter Action BS2p Special Formatters. Input a character string of length L into an array. If specified, an STR ByteArray \L {\E} end character E causes the string input to end before reaching length L.
Page 287
5: BASIC Stamp Command Reference – SERIN If the serial input were "hello*" DEBUG would display "hello" since it collects bytes up to (but not including) the end character. It fills the unused bytes up to the specified length with 0s. DEBUG’s normal STR formatter understands a 0 to mean end-of-string.
Page 288
SERIN - BASIC Stamp Command Reference SerString BYTE(4) ' Make a 4-byte array. DEBUG "Enter a 4 character password", CR SERIN 1, 16468, [STR SerString\4] ' Get the string DEBUG "Waiting for: ", STR SerString\4, CR SERIN 1, 16468, [WAITSTR SerString\4] 'Wait for a match DEBUG "Password accepted!", CR SERIN’s InputData can be structured as a sophisticated list of actions to...
Page 289
5: BASIC Stamp Command Reference – SERIN the data was wrong, or the parity bit itself could be bad when the rest of the data was OK. Many systems that work exclusively with text use (or can be set for) 7- bit/even-parity mode.
Page 290
SERIN - BASIC Stamp Command Reference If no data arrives within 2 seconds, the program aborts SERIN and continues at the label NoData. Here's a very important concept: this timeout feature is not picky about EMEMBER IMEOUT DOES NOT CARE WHAT KIND OF DATA IS the kind of data SERIN receives;...
Page 291
5: BASIC Stamp Command Reference – SERIN the rules of other serial handshaking schemes, but most computers other than the BASIC Stamp cannot start and stop serial transmission on a byte- by-byte basis. That’s why this discussion is limited to communication between BASIC Stamps.) Here’s an example using flow control on the BS2 (data through I/O pin 1, flow control through I/O pin 0, 9600 baud, N8, noninverted):...
Page 292
SERIN - BASIC Stamp Command Reference Host PC (for Debug) Figure 5.33: Flow-Control Example Circuit. programming cable receiver sender Serial communication, because of its complexity, can be very difficult to SERIN T ROUBLESHOOTING work with at times. Please follow these guidelines when developing a project using the SERIN and SEROUT commands: Always build your project in steps.
Page 293
5: BASIC Stamp Command Reference – SERIN data you receive is unreadable, it is most likely a baud rate setting error. If receiving data from another device that is not a BASIC Stamp, try to use baud rates of 4800 and below. Because of additional overhead in the BASIC Stamp, and the fact that the BASIC Stamp has no hardware receive buffer for serial communication, received data may...
Page 294
SERIN - BASIC Stamp Command Reference Demo Program (SERIN-OUT_SENDER.bs2 & SERIN-OUT_RECEIVER.bs2) ' Using two BS2-IC's, connect the circuit shown in the SERIN command description and run NOTE: This is written for the BS2 ' this program on the BASIC Stamp designated as the Sender. This program demonstrates but can be used for the BS2e, ' the use of Flow Control (FPin).
5: BASIC Stamp Command Reference – SEROUT SEROUT BS2e BS2sx BS2p SEROUT Tpin, Baudmode, ( {#} OutputData ) SEROUT Tpin {\Fpin}, Baudmode, {Pace,} {Timeout, Tlabel,} [ InputData ] Function Transmit asynchronous serial data (e.g., RS-232 data). • Tpin is a variable/constant/expression (0 – 16) that specifies the I/O NOTE: Expressions are not allowed as arguments on the BS1.
Page 296
SEROUT - BASIC Stamp Command Reference hex or binary text representations, or transmit strings of bytes from variable arrays. These actions can be combined in any order in the OutputData list. Quick Facts Table 5.79: SEROUT Quick Facts. BS2e BS2sx BS2p Units in Pace 1 ms...
Page 297
5: BASIC Stamp Command Reference – SEROUT All BASIC Stamps (including the BS1) can also transmit RS-232 data through any of their I/O pins (Tpin = 0 – 7 for BS1, Tpin = 0 – 15 on all other BASIC Stamps). The I/O pins only provide a 0 to +5 volt swing (outside of RS-232 specs) and may need to be connected through a line driver for proper operation with all serial ports.
Page 298
SEROUT - BASIC Stamp Command Reference On the BS1, serial communication is limited to: no-parity, 8-data bits and 1-stop bit at one of four different speeds: 300, 600, 1200 or 2400 baud. Table 5.80 indicates the Baudmode value or symbols to use when selecting the desired mode.
Page 300
SEROUT - BASIC Stamp Command Reference SEROUT 1, N2400, ( 65 ) --or-- SEROUT 1, 16780, [ 65 ] This is written with the BS2's Here, SEROUT will transmit a byte equal to 65 (the ASCII value of the BaudMode value. Be sure to adjust character "A") through pin 1.
Page 301
5: BASIC Stamp Command Reference – SEROUT The SEROUT command sends quoted text exactly as it appears in the OutputData list: SEROUT 1, N2400, ( "HELLO", CR ) SEROUT 1, N2400, ( "Num = ", #100 ) --or-- SEROUT 1, 16780, [ "HELLO", CR ] SEROUT 1, 16780, [ "Num = ", DEC 100 ] This is written with the BS2's BaudMode value.
Page 302
SEROUT - BASIC Stamp Command Reference code for the “X” character, 89 is the ASCII code for the “Y” character, and so on. The decimal formatter is only one of a whole family of conversion DDITIONAL CONVERSION FORMATTERS formatters available with SERIN on the BS2, BS2e, BS2sx and BS2p. See Table 5.85 for a list of available conversion formatters.
Page 303
5: BASIC Stamp Command Reference – SEROUT Table 5.86: BS2, BS2e, BS2sx and Special Formatter Action BS2p Special Formatters. Displays "symbol = x' + carriage return; where x is a number. Default format is decimal, but may be combined with conversion formatters (ex: BIN ? x to display "x = binary_number").
Page 304
SEROUT - BASIC Stamp Command Reference sending the 7-bit value: %0011010, it sets the parity bit to 1 in order to make an even number of 1s (four). The receiver also counts the data bits to calculate what the parity bit should be.
Page 305
5: BASIC Stamp Command Reference – SEROUT SerData BYTE SEROUT 1\0, 84, [SerData] When SEROUT executes, I/O pin 1 (Tpin) is made an output, and I/O pin 0 (Fpin) is made an input, to wait for the “go” signal from the receiver. Here’s the relationship of serial polarity to Fpin states.
Page 306
SEROUT - BASIC Stamp Command Reference Host PC (for Debug) Figure 5.35: Flow-Control Example Circuit. programming cable receiver sender The SEROUT command supports open-drain and open-source output, SING AUDMODES FOR BASIC S which makes it possible to network multiple BASIC Stamps on a single ETWORKING TAMPS pair of wires.
Page 307
5: BASIC Stamp Command Reference – SEROUT Figure 5.36: SEROUT Open-Drain Circuit. This circuit is for use with the Open, Non-inverted baudmode. 1 kΩ To other To other devices devices (Vss) (Vss) BASIC BASIC Stamp Stamp Figure 5.37: SEROUT Open- Source Circuit.
Page 308
SEROUT - BASIC Stamp Command Reference Pay attention to timing. Be very careful to calculate and overestimate the amount of time operations should take within the BASIC Stamp. Misunderstanding the timing constraints is the source of most problems with code that communicate serially. b.
Page 309
5: BASIC Stamp Command Reference – SEROUT Demo Program (SERIN-OUT_SENDER.bs2 & SERIN-OUT_RECEIVER.bs2) ' Using two BS2-IC's, connect the circuit shown in the SEROUT command description and NOTE: This is written for the BS2 ' run this program on the BASIC Stamp designated as the Sender. This program but can be used for the BS2e, ' demonstrates the use of Flow Control (FPin).
5: BASIC Stamp Command Reference – SHIFTIN SHIFTIN BS2e BS2sx BS2p SHIFTIN Dpin, Cpin, Mode, [ Variable {\Bits} {, Variable {\Bits}…} ] Function Shift data in from a synchronous serial device. • Dpin is a variable/constant/expression (0 – 15) that specifies the I/O pin that will be connected to the synchronous serial device’s data output.
Page 312
SHIFTIN - BASIC Stamp Command Reference 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. The SHIFTIN instruction first causes the clock pin to output low and the SHIFTIN OPERATION data pin to switch to input mode.
Page 313
5: BASIC Stamp Command Reference – SHIFTIN Here is a simple example: SHIFTIN SIMPLE EXAMPLE Result BYTE SHIFTIN 0, 1, MSBPRE, [ Result ] Here, the SHIFTIN command will read I/O pin 0 (the Dpin) and will generate a clock signal on I/O 1 (the Cpin). The data that arrives on the Dpin depends on the device connected to it.
Page 314
SHIFTIN - BASIC Stamp Command Reference Demo Program (SHIFTIN.bs2) ' This program uses the SHIFTIN instruction to interface with the ADC0831 8-bit NOTE: This is written for the BS2 ' analog-to-digital converter from National Semiconductor. but can be used for the BS2e, BS2sx and BS2p also.
5: BASIC Stamp Command Reference – SHIFTOUT SHIFTOUT BS2e BS2sx BS2p SHIFTOUT Dpin, Cpin, Mode, [ OutputData {\Bits} {,OutputData {\Bits}…} ] Function Shift data out to a synchronous serial device. • Dpin is a variable/constant/expression (0 – 15) that specifies the I/O pin that will be connected to the synchronous serial device’s data input.
Page 316
SHIFTOUT - BASIC Stamp Command Reference At their heart, synchronous-serial devices are essentially shift-registers; trains of flip-flops that receive data bits in a bucket brigade fashion from a single data input pin. Another bit is input each time the appropriate edge (rising or falling, depending on the device) appears on the clock line.
Page 317
5: BASIC Stamp Command Reference – SHIFTOUT Here is a simple example: SHIFTOUT SIMPLE EXAMPLE SHIFTOUT 0, 1, MSBFIRST, [ 250 ] Here, the SHIFTOUT command will write to I/O pin 0 (the Dpin) and will generate a clock signal on I/O 1 (the Cpin). The SHIFTOUT command will generate eight clock pulses while writing each bit (of the 8-bit value 250) onto the data pin (Dpin).
Page 318
SHIFTOUT - BASIC Stamp Command Reference Figure 5.40: SHIFTOUT Timing Ω LEDs (all) Diagram. Refer to the SHIFTOUT Quick Answers table for timing information on t and t To P0 DATA IN 74HC595 To P2 LATCH To P1 RESET Demo Program (SHIFTOUT.bs2) ' This program uses the SHIFTOUT command to interface to the 74HC595 shift register as an NOTE: This is written for the BS2 ' 8-bit output port.
5: BASIC Stamp Command Reference – SLEEP SLEEP BS2e BS2sx BS2p SLEEP Period Function Put the BASIC Stamp into low-power mode for a specified time. NOTE: Expressions are not • Period is a variable/constant/expression (1 – 65535) that specifies allowed as arguments on the BS1. the duration of sleep.
Page 320
SLEEP - BASIC Stamp Command Reference calculates a correction factor that it uses during SLEEP. As a result, longer SLEEP intervals are accurate to approximately ±1 percent. If your application is driving loads (sourcing or sinking current through output-high or output-low pins) during SLEEP, current will be interrupted for about 18 ms when the BASIC Stamp wakes up every 2.3 seconds.
5: BASIC Stamp Command Reference – SOUND SOUND BS2e BS2sx BS2p SOUND Pin, ( Note, Period {, Note, Period…} ) (See FREQOUT) Function Generate square-wave tones for a specified period. • Pin is a variable/constant (0 – 7) that specifies the I/O pin to use. This pin will be set to output mode.
Page 322
SOUND - BASIC Stamp Command Reference Figure 5.42: Example RC filter Driving an Audio Amplifier circuits for driving and audio amplifier or a speaker. from I/O pin Amplifier .g., Radio Shack 0.1µF 0.01µF 277-1008C) Driving a Speaker 10µF (both) ≥40Ω Speaker from I/O pin (or 8Ω...
5: BASIC Stamp Command Reference – STOP STOP BS2e BS2sx BS2p STOP Function Stop program execution. Explanation STOP prevents the BASIC Stamp from executing any further instructions until it is reset. The following actions will reset the BASIC Stamp: Pressing and releasing the RESET button on the development board.
5: BASIC Stamp Command Reference – STORE STORE BS2e BS2sx BS2p STORE ProgramSlot Function Designate a program slot for the READ/WRITE instructions to operate upon. • ProgramSlot is a variable/constant/expression (0 – 7) that specifies the program slot to use for READ and WRITE instructions. Explanation STORE tells the BS2p which program slot to use when a READ or WRITE instruction is executed.
Page 326
STORE - BASIC Stamp Command Reference ' -------------------------- Main Routines -------------------------- Main: GOSUB DisplaySlotsAndReadData PAUSE 2000 STORE 1 'Switch to READ/WRITE slot 1 GOSUB DisplaySlotsAndReadData PAUSE 2000 RUN 1 'Switch to program 1 ' --------------------------- Subroutines --------------------------- DisplaySlotsAndReadData: GET 127, Value DEBUG CR, "Prog Slot: ", DEC1 Value.LOWNIB DEBUG "...
Page 327
5: BASIC Stamp Command Reference – STORE Demo Program (STORE2.bsp) DATA @0, 11, 12, 13, 14, 15 WORD Value BYTE ' -------------------------- Main Routines -------------------------- Main: GOSUB DisplaySlotsAndReadData PAUSE 2000 STORE 0 'Switch to READ/WRITE slot 0 GOSUB DisplaySlotsAndReadData STOP 'Stop execution ' --------------------------- Subroutines --------------------------- DisplaySlotsAndReadData:...
Page 328
STORE - BASIC Stamp Command Reference Value = Idx – 2048 * 2 'Use different numbers in each location GOSUB WriteWordToEEPROM DEBUG "Location: ", DEC5 Idx, " Value: ", DEC5 Value, CR NEXT DEBUG "Reading...", CR PAUSE 2000 FOR Idx = 2048 TO 16383 STEP 32 'Read values from EEPROM GOSUB ReadWordFromEEPROM DEBUG "Location: ", DEC5 Idx, "...
5: BASIC Stamp Command Reference – TOGGLE TOGGLE BS2e BS2sx BS2p TOGGLE Pin Function Invert the state of an output pin. NOTE: Expressions are not • Pin is a variable/constant/expression (0 – 15) that specifies which allowed as arguments on the BS1. I/O pin to set high.
Page 330
TOGGLE - BASIC Stamp Command Reference Ω Figure 5.43: Example LED circuit for TOGGLE demo programs. Ω Ω Ω Demo Program (TOGGLE.bas) ' Connect LEDs to pins 0 through 3 as shown in the TOGGLE command description in the ' manual and run this program. The TOGGLE command will treat you to a light show. You ' may also run the demo without LEDs.
5: BASIC Stamp Command Reference – WRITE WRITE BS2e BS2sx BS2p WRITE Location, DataItem Function Write DataItem into Location in EEPROM. • Location is a variable/constant/expression (0 – 255 on BS1, 0 – 2047 on all other BASIC Stamps) that specifies the EEPROM address to write to.
Page 332
WRITE - BASIC Stamp Command Reference WRITE 100, 245 --or-- WRITE 100, 245 The EEPROM is organized as a sequential set of byte-sized memory RITING WORD VALUES VS BYTE VALUES locations. The WRITE command only stores byte-sized values into EEPROM. This does not mean that you can't write word-sized values, however.
Page 333
5: BASIC Stamp Command Reference – WRITE might take to exceed the guaranteed maximum. For example, on the BS2, at one write per second (86,400 writes/day) it would take nearly 116 days of continuous operation to exceed 10 million. The primary function of the EEPROM is to store programs (data is stored in leftover space).
Page 334
WRITE - BASIC Stamp Command Reference NEXT Demo Program (WRITE.bs2) ' This program writes a few bytes to EEPROM and then reads them back out and displays NOTE: This is written for the BS2 ' them on the screen. but can be used for the BS2e, BS2sx and BS2p also.
5: BASIC Stamp Command Reference – XOUT XOUT BS2e BS2sx BS2p XOUT Mpin, Zpin, [ House\Command { \Cycles} {, House\Command { \Cycles}…} ] Function Send an X-10 power-line control command (through the appropriate power-line interface). • Mpin is a variable/constant/expression (0 – 15) that specifies the I/O pin to output X-10 signals (modulation) to the power-line interface device.
Page 336
XOUT interfaces to the AC power-line through an approved interface device such as a PL-513 or TW-523, available from Parallax or X-10 dealers. The hookup requires a length of four-conductor phone cable and a standard modular phone-base connector (6P4C type). Connections are shown in Figure 5.44.
Page 337
5: BASIC Stamp Command Reference – XOUT Table 5.96 lists the XOUT command codes and their functions: Table 5.96: XOUT Commands and Command Value Function Their Function. UnitOn %10010 Turn on the currently selected unit. UnitOff %11010 Turn off the currently selected unit. UnitsOff %11100 Turn off all modules in this house code.
Page 338
XOUT - BASIC Stamp Command Reference first turning it completely off, then sending 10 cycles of the Dim command. This may seem odd, but it follows the peculiar logic of the X-10 system. Demo Program (X10.bs2) ' This program--really two program fragments--demonstrates the syntax and use of the XOUT NOTE: This is written for the BS2 ' command.
Appendix A: ASCII Chart ASCII Chart (first 128 characters) Char Name / Function Char Char Char Null space Start Of Heading Start Of Text " End Of Text End Of Transmit Enquiry Acknowledge & Bell Backspace Horizontal Tab Line Feed Vertical Tab Form Feed Carriage Return...
Appendix C: Conversion Formatters Conversion Formatters This appendix lists the Conversion Formatters available for the commands SERIN, I2CIN, LCDIN, and OWIN and demonstrates, though various input/output data examples, exactly what will be received when using these formatters. Decimal Characters Received ⊗...
Page 344
Conversion Formatters Additional Characters Received Hexadecimal ⊗ ⊗ 1F⊗ ⊗ $1F⊗ ⊗ -$1F⊗ ⊗ ⊗ ⊗ $1F⊗ ⊗ $15AF⊗ ⊗ Formatters IHEX 15AF IHEX1 IHEX2 IHEX3 IHEX4 15AF 15AF ISHEX ISHEX1 ISHEX2 ISHEX3 ISHEX4 15AF NOTE: The HEX formatters are not case sensitive. For example, 1F is the same as 1f. ⊗...
Page 345
Appendix C: Conversion Formatters Additional Characters Received Binary ⊗ ⊗ 11⊗ ⊗ %11⊗ ⊗ -%11⊗ ⊗ ⊗ ⊗ %11⊗ ⊗ %101⊗ ⊗ Formatters IBIN IBIN1 IBIN2 IBIN3 – IBIN16 ISBIN ISBIN1 ISBIN2 ISBIN3 – ISBIN16 ⊗ Means any non-binary-numeric characters such as letters, spaces, minus signs, carriage returns, control characters, etc.
Need help?
Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?
Questions and answers