BASIC Stamp Syntax and Reference Manual Version 2.
Warranty Parallax Inc. warrants its products against defects in materials and workmanship for a period of 90 days from receipt of product. If you discover a defect, Parallax Inc. will, at its option, repair or replace the merchandise, or refund the purchase price. Before returning the product to Parallax, call for a Return Merchandise Authorization (RMA) number. Write the RMA number on the outside of the box used to return the merchandise to Parallax.
Internet BASIC Stamp Discussion List We maintain active web-based discussion forums for people interested in Parallax products. These lists are accessible from www.parallax.com via the Support → Discussion Forums menu. These are the forums that we operate from our web site: • • • • • • • BASIC Stamps – This list is widely utilized by engineers, hobbyists and students who share their BASIC Stamp projects and ask questions.
Contents PREFACE ...................................................................... 5 INTRODUCTION TO THE BASIC STAMP ..................................... 7 BASIC STAMP MODEL COMPARISON TABLE .........................................................................8 BASIC STAMP 1 HARDWARE .............................................................................................10 BASIC STAMP 2 HARDWARE .............................................................................................
Contents Negative (-)...............................................................................................................106 Encoder (NCD) .........................................................................................................107 Sine (SIN) .................................................................................................................107 Square Root (SQR) ..................................................................................................
Contents DTMFOUT.....................................................................................................................179 EEPROM.......................................................................................................................183 END...............................................................................................................................187 EXIT ...........................................................................................................
Contents RETURN .......................................................................................................................375 REVERSE.....................................................................................................................377 RUN ..............................................................................................................................381 SELECT...CASE .................................................................................................
Preface Thank you for purchasing a Parallax BASIC Stamp® microcontroller module. We have done our best to produce several full-featured, easy to use development systems for BASIC Stamp microcontrollers. Depending on the Starter Kit you purchased, your BASIC Stamp model, development board and other contents will vary. This manual is written for the latest available BASIC Stamp modules and software as of February 2005. As the product-line evolves, new information may become available.
Preface Book What’s a Microcontroller? Robotics with the Boe-Bot IR Remote for the Boe-Bot Basic Analog and Digital Applied Sensors Understanding Signals Industrial Control Elements of Digital Logic The Microcontroller Application Cookbook Volumes 1 and 2 Al’s “World Famous” Stamp Project of the Month Anthology The Nuts and Volts of BASIC Stamps Volumes 1, 2, 3, 4, and 5 StampWorks Stamp 2 Communication and Control Projects Programming and Customizing the BASIC Stamp Computer BASIC Stamp 2p Part # 28123
1: Introduction to the BASIC Stamp 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 November 2004, Parallax customers have put well over three million BASIC Stamp modules into use. Over this 12-year period, the BASIC Stamp line of controllers has evolved into six models and many physical package types, explained below.
Introduction to the BASIC Stamp BASIC Stamp Model Comparison Table Products BS1 BS2 BS2e Environment 0º - 70º C (32º - 158º F) ** 0º - 70º C (32º - 158º F) ** 0º - 70º C (32º - 158º F) ** Microcontroller Microchip PIC16C56a Microchip PIC16C57c Ubicom SX28AC Processor Speed 4 MHz 20 MHz 20 MHz Program Execution Speed ~2,000 instructions/sec.
1: Introduction to the BASIC Stamp BS2sx BS2p24 BS2p40 BS2pe BS2px 0º - 70º C (32º - 158º F) ** 0º - 70º C (32º - 158º F) ** 0º - 70º C (32º - 158º F) ** 0º - 70º C (32º - 158º F) ** 0º - 70º C (32º - 158º F) ** Ubicom SX28AC Ubicom SX48AC Ubicom SX48AC Ubicom SX48AC Ubicom SX48AC 50 MHz 20 MHz Turbo 20 MHz Turbo 8 MHz Turbo 32 MHz Turbo ~6000 instructions/sec. ~19,000 instructions/sec. ~10,000 instructions/sec. ~12,000 instructions/sec. ~12,000 instructions/sec.
Introduction to the BASIC Stamp BASIC Stamp 1 Figure 1.1: BASIC Stamp 1 (Rev B) (Stock# BS1-IC). Figure 1.2: BASIC Stamp 1 OEM (Rev. A) (Stock# 27295). Page 10 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
1: Introduction to the BASIC Stamp Figure 1.3: BASIC Stamp 1 (Rev Dx) (Stock# 27100). The BASIC Stamp 1 is available several physical packages. The BS1-IC (Figure 1.1) uses surface mount components to fit in a small 14-pin SIP package. The preassembled BASIC Stamp 1 OEM (Figure 1.2) features an easier-to-trace layout meant to aid customers who wish to integrate the BASIC Stamp 1 circuit directly into their design (as a lower-cost solution). The BASIC Stamp 1 Rev. Dx (simply called the Rev.
Introduction to the BASIC Stamp Pin Name 1 VIN 2 VSS 3 4 PCO PCI 5 VDD 6 RES 7-14 P0-P7 Description Unregulated power in: accepts 5.5 - 15 VDC (6-40 VDC on BS1-IC rev. b), which is then internally regulated to 5 volts. May be left unconnected if 5 volts is applied to the VDD (+5V) pin. System ground: connects to BS1 Serial Adapter ground for programming. PC Out: 4800 baud serial output (TTL level) to PC. PC In: 4800 baud serial input (TTL level) from PC.
1: Introduction to the BASIC Stamp BASIC Stamp 2 Figure 1.4: BASIC Stamp 2 (Rev. G) (Stock# BS2-IC). Figure 1.5: BASIC Stamp 2 OEM (Rev. A2) (Stock# 27290 assembled, or #27291 in kit form). The BASIC Stamp 2 is available in several physical packages. The BS2-IC (Figure 1.4) uses surface mount components to fit in a small 24-pin DIP package. The BASIC Stamp 2 OEM (Figure 1.
Introduction to the BASIC Stamp Stamp 2 OEM is available in either an assembled form or a kit form. These three packages are functionally equivalent. In addition to the dual-inline and OEM packages, there are prototyping boards available that feature a surface mounted BS2. Please check www.parallax.com → Products → Development Boards for product descriptions.
1: Introduction to the BASIC Stamp BASIC Stamp 2e Figure 1.6: BASIC Stamp 2e (Rev. B) (Stock# BS2E-IC). The BASIC Stamp 2e is available in the above 24-pin DIP package. Table 1.3: BASIC Stamp 2e Pin Descriptions. Pin Name 1 SOUT 2 SIN 3 ATN 4 VSS 5-20 P0-P15 21 VDD 22 RES 23 VSS 24 VIN Description Serial Out: connects to PC serial port RX pin (DB9 pin 2 / DB25 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 Stamp See the "BASIC Stamp Programming Connections" section on page 27 for more information on the required programming connections between the PC and the BASIC Stamp. Page 16 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
1: Introduction to the BASIC Stamp BASIC Stamp 2sx Figure 1.7: BASIC Stamp 2sx (Rev. E) (Stock# BS2sx-IC) Figure 1.8: BASIC Stamp 2sx OEM (Rev. A2) (Stock# 27294) The BASIC Stamp 2sx is available in the above two physical packages. The BS2sx-IC (Figure 1.7) uses surface mount components to fit in a small 24-pin DIP package. The preassembled BASIC Stamp 2sx OEM (Figure 1.
Introduction to the BASIC Stamp Pin Name 1 SOUT 2 SIN 3 ATN 4 VSS 5-20 P0-P15 21 VDD 22 RES 23 VSS 24 VIN Description Serial Out: connects to PC serial port RX pin (DB9 pin 2 / DB25 pin 3) for programming. Serial In: connects to PC serial port TX pin (DB9 pin 3 / DB25 pin 2) for programming. Attention: connects to PC serial port DTR pin (DB9 pin 4 / DB25 pin 20) for programming. System ground: (same as pin 23) connects to PC serial port GND pin (DB9 pin 5 / DB25 pin 7) for programming.
1: Introduction to the BASIC Stamp BASIC Stamp 2p Figure 1.9: BASIC Stamp 2p24 (Rev. C) (Stock# BS2p24-IC) This module is identical in function to the BS2p40-IC, except that it has 16 I/O pins. Figure 1.10: BASIC Stamp 2p40 (Rev. B) (Stock# BS2p40-IC) This module is identical in function to the BS2p24-IC, except that it has 32 I/O pins. The BASIC Stamp 2p is available in the above two physical packages. Both packages use surface mount components to fit in a small package. The BS2p24-IC (Figure 1.
Introduction to the BASIC Stamp Pin Name 1 SOUT 2 SIN 3 ATN 4 VSS 5-20 P0-P15 {21-36} X0-X15 21 {37} VDD 22 {38} RES 23 {39} VSS 24 {40} VIN Description Serial Out: connects to PC serial port RX pin (DB9 pin 2 / DB25 pin 3) for programming. Serial In: connects to PC serial port TX pin (DB9 pin 3 / DB25 pin 2) for programming. Attention: connects to PC serial port DTR pin (DB9 pin 4 / DB25 pin 20) for programming.
1: Introduction to the BASIC Stamp Basic Stamp 2pe Figure 1.11: BASIC Stamp 2pe (Rev. B) (Stock# BS2pe-IC) The BASIC Stamp 2pe is available in the above 24-pin DIP physical package. Table 1.6: BASIC Stamp 2pe Pin Descriptions. Pin Name 1 SOUT 2 SIN 3 ATN 4 VSS 5-20 P0-P15 21 VDD 22 RES 23 VSS 24 VIN Description Serial Out: connects to PC serial port RX pin (DB9 pin 2 / DB25 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 Stamp See the "BASIC Stamp Programming Connections" section on page 27 for more information on the required programming connections between the PC and the BASIC Stamp. Page 22 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
1: Introduction to the BASIC Stamp Basic Stamp 2px Figure 1.12: BASIC Stamp 2px (Rev. A) (Stock# BS2px-IC) The BASIC Stamp 2px is available in the above 24-pin DIP physical package. Table 1.7: BASIC Stamp 2px Pin Descriptions. Pin Name 1 SOUT 2 SIN 3 ATN 4 VSS 5-20 P0-P15 21 VDD 22 RES 23 VSS 24 VIN Description Serial Out: connects to PC serial port RX pin (DB9 pin 2 / DB25 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 Stamp See the "BASIC Stamp Programming Connections" section on page 27 for more information on the required programming connections between the PC and the BASIC Stamp. Page 24 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
1: Introduction to the BASIC Stamp Guidelines and Precautions When using the BASIC Stamp, or any IC chip, please follow the guidelines below. 1. 2. 3. Be alert to static sensitive devices and static-prone situations. a. The BASIC Stamp, like other IC’s, can be damaged by static discharge that commonly occurs touching grounded surfaces or other conductors. Environmental conditions (humidity changes, wind, static prone surfaces, etc) play a major role in the presence of random static charges.
Introduction to the BASIC Stamp has a half-circle or notch on one end, indicating the correct orientation. See Figure 1.14 for other examples. Pin 1 Reference Notch (pin 1 indicator) 23 2 4 5 Reference Notch Figure 1.13: Pin 1 Indicators BS2-IC shown in the correct orientation in relation to a 24-pin socket.
1: Introduction to the BASIC Stamp BASIC Stamp Programming Connections We suggest using a Parallax development board and cable for programming BASIC Stamp modules. When these items are not available, you may create your own board by duplicating the following diagrams with your own circuits and cables.
Introduction to the BASIC Stamp Figure 1.16: Programming and Run-time Communication Connections for all BS2 models. Note: Though it is not shown, power must be connected to the BASIC Stamp to program it. Also, the programming connections are the same for the BS2p40. Page 28 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
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 an appropriate development board. For the latest Parallax development board selection and documentation, go to www.parallax.com → Products → Development Boards.
Quick Start Guide development board or a breadboard, carefully follow the Programming Connections guidelines on page 27 before proceeding. Figure 2.1: BS1-IC, BS1 Carrier Board, and BS1 Serial Adapter 1) Insert the BASIC Stamp module into its socket, being careful to orient it properly. 2) Connect the 9-pin female end of the serial cable to an available serial port on your computer, then attach the male end to the BS1 Serial Adapter, Note: you cannot us a null modem cable.
2: Quick Start Guide Alkaline Battery Powercell Figure 2.2: BS2-IC and Board of Education 1) Insert the BASIC Stamp module into its socket, being careful to orient it properly. 3 2) Connect the 9-pin female end of the serial cable to an available serial port on your computer, and then connect the male end to the Board of Education. Note: you cannot use a null modem cable.
Quick Start Guide Figure 2.3: Test your PC connection to the BASIC Stamp. Select Run → Identify Verify that the BASIC Stamp was detected on one of the COM ports. 4) Enter a $STAMP Directive into the Editor window by clicking on the toolbar icon for the BASIC Stamp module you are using. (Hold the cursor over the icons for flyover help labels.) The example below shows the Stamp Directive that would be inserted for the BS2.
2: Quick Start Guide 6) Type the line DEBUG “Hello World!” below the compiler directives: ' {$STAMP BS2} ' {$PBASIC 2.5} DEBUG "Hello World!" 7) Download this program into the BASIC Stamp. You may select Run → Run from the menu bar, press CTRL-R from the keyboard, or click on the Run ► icon on the toolbar. Figure 2.5: To run your program, you may use the task bar menu or the Run icon.
Quick Start Guide c) If the error reported a connection problem with the BASIC Stamp, make sure the first line of code indicates the proper module name and verify the programming cable connections, module orientation (in the socket) and that it is properly powered, then try downloading again. 8) Congratulations! You've just written and downloaded your first BASIC Stamp program! The "Hello World!" text that appeared on the screen was sent from the BASIC Stamp, back up the programming cable, to the PC.
3: Using the BASIC Stamp Editor Introducing the BASIC Stamp Editor This section describes the BASIC Stamp Editor for Windows version 2.2. This software supports all 7 BASIC Stamp modules available as of February 2005, and all 3 versions of the PBASIC programming language, PBASIC 1.0, PBASIC 2.0, and PBASIC 2.5. The Programming Environment The BASIC Stamp Windows Editor, shown in Figure 3.1, was designed to be easy to use and mostly intuitive.
Using the BASIC Stamp Editor editor will have its own tab at the top of the page labeled with the name of the file, as seen in Figure 3.2. The full file path of the currently displayed source code appears in the title bar. Source code that has never been saved to disk will default to “Untitled#”; where # is an automatically generated number.
3: Using the BASIC Stamp Editor Figure 3.4: The Split Edit Pane Feature displaying the beginning and end of a long program at the same time. SYNTAX HIGHLIGHTING. NOTE: a complete list of reserved words can be found in Appendix B. Within the edit pane, BASIC Stamp source code files are displayed with syntax highlighting. Syntax Highlighting applies designated colors and character case (upper, lower, capitalized) to reserved words in the PBASIC language . This happens automatically as you type. Table 3.
Using the BASIC Stamp Editor Syntax Element Command Comment Constant -Binary Constant - Decimal Constant - Hexadecimal Constant – Predefined Constant – String Operators Declaration Directive, Conditional Compile Directive, Editor Directive, Target module Input/Output Formatter Selection Search match Variable modifier Variable – predefined Variable, type Text Color Blue Green Default Default Default Purple Red Default Default Gray(Bold) Teal (Bold) Teal (Bold) Navy White on Navy Lime on black Default Purple
3: Using the BASIC Stamp Editor Bookmark from either the Edit menu or from the shortcut menu (rightclick) in the edit pane. EDITING YOUR CODE. Table 3.2: Keyboard Shortcuts for Editing and Navigation Functions. You can navigate through and edit your code in the edit pane with keyboard shortcuts, most of which will be familiar to Windows users.
Using the BASIC Stamp Editor Find and Replace items are saved in the Find: and Replace: field’s dropdown lists. Figure 3.6: The Find/Replace Window. The Find/Replace window will stay visible when using the Find Next and Replace options for quick and convenient source code editing. Using the Replace All function, however, will close the Find/Replace window and perform the designated find/replace operation.
3: Using the BASIC Stamp Editor Figure 3.7: The Integrated Explorer Panel’s Recent list (top), Directory list (middle), and File list (bottom). THE DIRECTORY LIST. The Directory list, right below the Recent list, displays drives and directories in a hierarchical tree fashion. If a directory is selected, the Folders list displays the files in that directory. THE FILE LIST.
. Using the BASIC Stamp Editor Figure 3.8: The Filter List found at the bottom of the Integrated Explorer Panel. The BASIC Stamp Editor automatically associates BASIC Stamp source code file types (.bs1, .bs2, .bse, .bsx, .bsp, .bpe, and .bpx) with itself. This feature can be configured through automatic prompts or through the Preferences → Files & Directories tab.
3: Using the BASIC Stamp Editor Compiler Directives COMPILER DIRECTIVES . The BASIC Stamp Editor supports all of the BASIC Stamp models, and all versions of the PBASIC programming language. Compiler directives must be placed in each program to indicate the desired BASIC Stamp model and language version. In addition, it is sometimes useful to target a given program to a particular communication port. The Directive menu contains options for setting the $STAMP, $PBASIC, and $PORT directives.
Using the BASIC Stamp Editor If you choose to type the $STAMP directive, care must be taken, or it will not be recognized. The directive itself must be enclosed in curly braces, {…}, not parentheses (...) or square brackets [...]. There should not be any spaces between the dollar sign ($) and the word STAMP; however, the directive may contain additional spaces in certain other areas. For example: ' { $STAMP BS2 EXTRA SPACES ARE ALLOWED IN CERTAIN AREAS.
3: Using the BASIC Stamp Editor any BS2 model source code. A $PBASIC directive is required to use version 2.5, which is compatible with all BS2 models. PBASIC 2.5 has enhanced syntax options for several commands, as well as some additional commands not available in PBASIC 2.0. Table 3.4 shows the number of PBASIC commands that are available in each version of the PBASIC language, on each BASIC Stamp model.
Using the BASIC Stamp Editor (such as two BS2s) on two ports and you have two different PBASIC programs to download (one to each BS2). Without this directive, developing and downloading in this case would be a tedious task of always answering the "which BASIC Stamp?" prompt. The $PORT directive can be automatically inserted or modified by selecting the appropriate port from the Directive → Port menu.
3: Using the BASIC Stamp Editor The Device Type column shows the model of BASIC Stamp found on the respective port. For example, in Figure 3.10 above, the BASIC Stamp Editor found a BS2 on COM port 1 and a BS2sx on COM port 4. The Version column displays the firmware version number of the BASIC Stamp module that was found. NOTE: when using a BS1 Serial Adapter, the Loopback column of the Identification window should always indicate “No”.
Using the BASIC Stamp Editor Loopback Echo Yes Yes Yes No No Yes No No Interpretation Serial port and serial cable properly connected. BASIC Stamp properly inserted into socket. If no BASIC Stamp is detected, it is probably because the BASIC Stamp is not connected to power.
3: Using the BASIC Stamp Editor to the BASIC Stamp module (assuming the code is correct and the BASIC Stamp is properly connected). The Download Progress window looks similar to the Identify window with the exception of the additional Download Status progress bar, and the indicator LED by the port transmitting the data. Figure 3.11: The Download Progress Window. If any errors occur, such as communication failure or inability to detect a BASIC Stamp module, you will be prompted appropriately.
Using the BASIC Stamp Editor $STAMP directive in the program, notify you of this change and what it means, and then will try to download to the BS2. Another possibility is having two or more of the same BASIC Stamp model connected to the PC. In this case, the editor will prompt you for clarification as to which BASIC Stamp module you want to download to. In this case using a $PORT directive in your code will save you some tedium in repeatedly responding to such prompts.
3: Using the BASIC Stamp Editor THE EEPROM MAP. The EEPROM map is shown in two scales. The main view is the detailed EEPROM map, which displays the data in hexadecimal format in each location. The condensed EEPROM map is the vertical region on the left that shows a small-scale view of the entire EEPROM; the red square over it corresponds to the scroll bar handle in the detailed EEPROM map and indicates the portion of the EEPROM that is currently visible in the detailed EEPROM map.
Using the BASIC Stamp Editor Figure 3.14: Demo program using the Debug Terminal The text in the Debug Terminal’s Receive pane (blue area) prompts the user to enter a number into the Transmit pane (white area) . After typing the number 10 and pressing Enter, the Receive pane displays the number in decimal, hexadecimal, and binary format as dictated by the program (Figure 3.15). Figure 3.15: Debug Terminal output after entering a number.
3: Using the BASIC Stamp Editor automatically opened by the editor, however, if manually opened, these fields will be enabled to allow manual configuration. The signal status LEDs turn bright green when activity on the indicated port line is detected. The signal checkboxes (DTR and RTS) can be selected to set or clear the respective output line on the port.
Using the BASIC Stamp Editor Figure 3.16: The Help file contains the complete PBASIC syntax documentation. The current help files contain the entire PBASIC syntax documentation. In addition, the example demo code programs that appear after most command descriptions in Chapter 5 are automatically placed in default directories during the BASIC Stamp Editor v2.2 installation. These programs can be accessed via hyperlinks within the help file.
3: Using the BASIC Stamp Editor TIP OF THE DAY. The Tip of the Day function displays a new message each time you run the BASIC Stamp Editor. There are many useful tips, and you may browse through them any time with the Next Tip and Previous Tip buttons. You may also use the Edit Tips option to change the contents of any tip. All tips are contained in a single file, named Stamp_Tips.txt, that is stored in the editor’s installation directory, usually a path similar to C:\Program Files\Parallax Inc\Stamp Edit
Using the BASIC Stamp Editor preferences are specific to the editor, and are not saved as part of any BASIC Stamp program that you may have open while setting preferences. Figure 3.18: The Editor Appearance Tab under Edit → Preferences. The default font size for the edit pane is 10 point, but there are 12 fixed options ranging from 8 to 40 point. The Editor Font size setting and all the other text attribute settings under this tab will not affect the text in the Debug Terminal.
3: Using the BASIC Stamp Editor CUSTOMIZED SYNTAX HIGHLIGHTING. To create a custom scheme, select a default scheme you wish to modify, and click on the Copy Scheme button. Then, select (highlight) an element within the Syntax Element list, and apply new Text Attributes with the checkboxes and drop-down menus to the right. As you try various text attributes and color combinations, the Show Preview Example checkbox lets you audition your custom scheme without closing the Preferences window.
Using the BASIC Stamp Editor In addition to the actual character used for the Tab key, there are three behaviors of tabbing employed by the editor: Smart Tabs, Fixed Tabs and Fixed plus Smart Tabs. TAB BEHAVIOR. Figure 3.19: The Editor Operation Tab under Edit → Preferences. Smart Tabs (Figure 3.20) cause the tab key to move the cursor to a position that is aligned with the nearest break between words in nearby lines above the current line.
3: Using the BASIC Stamp Editor make the Tab key move the cursor to positions, 3, 5, 7, 9 and 11, then afterwards, 13, 15, 17, 19, etc. (a multiple of two (11 – 9 = 2) after the last listed position. FIXED PLUS SMART TABS. The last option is a mixture of the first two, Fixed plus Smart Tabs (Figure 3.22); it is the default and recommended setting.
Using the BASIC Stamp Editor The Fixed Tab Positions list is used to provide a list of desired fixed tab positions (used with Fixed Tabs or Fixed plus Smart Tabs options). The list can be a single number, or a list of comma separated numbers in ascending order. The allowable range is 2 to 512 and the list size is virtually unlimited. When multiple values are entered, the difference between the last two values will be used to set tab positions beyond the last position.
3: Using the BASIC Stamp Editor Figure 3.23: The Files and Directories Tab under Edit → Preferences. BACKUP COPY. Check the “Create backup copy” option to cause the editor to automatically create a backup copy of any file that is being re-saved under the same name. The backup file will be stored in the same directory and named the same as the existing file, but with a .bak extension appended to the existing extension. For example, “test.bs2” becomes “test.bs2.bak” and then the new file called “test.
Using the BASIC Stamp Editor into a single BASIC Stamp Editor, including an editor that is already running. The “Multiple Editors” option will cause a new BASIC Stamp Editor to open each time you open an associated BASIC Stamp file from any Explorer-shell. Also, by associating BASIC Stamp source code with the editor, Windows will provide an “Open With Stamp Editor” option when right-clicking on that source code from any Explorer-shell. OPEN WITH STAMP EDITOR OPTION.
3: Using the BASIC Stamp Editor You may use the Clear and Browse… buttons under the Module Directories list to select new default directory locations for each model of BASIC Stamp. These new folders will then appear as options when you use the File → Open From... and File → Save To... menus as well as the Recent list in the integrated explorer panel.
Using the BASIC Stamp Editor Figure 3.24: The Debug Appearance Tab under Edit → Preferences. The “Wrap Text to” field gives two options, Pane and Page. Wrapping to Pane is the default, and causes text to wrap at the right edge of the Receiver pane, reflecting the current visible size that the user happens to have set for the Debug Terminal’s window. Wrapping to Page, however, causes text to wrap at a specific line width, regardless of the user’s current Debug Terminal window size.
3: Using the BASIC Stamp Editor the screen. If the default is used, for example, you could receive 1024 lines worth of text from a BASIC Stamp, and still be able to scroll back and view the first line that was received. Upon receiving the 1025th line of text, the first line of text is pushed out of the buffer and is lost for good, making the first visible line in the Receive pane actually be the 2nd line of text that was received.
Using the BASIC Stamp Editor Under the Debug Function tab (Figure 3.25), checkboxes allow enabling or disabling of special processing for 16 different control characters. The default is for all 16 control characters to be processed, but you may disable one or more of them if you are using the Debug Terminal to view data coming from a device other than a BASIC Stamp. DEBUG FUNCTION PREFERENCES. Figure 3.25: The Debug Function Tab under Edit → Preferences.
3: Using the BASIC Stamp Editor DEBUG PORT PREFERENCES. Under the Debug Port tab (Figure 3.26), each of the four (4) Debug Terminal’s default COM port settings may be configured separately. These settings are only used when the Debug Terminal is manually opened. Figure 3.26: The Debug Port Tab under Edit → Preferences. You may assign a specific COM port from the available drop-down list; this list can be changed by clicking on the (...) button to the right.
Using the BASIC Stamp Editor Advanced Compilation Techniques For BS2e, BS2sx, BS2p, BS2pe and BS2px modules, each editor page can be a separate project, or part of a single project. A project is a set of up to eight files that should all be downloaded to the 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, 2p, 2pe, and 2px modules support multi-file projects. INTRODUCTION TO BASIC STAMP PROJECTS.
3: Using the BASIC Stamp Editor EASY STEPS TO CREATING MULTI-FILE PROJECTS. To create a project consisting of multiple files, follow these steps: 1. 2. Create the first file in the editor and save it (we'll call it Sample.bsx). This will be the program that is downloaded into program slot 0. Create at least one other file in the editor and save it also (we'll call it NextProgram.bsx). Note: At this point the editor tabs will be: 0:Sample.bsx and 0:NextProgram.bsx.
Using the BASIC Stamp Editor The editor has the ability to treat projects as one logical unit and can download each of the associated source code files at once. In order to minimize download time for large projects a Project Download Mode is available in the Preferences window. The available modes are: “Modified” (the default), “All” or “Current” and are explained below. This item only affects download operations for the BS2e, BS2sx, BS2p and BS2pe. See Table 3.7.
3: Using the BASIC Stamp Editor Lets look at the syntax and examples for each conditional compile directive. For an explanation of syntax conventions, see page 128. #DEFINE SYNTAX. #DEFINE Symbol { = Value } #DEFINE allows the programmer to create custom, compile-time, symbols for use within conditional compile control structures. • Symbol is a unique symbol name that will optionally represent a Value. • Value is an optional constant/expression specifying the value of Symbol.
Using the BASIC Stamp Editor False (0). Upon compiling this example, the #IF…#THEN statement will evaluate DebugMode, which is False (because it is undefined) and then will not allow the DEBUG statement to be compiled. Only the STOP command will be compiled into the program in this example.
3: Using the BASIC Stamp Editor #IF…#THEN is a conditional compile structure similar to the run-time IF…THEN command except that, at compile time, #IF…#THEN evaluates Condition(s) and, if it is True, compiles the Statement(s) following #THEN, otherwise it compiles the Statement(s) following #ELSE. • Condition is a statement that can be evaluated as True or False during compile-time. • Statement is any valid PBASIC instruction. Example: ' {$PBASIC 2.
Using the BASIC Stamp Editor #SELECT...#CASE SYNTAX. #SELECT Expression #CASE Condition(s) Statement(s) { #CASE Condition(s) Statement(s) #CASE #ELSE Statement(s) } #ENDSELECT #SELECT…#CASE is a conditional compile structure similar to the runtime SELECT…CASE command except that, at compile time, #SELECT…#CASE evaluates Expression and then conditionally compiles a block of code based on comparison to Condition(s).
3: Using the BASIC Stamp Editor #ERROR SYNTAX. #ERROR Message #ERROR displays a compile-time error. This allows the programmer to flag fatal errors during compilation. • Message is the error message string, enclosed in quotes. Example: ' {$PBASIC 2.5} #DEFINE I2CReady = (($STAMP = BS2p) OR ($STAMP = BS2pe) OR ($STAMP = BS2px)) #IF NOT I2CReady #THEN #ERROR "BS2p, BS2pe, or BS2px is required for this program.
Using the BASIC Stamp Editor customers using BASIC Stamp-based products, you can release firmware updates to them in this manner. Object code can be saved as a separate .obj file (downloadable with the StampLoader.exe program) or as a single executable (integrated with the StampLoader.exe inside of it). The single executable method provides a simpler way to pass your firmware update on to your customers.
3: Using the BASIC Stamp Editor Figure 3.28: The Generate Object Code Window. In the example above, we chose to generate a single executable with custom names and messages as shown. Then we clicked the Generate… button (which prompted us for a file name) and the file was created. When a user runs the file we just generated, they see a screen similar to the figure below: Figure 3.29: Example customized StampLoader.exe file. BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
Using the BASIC Stamp Editor Another feature of interest to some developers is the BASIC Stamp Editor’s Command Line interface. This interface provides for command line, batch file or third-party driven control of the editor. The Stampw.exe program is a Win32 application that can be run through any standard method. When run with the command-line options, however, it provides special features that developers and product manufacturing managers may find useful.
3: Using the BASIC Stamp Editor Table 3.9: Command Line Switches Command /Com# /ReadOnly /Identify /Tokenize /Download /Updates /NoDebug /NoPrompts /Pipe master_file /Help Function Specify com port (serial port) to download to. # is a valid com port number. NOTE: must be one word, i.e.: Com2 indicates com port 2. Open source_file in read-only mode. The Ctrl key acts as a download key when in read-only mode. Requires source_file argument.
Using the BASIC Stamp Editor Page 80 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
4: BASIC Stamp Architecture – Memory Organization BASIC Stamp Architecture Introduction This chapter provides detail on the architecture (RAM usage) and math functions of the BS1, BS2, BS2e, BS2sx, BS2p, BS2pe, and BS2px. The following icons will appear to indicate where there are differences among the various BASIC Stamp models: One or more of these icons indicates the item applies only to the BS1, BS2, BS2e, BS2sx, BS2p, BS2pe, or BS2px respectively.
BASIC Stamp Architecture – Memory Organization sets the corresponding I/O pin to an output direction and a low bit (0) sets the corresponding I/O pin to an input direction. The remaining words (W0 – W6) are available for general-purpose use. Each word consists of separately addressable bytes and the first two bytes (B0 and B1) are bit addressable as well. You may assign other names (symbols) to these RAM registers as shown in section "Defining and Using Variables", below.
4: BASIC Stamp Architecture – Memory Organization the variable RAM for these models, only the BS2p40 module has the extra 16 I/O pins for which this feature is intended. THE INPUT/OUTPUT VARIABLES. The word variable INS is unique in that it is read-only. The 16 bits of INS reflect the state of I/O pins P0 through P15. It may only be read, not written. OUTS contains the states of the 16 output latches. DIRS controls the direction (input or output) of each of the 16 I/O pins.
BASIC Stamp Architecture – Memory Organization The INS variable always shows the state of the I/O pins themselves, regardless of the direction of each I/O pin. We call this, "reading the pins". If a pin was set to an input mode (within DIRS) and an external 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 2 The 40-pin BS2p uses the first three words for I/O even though it has twice as many I/O pins. This is done with the AUXIO, MAINIO, and IOTERM commands, which effectively switch the auxiliary I/O registers in and out of the INS, OUTS, and DIRS locations. Just like the I/O variables, the general-purpose variables have predefined names: W0 through W12 and B0 through B25.
BASIC Stamp Architecture – Defining Variables number of bits of storage for the variable. NOTE: The top example is for the BS1 and the bottom example is for all BS2 models. There are certain rules regarding symbol names. Symbols must start with a letter or underscore, can contain a mixture of letters, numbers, and underscore (_) characters, and must not be the same as PBASIC reserved words, or labels used in your program. Additionally, symbols can be up to 32 characters long.
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-sized 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; the BASIC Stamp will arrange them in RAM as it sees fit.
BASIC Stamp Architecture – Defining Arrays myBytes idx VAR VAR Byte(10) Nib ' Define 10-byte array ' Define 4-bit var FOR idx = 0 TO 9 myBytes(idx) = idx * 13 NEXT ' Repeat with idx = 0, 1, 2...9 ' Write idx * 13 to each cell FOR idx = 0 TO 9 DEBUG ? myBytes(idx) NEXT STOP ' Repeat with idx = 0, 1, 2...
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 "Displaying Strings (Byte Arrays)" in the DEBUG command description on page 166 for more information. An alias is an alternative name for an existing variable. For example: ALIASES AND VARIABLE MODIFIERS.
BASIC Stamp Architecture – Aliases and Modifiers Symbol LOWBYTE HIGHBYTE BYTE0 BYTE1 LOWNIB HIGHNIB NIB0 NIB1 NIB2 NIB3 LOWBIT HIGHBIT BIT0 BIT1 BIT2 BIT3 BIT4 … BIT7 BIT8 … Bit15 Definition low byte of a word high byte of a word byte 0 (low byte) of a word byte 1 (high byte) of a word low nibble of a word or byte high nibble of a word or byte nib 0 of a word or byte nib 1 of a word or byte nib 2 of a word nib 3 of a word low bit of a word, byte, or nibble high bit of a word, byte, or nibble bit 0 of a wor
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. In the example above, when myBytes() is addressed as a byte array, it has 10 byte-sized cells numbered 0 through 9. When it is addressed as a nibble array, using myBytes.
BASIC Stamp Architecture – Scratch Pad RAM The BS2e, BS2sx, BS2p, BS2pe, and BS2px have some additional RAM called Scratch Pad RAM. The BS2e and BS2sx have 64 bytes of Scratch Pad RAM (0 to 63) and the BS2p, BS2pe, and BS2px have 136 bytes of Scratch Pad RAM (0-135). Scratch Pad RAM can only be accessed with the GET and PUT commands and cannot have variable names assigned to it. Table 4.4 shows the layout of all SPRAM registers.
4: BASIC Stamp Architecture – Scratch Pad RAM Table 4.4: Layout of SPRAM Registers. NOTE: Scratch Pad RAM can only be accessed with the GET and PUT commands. Scratch Pad RAM cannot have variable names assigned to it. Location 0...62 64..126 BS2e and BS2sx General Purpose RAM Bits 0-3: Active program slot number.
BASIC Stamp Architecture – Constants and Expressions Suppose you’re working on a program called “Three Cheers” that flashes LEDs, makes hooting sounds, and activates a motor that crashes cymbals together, all in sets of three. A portion of your PBASIC program might contain something like: CONSTANTS AND COMPILE-TIME EXPRESSIONS. 1 All 2 FOR counter = 1 TO 3 GOSUB Make_Cheers NEXT ... FOR counter = 1 TO 3 GOSUB Blink_LEDs NEXT ...
4: BASIC Stamp Architecture – Constants and Expressions Once created, named constants may be used in place of the numbers they represent. For example: 1 SYMBOL Cheers = 3 ' Number of cheers. FOR counter = 1 TO Cheers GOSUB Make_Cheers NEXT -- or -All 2 Cheers CON 3 ' Number of cheers. FOR counter = 1 TO Cheers GOSUB Make_Cheers NEXT That code works exactly the same as the corresponding FOR…NEXT loop in the previous example.
BASIC Stamp Architecture – Number Representations Now, assuming that you used the constant Cheers wherever your program needed ‘the number of cheers,’ your upgrade would be done. On all BS2 models, you can take this idea a step further by defining constants with expressions; groups of math and/or logic operations that the editor software solves (evaluates) at compile-time (the time right after you start the download and before the BASIC Stamp starts running your program).
4: BASIC Stamp Architecture – Number Representations everyday decimal (base-10) system. However, you may also use hexadecimal (base-16; also called hex) or binary (base-2). Since the symbols used in decimal, hex and binary numbers overlap (e.g.
BASIC Stamp Architecture – Number Representations and the last nibble is 6; this corresponds exactly to the BCD form of the decimal number 4096. The second line in the above example uses the HEX Conversion Formatter within the DEBUG command (see DEBUG, page 159) to output the BCD value 4096 to the Debug Terminal.
4: BASIC Stamp Architecture – PIN Symbols expression 100+90 into a compile-time expression like OneNinety CON 100+90. To sum up: compile-time expressions are those that involve only constants; once a variable is involved, the expression must be solved at run-time. That’s why the line “NotWorking CON 3 * result” would generate an error message. The CON directive works only at compile-time and result is a variable; variables are not allowed in compile-time expressions.
BASIC Stamp Architecture – PIN Symbols the Condition argument in the IF…THEN statement will always evaluate to false because signal is a constant equal to 1, and “1 = 0” is false. What the user really meant to happen is something like: IF IN1 = 0 THEN Wait because IN1 is the input variable representing the current state of I/O pin 1. This situation is perfect for the PIN directive: ' {$PBASIC 2.
4: BASIC Stamp Architecture – PIN Symbols All 2 ' {$PBASIC 2.5} signal PIN 2 OUTPUT signal signal = 1 ' pin-type symbol representing I/O 2 ' set signal pin to output ' set signal high The OUTPUT command treats signal as a constant equal to 2 and the signal = 1 statement treats signal as a variable equal to the output variable for the defined pin (OUT2 in this case).
BASIC Stamp Architecture – PIN Symbols PIN_Symbol behaves like a constant: 1. when used in a command’s Pin argument. Example: OUTPUT 2. PIN_Symbol when used in the index of an array. Example: myArray(PIN_Symbol) = 25 PIN_Symbol behaves like an input variable (INx): 1. when used in a command’s non-Pin argument that expects to read a variable/constant/expression. Example: DEBUG BIN PIN_Symbol 2. when used in a command’s Condition argument. Example: IF PIN_Symbol = 1 THEN… 3.
4: BASIC Stamp Architecture – Order of Operations The BASIC Stamp solves math problems in the order they are written: from left to right. The result of each operation is fed into the next operation. So to compute 12+3*2/4, the BASIC Stamp goes through a sequence like this: ORDER OF OPERATIONS. 12 + 3 = 15 15 * 2 = 30 30 / 4 = 7 Since the BASIC Stamp performs integer math (whole numbers only) 30 / 4 results in 7, not 7.5. We’ll talk more about integers in the next section.
BASIC Stamp Architecture – Math and Operators All BS2 models can interpret twos complement negative numbers correctly in DEBUG and SEROUT instructions using formatters like SDEC (for signed decimal). In calculations, however, it assumes that all values are positive. This yields correct results with two’s complement negative numbers for addition, subtraction, and multiplication, but not for division. The standard operators we just discussed: +, - ,* and / all work on two values; as in 1 + 3 or 26 * 144.
4: BASIC Stamp Architecture – Math and Operators, ABS All 2 value VAR Byte value = - 99 DEBUG SDEC ? 1 All 2 value ' Show signed decimal result (157) We expected -99 to be displayed but what we got was 157. How did -99 become 157? Let’s look at the bits: 99 is %01100011 binary. When the BASIC Stamp negates 99, it converts the number to 16 bits %0000000001100011, and then takes the two’s complement, %1111111110011101.
BASIC Stamp Architecture – COS, DCD, ~, result VAR Word result = -99 ' ' ' ' DEBUG SDEC ? result DEBUG SDEC ? ABS result Put -99 ...(2's Display Display into result complement format) as a signed # as a signed # The Cosine operator (COS) returns the two’s complement, 16-bit cosine of an angle specified as an 8-bit “binary radian” (0 to 255) angle. COS is the same as SIN in all respects, except that the cosine function returns the x distance instead of the y distance.
4: BASIC Stamp Architecture – NCD, SIN All 2 result VAR Word result = 99 ' ' ' ' ' DEBUG SDEC ? result result = -result DEBUG SDEC ? result ENCODER: NCD All 2 The Encoder operator (NCD) is a "priority" encoder of a 16-bit value. NCD takes a 16-bit value, finds the highest bit containing a 1 and returns the bit position plus one (1 through 16). If the input value is 0, NCD returns 0.
BASIC Stamp Architecture – SIN, SQR Figure 4.1: 127-Unit Circle To convert brads to degrees, multiply by 180 then divide by 128, or simply multiply with “*/ 360”. To convert degrees to brads, multiply by 128, then divide by 180.
4: BASIC Stamp Architecture – + doing its integer-only math. So it computes the square root of 100 as 10 (correct), but the square root of 99 as 9 (the actual is close to 9.95). Example: DEBUG ? SQR DEBUG ? SQR ' Display square root of 100 (10) ' Display of square root of 99 ' ...(9 due to truncation) Table 4.6 lists the available Binary (two-argument) Operators. BINARY OPERATORS. Table 4.6: Binary Operators. Note: some binary operators are not supported by all BASIC Stamp models.
BASIC Stamp Architecture – +, -, * For example: SYMBOL SYMBOL value1 value2 value1 DEBUG value1 value2 = = W0 W1 = - 99 = 100 = value1 + value2 value1 1 ' Add the numbers ' Show the result (1) -- or -value1 value2 value1 value2 value1 DEBUG VAR VAR Word Word All = - 1575 = 976 = value1 + value2 SDEC ? value1 ' Add the numbers ' Show the result (-599) The Subtraction operator (-) subtracts variables and/or constants, returning a 16-bit result.
4: BASIC Stamp Architecture – *, ** 1 SYMBOL SYMBOL value1 value2 value1 DEBUG value1 value2 = = W0 W1 = 1000 = 19 = value1 * value2 value1 ' Multiply value1 by value2 ' Show the result (19000) VAR VAR = 1000 = - 19 = value1 SDEC ? ' Multiply value1 by value2 ' Show the result (-19000) -- or -All MULTIPLY HIGH: ** 2 1 All 2 1 value1 value2 value1 value2 value1 DEBUG Word Word * value2 value1 The Multiply High operator (**) multiplies variables and/or constants, returning the high 16 bits of
BASIC Stamp Architecture – **, */ multiply the fraction part by 65536. For example, 0.72562 is represented by 47554, which is 0.72562 * 65536. SYMBOL SYMBOL Frac value = 47554 = W0 value = 10000 value = value ** Frac DEBUG value ' = 0.72562 x 65536 1 ' Multiply 10000 by 0.72562 ' Show result (7256) -- or – Frac value CON VAR value = 10000 value = value ** Frac DEBUG ? value 47554 Word ' = 0.72562 x 65536 VAR Word value1 = 100 value1 = value1*/ $0180 DEBUG ? value1 2 ' Multiply 10000 by 0.
4: BASIC Stamp Architecture – /, // DIVIDE: / 1 All 2 1 The Divide operator (/) divides variables and/or constants, returning a 16-bit result. Works exactly as you would expect with unsigned integers from 0 to 65535. Use / only with positive values; signed values do not provide correct results.
BASIC Stamp Architecture – //, ATN returns the remainder, 4 in this example. Naturally, numbers that divide evenly, such as 1000/5, produce a remainder of 0.
4: BASIC Stamp Architecture – ATN, HYP, MIN Figure 4.2: ATN and HYP operators in the PBASIC unit circle HYPOTENUSE: HYP All 2 The Hypotenuse operator (HYP) returns the length of the hypotenuse of a right triangle with sides of length A and B. The syntax of HYP is: SideA HYP SideB where SideA and SideB are the side lengths of a right-triangle (the order isn’t important). Another application of HYP is to calculate the distance between the origin (0, 0) and a point (X, Y) in a Cartesian coordinate system.
BASIC Stamp Architecture – MIN, MAX MIN works in positive math only; its comparisons are not valid when used on two’s complement negative numbers, since the positive-integer representation of a number like -1 ($FFFF or 65535 in unsigned decimal) is larger than that of a number like 10 ($000A or 10 decimal). Use MIN only with unsigned integers. Because of the way fixed-size integers work, you should be careful when using an expression involving MIN 0.
4: BASIC Stamp Architecture – MAX, DIG, <<, >> 1 SYMBOL SYMBOL value1 value2 = W0 = W1 FOR value1 = 0 TO 100 STEP 10 value2 = value1 MAX 50 DEBUG value2 NEXT ' Walk value1 from 0 to 100 ' Use MAX to clamp at 50 ' Show "clamped" value -- or -All 2 value VAR Word FOR value = 0 TO 100 STEP 10 DEBUG ? value MAX 50 NEXT DIGIT: DIG All 2 ' Walk value from 0 to 100 ' Show value, use MAX clamp at 50 The Digit operator (DIG) returns the specified decimal digit of a 16-bit positive value.
BASIC Stamp Architecture – >>, REV, &, | lost; bits shifted into the left end of the number are 0s. Shifting the bits of a value right n number of times has the same effect as dividing that number by 2 to the nth power. For instance 100 >> 3 (shift the bits of the decimal number 100 right three places) is equivalent to 100 / 23.
4: 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.
BASIC Stamp Architecture – &/, |/ DEBUG BIN8 ? %00001111 ^ %10101001 ' Show result of XOR (%10100110) The And Not operator (&/) returns the bitwise AND NOT of two values. Each bit of the values is subject to the following logic: All 2 AND NOT: &/ 1 0 AND NOT 0 = 0 0 AND NOT 1 = 0 1 AND NOT 0 = 1 1 AND NOT 1 = 0 The result returned by &/ will contain 1s in any bit positions in which the first value is 1 and the second value is 0.
4: BASIC Stamp Command Reference – ^/ XOR NOT: ^/ 1 The Xor Not operator (^/) returns the bitwise XOR NOT of two values. Each bit of the values is subject to the following logic: 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.
BASIC Stamp Architecture Page 122 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference Introduction This chapter provides details on all three versions of the PBASIC Programming Language. A categorical listing of all available PBASIC commands is followed by an alphabetized command reference with syntax, functional descriptions, and example code for each command. PBASIC LANGUAGE VERSIONS There are three forms of the PBASIC language: PBASIC 1.0 (for the BS1), PBASIC 2.0 (for all BS2 models) and PBASIC 2.5 (for all BS2 models).
BASIC Stamp Command Reference Feature Categories New Items DEBUGIN, Additional Commands DO...LOOP, EXIT, ON. SELECT...CASE IF...THEN, Enhanced Commands GET, PUT, READ, WRITE Description Allows easier user input and program control. See individual command descriptions. Improves program control, and SPRAM and EEPROM access. See individual command descriptions. Provides flexible, context-sensitive I/O pin Additional Directive PIN references; see page 99.
5: BASIC Stamp Command Reference All 2 ON2.5 1 All 2 All Jump to address or subroutine specified by an offset. RETURN Return from subroutine. RUN Switch execution to another program slot. POLLRUN Switch execution to another program page upon the occurrence of a polled interrupt. 2 SELECT …CASE2.5 All 2 STOP Evaluate expression and conditionally execute a block of code based on comparison to multiple conditions. Halt program execution until BASIC Stamp is reset.
BASIC Stamp Command Reference NUMERICS 1 LET Optional instruction assignments. to perform variable 1 All 2 LOOKUP Look up data specified by offset and store in variable. This instruction provides a means to make a lookup table. 1 All 2 LOOKDOWN Find target’s matching value in table and store match number (0-N) in variable. 1 All 2 RANDOM Generate a pseudo-random number. DIGITAL I/O CONFIGPIN Configure pin properties. 1 All 2 INPUT Make pin an input. 1 All 2 OUTPUT Make pin an output.
5: BASIC Stamp Command Reference ASYNCHRONOUS SERIAL I/O 1 All 2 SERIN Input data in an asynchronous serial stream. 1 All 2 SEROUT Output data in an asynchronous serial stream. OWIN Input data from a 1-wire device. OWOUT Output data to a 1-wire device. SYNCHRONOUS SERIAL I/O 1 All 2 SHIFTIN Shift data in from synchronous serial device. 1 All 2 SHIFTOUT Shift data out to synchronous serial device. I2CIN Input data from I2C serial device. I2COUT Output data to I2C serial device.
BASIC Stamp Command Reference POWER CONTROL 1 All 2 NAP Nap for a short period. Power consumption is reduced. 1 All 2 SLEEP Sleep for 1-65535 seconds. Power consumption is reduced. 1 All 2 END Sleep until the power cycles or the PC connects. Power consumption is reduced. PROGRAM DEBUGGING 1 All 2 All DEBUG 2 DEBUGIN2.5 Send information to the PC for viewing in the Debug Terminal’s Receive windowpane.
5: BASIC Stamp Command Reference – AUXIO AUXIO BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px AUXIO Function Switch from control of main I/O pins to auxiliary I/O pins (on the BS2p40 only). Quick Facts Table 5.2: AUXIO Quick Facts. I/O pin IDs Special Notes Related Commands BS2p, BS2pe, and BS2px 0 – 15 (just like main I/O, but after AUXIO command, all references affect physical pins 21 – 36).
AUXIO - BASIC Stamp Command Reference Here is a simple AUXIO example: HIGH 0 AUXIO LOW 0 A SIMPLE AUXIO EXAMPLE. ' make P0 high ' select auxiliary pins ' make X0 low The first line of the above example will set I/O pin 0 of the main I/O pins (P0, physical pin 5) high. Afterward, the AUXIO command tells the BASIC Stamp that all commands following it should affect the auxiliary I/O pins. The following LOW command will set I/O pin 0 of the auxiliary I/O pins (X0, physical pin 21) low.
5: BASIC Stamp Command Reference – AUXIO IOTERM port TOGGLE 3 port = ~port PAUSE 1000 LOOP END ' ' ' ' ' ' Switch to main or aux I/Os -- depending on port Toggle state of I/O pin 3 -- on main and aux, alternately Invert port 1 second delay BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
AUXIO - BASIC Stamp Command Reference Page 132 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – BRANCH BRANCH 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px BRANCH Offset, ( Address0, Address1, ...AddressN ) BRANCH Offset, [ Address0, Address1, ...AddressN ] Function 1 NOTE: Expressions are not allowed as arguments on the BS1. Go to the address specified by offset (if in range). • Offset is a variable/constant/expression (0 – 255) that specifies the index of the address, in the list, to branch to (0 – N). • Addresses are labels that specify where to go.
BRANCH – BASIC Stamp Command Reference Demo Program (BRANCH.bs1) 1 ' BRANCH.bs1 ' This program shows how the value of idx controls the destination of the ' BRANCH instruction. ' {$STAMP BS1} ' {$PBASIC 1.0} SYMBOL idx = B2 Main: DEBUG "idx: ", #idx, " " BRANCH idx, (Task_0, Task_1, Task_2) DEBUG "BRANCH target error...", CR, CR Next_Task: idx = idx + 1 // 4 GOTO Main ' branch to task ' ... unless out of range ' force idx to be 0..
5: BASIC Stamp Command Reference – BRANCH PAUSE 250 GOTO Main Task_0: DEBUG "BRANCHed to Task_0", CR GOTO Next_Task Task_1: DEBUG "BRANCHed to Task_1", CR GOTO Next_Task Task_2: DEBUG "BRANCHed to Task_2", CR GOTO Next_Task BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
BRANCH – BASIC Stamp Command Reference Page 136 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – BUTTON BUTTON 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px BUTTON Pin, DownState, Delay, Rate, Workspace, TargetState, Address Function 1 NOTE: Expressions are not allowed as arguments on the BS1. The range of the Pin argument on the BS1 is 0 – 7. Monitor and process a pushbutton input, perform auto-repeat, and branch to address if button is in target state. Button circuits may be active-low or active-high.
BUTTON – BASIC Stamp Command Reference ensure that the contact remains in a specified state for a minimum duration, spurious multiple inputs caused by contact noise can be eliminated. The BUTTON instruction helps prevent this noise from being interpreted as more than one switch action; this is the function of the Delay parameter. For a demonstration of switch bounce, see the demo program for the COUNT instruction.
5: BASIC Stamp Command Reference – BUTTON Figure 5.1: Sample BUTTON circuits. Active-high (left) and active-low (right). 1 Demo Program (BUTTON.bs1) ' ' ' ' ' ' ' BUTTON.bs1 Connect an active-low circuit to pin P0 of the BS1. When you press the button, the DEBUG screen will display an asterisk (*). The program, as shown below, will print an asterisk at the first button press, then delay approximately one second (200 x 5 ms PAUSE) before auto-repeating at a rate of approximately 100 ms (5 x 20 ms).
BUTTON – BASIC Stamp Command Reference Demo Program (BUTTON.bs2) ' ' ' ' ' ' ' BUTTON.bs2 Connect an active-low circuit to pin P0 of the BS2. When you press the button, the DEBUG screen will display an asterisk (*). The program, as shown below, will print an asterisk at the first button press, then delay approximately one second (200 x 5 ms PAUSE) before auto-repeating at a rate of approximately 100 ms (5 x 20 ms).
5: BASIC Stamp Command Reference – COMPARE COMPARE BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px COMPARE Mode, Variable Function Enable or disable comparator, compare voltages on P1 and P2 and retrieve comparison result to store in Variable. • Mode is a variable/constant/expression (0 – 2) that enables or disables the comparator (input pins P1 and P2) and determines if the optional comparator output pin (pin P0) is enabled or not. See Table 5.4 for an explanation of the Mode values.
COMPARE – BASIC Stamp Command Reference input voltage on P1 was greater than that of P2. Result and the output pin P0 will be 1 if the input voltage on P1 was less than that of P2. Note that the comparator hardware operates independently of the execution speed of the BS2px and will continue to run and update P0 if Mode = 1, even during sleep mode (execution of END, NAP, POLLWAIT 8, or SLEEP commands). To avoid spurious current draw during sleep mode, disable the comparator first. Demo Program (COMPARE.
5: BASIC Stamp Command Reference – CONFIGPIN CONFIGPIN BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px CONFIGPIN Mode, PinMask Function Configure special properties of I/O pins. • Mode is a variable/constant/expression (0 – 3), or one of four predefined symbols, that specifies the I/O pin property to configure: Schmitt Trigger, Logic Threshold, Pull-up Resistor or Output Direction. See Table 5.5 for an explanation of Mode values.
CONFIGPIN – BASIC Stamp Command Reference Every high bit (1) in the PinMask argument enables the output direction for the corresponding I/O pin while every low bit (0) disables the output direction. In the above example, I/O pins 8, 4, 1, and 0 are set to the output direction and all other I/O pins are set to the input direction.
5: BASIC Stamp Command Reference – CONFIGPIN The logic threshold for TTL is 1.4 volts; a voltage below 1.4 is considered to be a logic 0 while a voltage above 1.4 is considered to be a logic 1. The logic threshold for CMOS is 50% of Vdd; a voltage below ½ Vdd is considered a logic 0 while a voltage above ½ Vdd is considered a logic 1.
CONFIGPIN – BASIC Stamp Command Reference For the CONFIGPIN command’s SCHMITT mode, a high bit (1) in the PinMask argument enables the Schmitt Trigger on the corresponding I/O pin and a low bit (0) disables the Schmitt Trigger. The following example sets Schmitt Triggers on I/O pins 7, 6, 5, and 4, and sets all other I/O pins to normal mode.
5: BASIC Stamp Command Reference – CONFIGPIN " | | | |", CR, "---- ---- ---- ----" Main: DO 'Display input pin states DEBUG CRSRXY,0,12, BIN4 IND, " ", BIN4 INC, " ", BIN4 INB, " ", BIN4 INA LOOP BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
CONFIGPIN – BASIC Stamp Command Reference Page 148 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – COUNT COUNT All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px COUNT Pin, Duration, Variable Function Count the number of cycles (0-1-0 or 1-0-1) on the specified pin during the Duration time frame and store that number in Variable. • Pin is a variable/constant/expression (0 – 15) that specifies the I/O pin to use. This pin will be set to input mode. • Duration is a variable/constant/expression (1 – 65535) specifying the time during which to count.
COUNT – BASIC Stamp Command Reference width (on the BS2). Refer to Table 5.6 for data on other BASIC Stamp models. 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 module’s logic threshold slowly enough that noise causes false counts. You can fix this by passing the signal through a Schmitt Trigger, like one of the inverters of a 74HCT14.
5: BASIC Stamp Command Reference – COUNT PAUSE 500 DEBUG "GO!", CR COUNT PushBtn, (Capture */ DurAdj), cycles DEBUG CR, "Your score: ", DEC cycles, CR PAUSE 3000 DEBUG "Press button to go again." DO : LOOP UNTIL (PushBtn = 0) ' wait for button press LOOP END BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
COUNT – BASIC Stamp Command Reference Page 152 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – DATA DATA 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px (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. • DataItem is a constant/expression (0 – 65535) indicating a value, and optionally how to store the value. Quick Facts Table 5.7: DATA Quick Facts.
DATA – BASIC Stamp Command Reference DATA uses a counter, called a pointer, to keep track of available EEPROM addresses. The value of the pointer is initially 0. When a program is downloaded, the DATA directive stores the first byte value at the current pointer address, then increments (adds 1 to) the pointer. If the program contains more than one DATA directive, subsequent DATAs start with the pointer value left by the previous DATA.
5: BASIC Stamp Command Reference – DATA symbol name. This symbol becomes a constant that is set equal to the location number of the first byte of data within the directive. For example, MyNumbers DATA @100, 72, 73 This would store the values 72 and 73 starting with location 100 and will create a constant, called MyNumbers, which is set equal to 100. Your program can then use the MyNumbers constant as a reference to the start of the data within a READ or WRITE command.
DATA – BASIC Stamp Command Reference For example, DATA @100, 0 (20) This statement writes the value 0 in all the EEPROM locations from 100 to 119. A common use for DATA is to store strings; sequences of bytes representing text. PBASIC converts quoted text like "A" into the corresponding ASCII character code (65 in this case).
5: BASIC Stamp Command Reference – DATA To retrieve a word-sized value, you'll need to use the WORD modifier in the READ command and a word-sized variable. Finally, a DataItem may be defined using a simple expression with the binary operators shown in Table 4.5. For example, MinLvl CON 10 myLvl VAR Byte Level1 Level2 DATA DATA MinLvl + 10 MinLvl * 5 + 21 READ Level2, myLvl DEBUG DEC myLvl All NOTE: This example program can be used with all BS2 models by changing the $STAMP directive accordingly.
DATA – BASIC Stamp Command Reference Text4 DATA DATA DATA DATA DATA DATA CLS, "This program also demonstrates retrieving data " "out of order ", CR, "in relation to the way it is " "stored in EEPROM. Additionally,", CR, "control codes " "(like carriage-returns, clear-screens, etc) can ", CR "be embedded right in the data, as it is here.
5: BASIC Stamp Command Reference – DEBUG DEBUG 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px DEBUG OutputData { , OutputData } Function 1 NOTE: Expressions are not allowed as arguments on the BS1. The only constant allowed for the BS1 DEBUG command is a text string. Display information on the PC screen within the BASIC Stamp Editor’s Debug Terminal.
DEBUG – BASIC Stamp Command Reference the BASIC Stamp. A moment later, the phrase "Hello World!" will appear. Note that if you close the Debug Terminal, your program keeps executing, but you can’t see the DEBUG data anymore. Multiple pieces of data can be sent with one DEBUG command by separating the data with commas (,). The following example produces exactly the same results as the example above. DEBUG "Hello ", "World!" DEBUG can also print and format numbers (values) from both constants and variables.
5: BASIC Stamp Command Reference – DEBUG After running the above code, "x = $4B" and "x = %01001011" should appear on the screen. To display hexadecimal or binary values without the "symbol = " preface, use the value formatter (#) before the $ and %, as shown below: SYMBOL x = B2 x = 75 DEBUG #x, "as HEX is ", #$x DEBUG #x, "as BINARY is ", #%x DISPLAYING ASCII CHARACTERS (BS1).
DEBUG – BASIC Stamp Command Reference BASIC Stamp 2, 2e, 2sx, 2p, 2pe, and 2px Formatting On the all BASIC Stamp models except the BS1, the DEBUG command, by default, displays everything as ASCII characters. What if you want to display a number? You might think the following example would do this: x VAR x = 65 DEBUG DEC x DISPLAYING ASCII CHARACTERS. ' Try to show decimal value of x Since we set x equal to 65 (in line 2), you might expect the DEBUG line to display “65” on the screen.
5: BASIC Stamp Command Reference – DEBUG Table 5.11: DEBUG Special Formatters for all BS2 models. Special Formatter ? ASC ? STR ByteArray {\L} REP Byte \L Table 5.12: DEBUG Conversion Formatters for all BS2 models. Conversion Formatter DEC{1..5} SDEC{1..5} HEX{1..4} SHEX{1..4} IHEX{1..4} Action 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").
DEBUG – BASIC Stamp Command Reference hexadecimal, you might think it was 41, in decimal… a totally different number. To help avoid this, use the IHEX formatter (the "I" stands for indicated). Changing the DEBUG line to read: DEBUG IHEX x would print "$41" on the screen. A similar formatter for binary also exists, IBIN, which prints a "%" before the number. Signed numbers are preceded with a space ( ) or a minus sign (-) to indicate a positive or negative number, respectively.
5: BASIC Stamp Command Reference – DEBUG but typing the name of the variables in quotes (for the display) can get a little tedious. A special formatter, the question mark (?), can save you a lot of time.
DEBUG – BASIC Stamp Command Reference displays "00165". Notice that leading zeros? The display is "fixed" to 5 digits, no more and no less. Any unused digits will be filled with zeros. 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. In this case, it would truncate the "1" and only display "65".
5: BASIC Stamp Command Reference – DEBUG doesn't end with 0, the BASIC Stamp will read and output all RAM register contents until it finds a 0 or until it cycles through all RAM locations. FIXED-WIDTH STRINGS. To specify a fixed-width format for the STR formatter, use the form STR 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" on the screen. REPEATING CHARACTERS.
DEBUG – BASIC Stamp Command Reference The upper-left cursor position is 0,0 (that is column 0, row 0). The rightmost cursor positions depend on the size of the Debug Terminal window (which is user adjustable). If a character position that is out of range is received, the Debug Terminal wraps back around to the opposite side of the screen. The Move To Column (x) and Move To Row (y) control characters work similarly to Move To (x,y) except they only expect a singe position value to follow.
5: BASIC Stamp Command Reference – DEBUG TECHNICAL BACKGROUND All 2 On all the BS2 models, DEBUG is actually a special case of the SEROUT instruction. It is set for inverted (RS-232-compatible) serial output through the programming connector (the SOUT pin) at 9600 baud, no parity, 8 data bits, and 1 stop bit. For example, DEBUG "Hello" is exactly like: ' {$STAMP BS2} SEROUT 16, $4054, ["Hello"] in terms of function on a BS2.
DEBUG – BASIC Stamp Command Reference Page 170 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – DEBUGIN DEBUGIN All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px DEBUGIN InputData { , InputData } NOTE: DEBUGIN requires the $PBASIC 2.5 compiler directive. Function Accept information from the user via the Debug Terminal within the BASIC Stamp Editor program. • InputData is list of variables and formatters that tells DEBUGIN what to do with incoming data.
DEBUGIN – BASIC Stamp Command Reference is exactly like: ' {$STAMP BS2} SERIN 16, $4054, [DEC1 myNum] in terms of function on a BS2. The DEBUGIN line actually takes less program space, and is obviously easier to type. Example: ' {$PBASIC 2.
5: BASIC Stamp Command Reference – DEBUGIN Table 5.17: DEBUGIN Conversion Formatters. Conversion Formatter Type of Number DEC{1..5} SDEC{1..5} Decimal, optionally limited to 1 – 5 digits Signed decimal, optionally limited to 1 – 5 digits Hexadecimal, optionally limited to 1 – 4 digits HEX{1..4} SHEX{1..4} IHEX{1..4} ISHEX{1..4} BIN{1..16} SBIN{1..16} IBIN{1..16} ISBIN{1..
DEBUGIN – BASIC Stamp Command Reference Demo Program (DEBUGIN.bs2) All ' DEBUGIN.bs2 ' This program demonstrates the ability to accept user input from the ' Debug Terminal, and to accept numeric entry in any valid format. ' {$STAMP BS2} ' {$PBASIC 2.
5: BASIC Stamp Command Reference – DO...LOOP DO…LOOP All NOTE: DO...LOOP requires the PBASIC 2.5 compiler directive. 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px DO { WHILE | UNTIL Condition(s) } Statement(s) LOOP { WHILE | UNTIL Condition(s) } Function Create a repeating loop that executes the Statement(s), one or more program lines that form a code block, between DO and LOOP, optionally testing Condition(s) before or after the Statement(s).
DO...LOOP – BASIC Stamp Command Reference For example: ' {$PBASIC 2.5} AckPin Pressed PIN CON 0 1 DO DEBUG "Error...", CR IF (AckPin = Pressed) THEN EXIT PAUSE 2000 LOOP GOTO Initialize ' wait for user button press ' re-initialize system In this case the DO...LOOP will continue until the pin called AckPin is equal to Pressed (1), and then the loop will terminate and continue at the line GOTO Initialize.
5: BASIC Stamp Command Reference – DO...LOOP Note that the WHILE test (loop runs WHILE Condition is True) and UNTIL test (loop runs UNTIL Condition is True) can be interchanged, but they are generally used as illustrated above. All 2 NOTE: This example program can be used with all BS2 models by changing the $STAMP directive accordingly. Demo Program (DO-LOOP.bs2) ' ' ' ' ' ' DO-LOOP.bs2 This program creates a little guessing game. It starts by creating a (pseudo) random number between 1 and 10.
DO...LOOP – BASIC Stamp Command Reference Page 178 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – DTMFOUT DTMFOUT All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px 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. This pin will be set to output mode during generation of tones and set to input mode afterwards.
DTMFOUT – BASIC Stamp Command Reference The following DTMFOUT instruction will generate DTMF tones on I/O pin 10: DTMFOUT 10, [6, 2, 4, 8, 3, 3, 3] ' Call Parallax If the BASIC Stamp is connected to the phone line properly, the above command would be equivalent to dialing 624-8333 from a phone keypad.
5: BASIC Stamp Command Reference – DTMFOUT The BASIC Stamp microcontroller is a purely digital device. DTMF tones are 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.
DTMFOUT – BASIC Stamp Command Reference ' {$STAMP BS2} ' {$PBASIC 2.5} Spkr PIN 10 #SELECT $STAMP #CASE BS2, BS2E, BS2PE TmAdj CON $100 #CASE BS2SX TmAdj CON $280 #CASE BS2P TmAdj CON $3C5 #CASE BS2PX TmAdj CON $607 #ENDSELECT ' DTMF output on pin 10 ' x 1.0 (time adjust) ' x 2.5 ' x 3.77 ' x 6.03 eeLoc eeByte dtDig phone hiLo VAR VAR VAR VAR VAR Byte Byte eeByte.
5: BASIC Stamp Command Reference – EEPROM EEPROM 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px 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. If no location is given, data is written starting at the next available location. • DataItem is a constant (0 – 255) to be stored in EEPROM.
EEPROM – BASIC Stamp Command Reference The EEPROM directive uses a counter, called a pointer, to keep track of available EEPROM addresses. The value of the pointer is initially 0. When a program is downloaded, the EEPROM directive stores the first byte value at the current pointer address, then increments (adds 1 to) the pointer. If the program contains more than one EEPROM directive, subsequent EEPROM directives start with the pointer value left by the previous EEPROM directive.
5: BASIC Stamp Command Reference – EEPROM EEPROM directive, and PBASIC will understand it to mean a series of bytes (see the last line of code below). The following three EEPROM directives are equivalent: EEPROM EEPROM EEPROM (72, 69, 76, 76, 79) ("H", "E", "L", "L", "O") ("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.
EEPROM – BASIC Stamp Command Reference READ commands will read the low-byte and high-byte out of EEPROM (reconstructing it in a word-sized variable) and then display the value on the screen. See the READ and WRITE commands for more information. Demo Program (EEPROM.bs1) ' ' ' ' ' ' 1 EEPROM.bs1 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.
5: BASIC Stamp Command Reference – END END 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px END 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. The END command is optional. Quick Facts Table 5.23: END Quick Facts.
END – BASIC Stamp Command Reference Page 188 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – EXIT EXIT All 2 NOTE: EXIT requires the PBASIC 2.5 compiler directive. BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px EXIT Function Causes the immediate termination of a loop construct (DO...LOOP, FOR...NEXT). Quick Facts Table 5.24: EXIT Quick Facts. All BS2 Models 16 DO...LOOP and FOR...NEXT Maximum EXITs per Loop Related Commands Explanation The EXIT instruction allows a program to terminate a loop structure before the loop limit test is executed.
EXIT – BASIC Stamp Command Reference row VAR Nib Setup: col = 0 Main: DO WHILE (col < 10) FOR row = 0 TO 15 IF (row > 9) THEN EXIT DEBUG CRSRXY, (col * 8), row, DEC col, "/", DEC row, CR NEXT col = col + 1 IF (col = 3) THEN EXIT LOOP END ' ' ' ' attempt 10 iterations attempt 16 iterations terminate when row > 9 print col/row at location ' update column ' terminate when col = 3 Page 190 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – FOR...NEXT FOR…NEXT 1 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px FOR Counter = StartValue TO EndValue { STEP {-} StepValue } Statement(s) NEXT { Counter } All 2 FOR Counter = StartValue TO EndValue { STEP StepValue } Statement(s) NEXT { Counter } Function 1 NOTE: Expressions are not allowed as arguments on the BS1. 1 NOTE: Use a minus sign to indicate negative StepValues on the BS1.
FOR…NEXT – BASIC Stamp Command Reference Quick Facts BS1 All BS2 Models 8 16 Set StartValue > EndValue and Set StartValue > EndValue enter negative StepValue* Exit loop if Counter exceeds Exit loop if Counter outside range Counter Comparison EndValue set by StartValue to EndValue None DO...LOOP and EXIT Related Commands *NOTE: For the BS1, direction (increment or decrement) cannot be changed at run-time. Max. Nested Loops To Decrement Counter Variable Table 5.25: FOR...NEXT Quick Facts. Explanation FOR...
5: BASIC Stamp Command Reference – FOR...NEXT NOTE: Change the first line as noted 1 above and replace line 3 with DEBUG #Reps, CR reps VAR Nib FOR reps = 1 TO 3 DEBUG DEC reps, CR NEXT ' counter for the FOR/NEXT loop ' repeat with reps = 1, 2, 3 ' print rep number Running this example should display "1" , "2", and "3" on the screen. FOR…NEXT can also be made to decrement (rather than increment) the Counter variable.
FOR…NEXT – BASIC Stamp Command Reference All the arguments in the FOR…NEXT command can be constants, variables or expressions on all BS2 models. This leads to some interesting uses. For example, if you make the StartValue and EndValue a variable, and change their values within the loop, you'll change the behavior of the loop itself. Try the following: {' $PBASIC 2.5} reps startVal endVal USING VARIABLES AS ARGUMENTS.
5: BASIC Stamp Command Reference – FOR...NEXT number). If you add 1 to 65535, you get 0 as the 16-bit register rolls over (like a car’s odometer does when you exceed the maximum mileage it can display). Similarly, if you subtract 1 from 0, you'll get 65535 as the 16-bit register rolls under (a rollover in the opposite direction). If you write a FOR...NEXT loop who's StepValue would cause Counter to go past 65535, this rollover may cause the loop to execute more times than you expect.
FOR…NEXT – BASIC Stamp Command Reference reps becomes 0 (bytes will rollover after 255 just like words will rollover after 65535). The result, 0, is compared against the range (0 – 255) and it is found to be within the range, so the FOR…NEXT loop continues. It's important to realize that on all the BS2 models, the test is against the entire range, not just the EndValue. The code below is a slight modification of the previous example (the StartValue is 10 instead of 0) and will not loop endlessly.
5: BASIC Stamp Command Reference – FOR...NEXT All 2 NOTE: This example program can be used with all BS2 models by changing the $STAMP directive accordingly. Demo Program (FOR-NEXT.bs2) ' ' ' ' ' ' FOR-NEXT.bs2 This example uses a FOR...NEXT loop to churn out a series of sequential squares (numbers 1, 2, 3, 4... raised to the second power) by using a variable to set the FOR...NEXT StepValue, and incrementing StepValue within the loop.
FOR…NEXT – BASIC Stamp Command Reference Page 198 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – FREQOUT FREQOUT 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px (See SOUND) FREQOUT Pin, Duration, Freq1 { , Freq2 } Function Generate one or two sine-wave tones for a specified Duration. • Pin is a variable/constant/expression (0 – 15) that specifies the I/O pin to use. This pin will be set to output mode. • Duration is a variable/constant/expression (0 - 65535) specifying the amount of time to generate the tone(s). The unit of time for Duration is described in Table 5.
FREQOUT – BASIC Stamp Command Reference On the BS2, this command generates a 2500 Hz tone for 1 second (1000 ms) on I/O pin 2. See Table 5.26 for timing data on other BASIC Stamp models. To play two tones on the same I/O pin at once: FREQOUT 2, 1000, 2500, 3000 GENERATING TWO TONES AT ONCE. This will generate a 2500 Hz and 3000 Hz tone 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.
5: BASIC Stamp Command Reference – FREQOUT All 2 NOTE: This example program can be used with all BS2 models. This program uses conditional compilation techniques; see Chapter 3 for more information. Demo Program (FREQOUT.bs2) ' ' ' ' FREQOUT.bs2 This program demonstrates sound-effects generation by the BASIC Stamp. Conditional compilation sets timing and frequency adjustment factors so that the output will sound the same on any BS2 model. ' {$STAMP BS2} ' {$PBASIC 2.
FREQOUT – BASIC Stamp Command Reference Page 202 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – GET GET BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px GET Location, { WORD } Variable { , { WORD } Variable... } NOTE: The optional arguments require PBASIC 2.5. Function Read the value from Scratch Pad RAM (SPRAM) Location and store in Variable. • Location is a variable/constant/expression (0 – 63 for BS2e and BS2sx and 0 – 131 for BS2p, BS2pe, and BS2px) that specifies the SPRAM location to read from.
GET – BASIC Stamp Command Reference temp VAR Byte GET 25, temp DEBUG DEC temp ' retrieve byte from location 25 When using the PBASIC 2.5 directive, multiple sequential variables may be read from the Scratch Pad RAM, starting at Location, and the WORD modifier may be specified to retrieve 16-bit values. ' {$PBASIC 2.
5: BASIC Stamp Command Reference – GET Table 5.28: Layout of SPRAM Registers. Location 0...62 64..126 BS2e and BS2sx General Purpose RAM Bits 0-3: Active program slot number. n/a 127 n/a 128 n/a 129 n/a 130 n/a 131 n/a 132 n/a 133 n/a 134 n/a 135 n/a 63 NOTE: Scratch Pad RAM can only be accessed with the GET and PUT commands. Scratch Pad RAM cannot have variable names assigned to it.
GET – BASIC Stamp Command Reference #SELECT $STAMP #CASE BS2 #ERROR "BS2e or greater required." #CASE BS2E, BS2SX Slot CON 63 #CASE BS2P, BS2PE, BS2PX Slot CON 127 #ENDSELECT value idx VAR VAR Byte Byte Setup: GET Slot, value DEBUG "Program Slot #", DEC value.NIB0, CR Main: FOR idx = 0 TO 9 value = (idx + 3) * 8 PUT idx, value DEBUG " Writing: ", DEC2 value, " to location: ", DEC2 idx, CR NEXT DEBUG CR RUN 1 END Demo Program (GET_PUT2.bsx) ' ' ' ' ' ' ' GET_PUT2.
5: BASIC Stamp Command Reference – GET Setup: GET Slot, value DEBUG "Program Slot #", DEC value.NIB0, CR Main: FOR idx = 0 TO 9 GET idx, value DEBUG " Reading: ", DEC2 value, " from location: ", DEC2 idx, CR NEXT END BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
GET – BASIC Stamp Command Reference Page 208 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – GOSUB GOSUB 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px 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. • Address is a label that specifies where to go. Quick Facts Table 5.29: GOSUB Quick Facts. Max. GOSUBs per program Max. nested GOSUBs Related Commands BS1 All BS2 Models 16 255 4 4 GOTO ON...
GOSUB – BASIC Stamp Command Reference RETURN command, then just use a GOSUB command at each of the 10 locations to access it. This technique can save a lot of program space. Try the example below: Main: GOSUB Hello DEBUG "How are you?" END 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… which prints "How are you?" and ENDs.
5: BASIC Stamp Command Reference – GOSUB BASIC Stamp encounters a RETURN without a previous GOSUB, the entire program starts over from the beginning. Take care to avoid these phenomena. 1 Demo Program (GOSUB.bs1) ' ' ' ' ' ' ' ' ' ' GOSUB.bs1 This program is a guessing game that generates a random number in a subroutine called Pick_A_Number. It is written to stop after ten guesses. To see a common bug associated with GOSUB, delete or comment out the line beginning with END after the FOR-NEXT loop.
GOSUB – BASIC Stamp Command Reference Demo Program (GOSUB.bs2) ' ' ' ' ' ' ' ' ' ' All GOSUB.bs2 This program is a guessing game that generates a random number in a subroutine called Pick_A_Number. It is written to stop after ten guesses. To see a common bug associated with GOSUB, delete or comment out the line beginning with END after the FOR-NEXT loop. This means that after the loop is finished, the program will wander into the Pick_A_Number subroutine.
5: BASIC Stamp Command Reference – GOTO GOTO 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px 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.30: GOTO Quick Facts. Related Commands Max. GOTOs per Program BS1 All BS2 Models BRANCH and GOSUB ON...GOTO, BRANCH and GOSUB Unlimited, but good programming practices suggest using the least amount possible.
GOTO – BASIC Stamp Command Reference '{$STAMP BS2} GOTO Routine1 Routine2: DEBUG "We're in routine #2",CR PAUSE 1000 GOTO Routine3 Routine1: DEBUG "We're in routine #1",CR PAUSE 1000 GOTO Routine2 Routine3: DEBUG "We're in routine #3",CR PAUSE 1000 GOTO Routine1 Page 214 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – HIGH HIGH 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px BS2px HIGH Pin Function 1 NOTE: Expressions are not allowed as arguments on the BS1. The range of the Pin argument on the BS1 is 0 – 7. Make the specified pin output high. • Pin is a variable/constant/expression (0 – 15) that specifies which I/O pin to set high. This pin will be placed into output mode. Quick Facts Table 5.31: HIGH Quick Facts.
HIGH – BASIC Stamp Command Reference Demo Program (HIGH.bs2) ' ' ' ' HIGH.bs2 This simple program sets I/O pin 0 high for 1/2 second and low for 1/2 second in an endless loop. Connect an LED to P0 for a simple blinker. ' {$STAMP BS2} Main: HIGH 0 PAUSE 500 LOW 0 PAUSE 500 GOTO Main END Page 216 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – I2CIN I2CIN BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px I2CIN Pin, SlaveID, { Address { \LowAddress }, } [ InputData ] Function Receive data from a device using the I2C protocol. • Pin is a variable/constant/expression (0 or 8) that specifies which I/O pins to use. I2C devices require two I/O pins to communicate.
I2CIN – BASIC Stamp Command Reference Quick Facts Values for Pin I/O Pin Arrangement Transmission Rate Special Notes BS2p, BS2pe, and BS2px Pin = 0 Pin = 8 0: Serial Data (SDA) pin 8: Serial Data (SDA) pin 1: Serial Clock (SCL) pin 9: Serial Clock (SCL) pin Approximately 81 kbits/sec on a BS2p, 45 kbits/sec on a BS2pe, and 83 kbits/sec on a BS2px (not including overhead). Both the SDA and SCL pins must have 1 kΩ - 4.7 kΩ pull-up resistors. The I2CIN command does not allow for multiple masters.
5: BASIC Stamp Command Reference – I2CIN Figure 5.8: Example Circuit for the I2CIN command and a 24LC16B EEPROM. P0 SDA P1 SCL Vdd Note: The 4.7 kΩ resistors are required for the I2CIN command to function properly. 4.7 kΩ 1 2 3 4 Vss RECEIVING FORMATTED DATA. 8 7 6 5 4.7 kΩ 24LC16B (DIP) The I2CIN command's InputData argument is similar to the SERIN command's InputData argument.
I2CIN – BASIC Stamp Command Reference Conversion Formatter Type of Number DEC{1..5} SDEC{1..5} Decimal, optionally limited to 1 – 5 digits Signed decimal, optionally limited to 1 – 5 digits Hexadecimal, optionally limited to 1 – 4 digits HEX{1..4} SHEX{1..4} IHEX{1..4} ISHEX{1..4} BIN{1..16} SBIN{1..16} IBIN{1..16} ISBIN{1..
5: BASIC Stamp Command Reference – I2CIN 2 THE I C PROTOCOL FORMAT. Figure 5.9: Slave ID Format. The I2C protocol has a well-defined standard for the information passed at the start of each transmission. First of all, any information sent must be transmitted in units of 1 byte (8-bits). The first byte, we call the SlaveID, is an 8-bit pattern whose upper 7-bits contain the unique ID of the device you wish to communicate with.
I2CIN – BASIC Stamp Command Reference S T A R T B U S SlaveID S a6 a5 a4 a3 a2 a1 a0 rw A C K Data S F A T R C O E K P E d7 d6 d5 d4 d3 d2 d1 d0 P A C K Address a7 a6 a5 a4 a3 a2 a1 a0 2 Figure 5.10: I C Transmission Format. NOTES: S = Start Condition P = Stop Condition a = id or address bit 2 d = data bit (transmitted by the BASIC Stamp or the I C device) ACK = Acknowledge signal.
5: BASIC Stamp Command Reference – I2CIN addr block value check result VAR VAR VAR VAR VAR Word Nib Byte Nib Byte(16) ' ' ' ' ' internal address block address in 24LC16 value to write for checking retuned values array for returned value Write_To_EEPROM: DEBUG "Writing...", CR PAUSE 2000 FOR addr = 0 TO 2047 STEP 16 ' loop through all addresses block = addr.NIB2 << 1 ' calculate block address value = addr >> 4 ' create value from upper 8 bits ' write 16 bytes I2COUT SDA, $A0 | block, addr, [REP value\16
I2CIN – BASIC Stamp Command Reference Page 224 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – I2COUT I2COUT BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px I2COUT Pin, SlaveID, { Address { \LowAddress }, } [ OutputData ] Function Send data to a device using the I2C protocol. • Pin is a variable/constant/expression (0 or 8) that specifies which I/O pins to use. I2C devices require two I/O pins to communicate.
I2COUT – BASIC Stamp Command Reference Quick Facts BS2p, BS2pe, and BS2px Pin = 0 Pin = 8 0: Serial Data (SDA) pin 8: Serial Data (SDA) pin I/O Pin Arrangement 1: Serial Clock (SCL) pin 9: Serial Clock (SCL) pin Approximately 81 kbits/sec on a BS2p, 45 kbits/sec on a BS2pe, Transmission and 83 kbits/sec on a BS2px (not including overhead). Rate The SDA and SCL pins must have 1 kΩ - 4.7 kΩ pull-up resistors. Special Notes The I2CIN command does not allow for multiple masters.
5: BASIC Stamp Command Reference – I2COUT SENDING AND FORMATTING DATA. The I2COUT command's OutputData argument is similar to the DEBUG and SEROUT command's OutputData argument. This means data can be sent as literal text, ASCII character values, repetitive values, decimal, hexadecimal and binary translations and string data as in the examples below. (Assume the 24LC16B EEPROM is being used).
I2COUT – BASIC Stamp Command Reference Special Formatter ? ASC ? STR ByteArray {\L} REP Byte \L Action 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"). Displays "symbol = 'x'" + carriage return; where x is an ASCII character. Send character string from an array. The optional \L argument can be used to limit the output to L characters, otherwise, characters will be sent up
5: BASIC Stamp Command Reference – I2COUT depending on the I2C device. Note that every device has different limitations regarding how may contiguous bytes they can receive or transmit in one session. Be aware of this, and program accordingly. START AND STOP CONDITIONS AND ACKNOWLEDGMENTS. Every I2C transmission session begins with a Start Condition and ends with a Stop Condition.
I2COUT – BASIC Stamp Command Reference ' I2COUT command description. ' {$STAMP BS2p} ' {$PBASIC 2.5} #IF ($STAMP < BS2P) #THEN #ERROR "Program requires BS2p, BS2pe or BS2px." #ENDIF SDA SCL PIN PIN 0 SDA + 1 ' I2C SDA pin addr block value check result VAR VAR VAR VAR VAR Word Nib Byte Nib Byte(16) ' ' ' ' ' internal address block address in 24LC16 value to write for checking retuned values array for returned value Write_To_EEPROM: DEBUG "Writing...
5: BASIC Stamp Command Reference – IF...THEN IF…THEN NOTE: PBASIC 1.0 and 1 All 2 PBASIC 2.0 only support IF Condition(s) THEN Address. PBASIC 2.5 supports all syntax All 2 variations.
IF…THEN – BASIC Stamp Command Reference Quick Facts Comparison Operators Conditional Logic Operators BS1 All BS2 Models =, <>, >, <, >=, <= =, <>, >, <, >=, <= AND, OR NOT, AND, OR, XOR Not Allowed Value1 Comparison Value2; where Value1 and Value2 can by any of variable, constant or expression Allowed n/a 16 n/a 16 n/a None 1 SELECT…CASE Variable Comparison Value; where Value is a variable or constant Format of Condition Parentheses Max nested IF…THENs Max ELSEIFs per IF Max ELSEs per IF Rel
5: BASIC Stamp Command Reference – IF...THEN GOTO) to the label called Main. This is the simplest form of IF…THEN and is the only form supported by PBASIC 1.0 and PBASIC 2.0. The Condition(s) argument is very powerful and flexible. In the next few pages we’ll demonstrate this flexibility in great detail and afterwards we’ll discuss the additional, optional arguments allowed by PBASIC 2.5. ALL ABOUT CONDITION(S). Here's a complete example of IF...
IF…THEN – BASIC Stamp Command Reference Test: IF -99 < 100 THEN Is_Less DEBUG "Greater than or equal to 100" END Is_Less: DEBUG "Less than 100" END 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. This phenomena will occur whether or not the negative value is a constant, variable or expression. IF...
5: BASIC Stamp Command Reference – IF...THEN The condition “value1 = 5 AND value2 = 10” is not true. Although value1 is 5, value2 is not 10. The AND operator works just as it does in English; both conditions must be true for the statement to be true. The OR operator also works in a familiar way; if one or the other or both conditions are true, then the statement is true.
IF…THEN – BASIC Stamp Command Reference Internally, the BASIC Stamp defines “false” as 0 and “true” as any value other than 0. Consider the following instructions: flag VAR Bit INTERNAL REPRESENTATION OF BOOLEAN VALUES (TRUE VS. FALSE). All 2 Setup: flag = 1 Test: IF flag THEN Is_True DEBUG "False" END Is_True: DEBUG "True" END Since flag is 1, IF...THEN would evaluate it as true and print the message “True” on the screen. Suppose you changed the IF...THEN command to read “IF NOT flag THEN Is_True.
5: BASIC Stamp Command Reference – IF...THEN IF…THEN WITH A SINGLE STATEMENT In addition to supporting everything discussed above, PBASIC 2.5 provides enhancements to the IF…THEN command that allow for more powerful, structured programming. In prior examples we’ve only used the first syntax form of this command: IF Condition(s) THEN Address. That form, while handy in some situations, can be quite limiting in others. For example, it is common to need to perform a single instruction based on a condition.
IF…THEN – BASIC Stamp Command Reference The IF…THEN in the previous example is called a “single-line” syntax. It is most useful where you only have one instruction to run as the result of a Condition. Sometimes this form may be a little hard to read, like in our above example. For these cases, it would be better to use the “multi-line” syntax of IF…THEN.
5: BASIC Stamp Command Reference – IF...THEN Here, the BASIC Stamp will look for and measure a pulse on I/O pin 0, then compare the result, value, against 4000. Based on this comparison, a message regarding the pulse width value will be printed. If value is greater than 4000, “Value was greater than 4000” is printed to the screen. Look what happens if value is not greater than 4000… the code in the ELSE block is run, which is another IF…THEN…ELSE statement.
IF…THEN – BASIC Stamp Command Reference Note that an IF…THEN construct can have as many as sixteen (16) ELSEIF clauses, but a maximum of only one (1) ELSE clause. There are three demo programs below. The first two demonstrate the PBASIC 1.0 (BS1) and PBASIC 2.0 (all BS2 models) form of the IF…THEN command. The last example demonstrates the PBASIC 2.5 (all BS2 models) form of IF…THEN. Demo Program (IF-THEN.bs1) ' ' ' ' ' ' 1 IF-THEN.
5: BASIC Stamp Command Reference – IF...THEN ' {$STAMP BS2} ' {$PBASIC 2.
IF…THEN – BASIC Stamp Command Reference hits = hits + 1 ELSE misses = misses + 1 ENDIF LOOP UNTIL (hits = 10) DEBUG CR, "All done.", "Hits: ", "Misses: ", "Samples: ", END CR, DEC DEC DEC ' count hits (divisible by 3) ' count misses ' quit after 10 hits CR, ' display results hits, CR, misses, CR, (hits + misses) Page 242 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – INPUT INPUT 1 All 2 1 NOTE: Expressions are not allowed as arguments on the BS1. The range of the PIN argument on the BS1 is 0 – 7. BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px INPUT Pin Function Make the specified pin an input. • Pin is a variable/constant/expression (0 – 15) that specifies which I/O pin to set to input mode. Quick Facts Table 5.41: INPUT Quick Facts.
INPUT – BASIC Stamp Command Reference on the BS1) will appear on the pin. The demo program shows how this works. Demo Program (INPUT.bs1) ' ' ' ' ' ' ' ' ' ' 1 INPUT.bs1 This program demonstrates how the input/output direction of a pin is determined by the corresponding bit of DIRS. It also shows that the state of the pin itself (as reflected by the corresponding bit of PINS) is determined by the outside world when the pin is an input, and by the corresponding bit of OUTS when it's an output.
5: BASIC Stamp Command Reference – INPUT BIN1 IN7, CR OUT7 = 0 DEBUG "After 0 written to OUT7: ", BIN1 IN7, CR ' Write 0 to output latch OUTPUT 7 ' Make P7 an output DEBUG "After P7 changed to output: ", BIN1 IN7 BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
INPUT – BASIC Stamp Command Reference Page 246 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – IOTERM IOTERM BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px 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. Quick Facts Table 5.42: IOTERM Quick Facts. Values for Port I/O pin IDs Special Notes Related Commands BS2p, BS2pe, and BS2px 0 = switch to main I/O group, 1 = switch to auxiliary I/O group.
IOTERM – BASIC Stamp Command Reference Stamp that all commands following it should affect the auxiliary I/O pins (Port = 1). The following LOW command will set I/O pin 0 of the auxiliary I/O pins (physical pin 21) low. Note that the main I/O and auxiliary I/O pins are independent of each other; the states of the main I/O pins remain unchanged while the program affects the auxiliary I/O pins, and vice versa. MAIN I/O AND AUXILIARY I/O PINS ARE INDEPENDENT AND UNAFFECTED BY CHANGES IN THE OPPOSITE GROUP.
5: BASIC Stamp Command Reference – LCDCMD LCDCMD BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px 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. Note that LCDCMD, LCDIN and LCDOUT use a 4-bit interface to the LCD which requires a specific initialization sequence before LCDIN and LCDOUT can be used. Specifics on the initialization sequence will follow.
LCDCMD – BASIC Stamp Command Reference instructions to the LCD. It is most commonly used to initialize the display upon a power-up or reset condition. The following is an example of the LCDCMD command: A SIMPLE LCDCMD EXAMPLE. LCDOUT 0, 24 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 0. This will cause the LCD display to scroll, or shift, the entire display one character to the left.
5: BASIC Stamp Command Reference – LCDCMD Note that we could have used 1 for the Pin argument and moved the LCD's Enable pin (pin 6) to I/O pin 1. Similarly, using 9 for the Pin argument would have required us to wire the LCD's pins to I/O pins 9 through 15, rather than I/O pins 0 and 2 through 7. INITIALIZING THE LCD; THE MOST IMPORTANT STEP! When the LCD is first powered-up, it defaults to an 8-bit interface and must be configured for a 4-bit buss before sending commands like the one shown above.
LCDCMD – BASIC Stamp Command Reference printed on the display (with the LCDOUT command) will appear at the current cursor's location. Here's another example: LCDCMD 0, 128 + 64 The above command will move the cursor to the first character position on the second line (on a 2 x 16 display). 128 is the Move To Display Address command and 64 is the location number. See the "Character Positioning" section, below, for more information.
5: BASIC Stamp Command Reference – LCDCMD location 0. Figure 5.15 indicates the position numbers for characters on the LCD screen. Table 5.45: All LCD Commands (for advanced users). These are supported by LCDs with the Hitachi 44780 controller.
LCDCMD – BASIC Stamp Command Reference On a standard 2 x 16 character display, the following command would move the cursor to the third column of the second line: LCDCMD 0, 128 + 66 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).
5: BASIC Stamp Command Reference – LCDCMD ground, the 4 resistors on LCD pins 7-10 may be removed (connecting pins 7-10 directly to ground). Note that even though this change will leave BASIC Stamp I/O pin 2 disconnected, it will still be set to output mode for each LCDCMD and LCDOUT command executed. Demo Program (LCDINIT.bsp) NOTE: This example program can be used with the BS2p, BS2pe, and BS2px by changing the $STAMP directive accordingly. ' ' ' ' ' LCDINIT.
LCDCMD – BASIC Stamp Command Reference PAUSE 3000 LCDCMD Lcd, LcdCls PAUSE 500 LOOP END Page 256 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – LCDIN LCDIN BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px 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. The Pin argument serves a double purpose; specifying the first pin and, indirectly, the group of other required pins. See explanation below.
LCDIN – BASIC Stamp Command Reference Explanation The three LCD commands (LCDCMD, LCDIN and LCDOUT) allow the BS2p, BS2pe, and BS2px to interface directly to standard LCD displays that feature a Hitachi 44780 controller (part #HD44780A). This includes many 1 x 16, 2 x 16 and 4 x 20 character LCD displays. NOTE: LCDCMD, LCDIN and LCDOUT use a 4-bit interface to the LCD which requires a specific initialization sequence before LCDIN and LCDOUT can be used; read more below.
5: BASIC Stamp Command Reference – LCDIN value LCDIN LCDIN LCDIN LCDIN LCDIN 0, 0, 0, 0, 0, VAR 128, 128, 128, 128, 128, Byte(13) [value] [DEC value] [HEX value] [BIN value] [STR value\13] 'receive 'receive 'receive 'receive 'receive the the the the the ASCII value for "V" number 3. number $3A. number %101. string "Value: 3A:101" Table 5.47 and Table 5.48 list all the special formatters and conversion formatters available to the LCDIN command.
LCDIN – BASIC Stamp Command Reference Conversion Formatter Type of Number DEC{1..5} SDEC{1..5} Decimal, optionally limited to 1 – 5 digits Signed decimal, optionally limited to 1 – 5 digits Hexadecimal, optionally limited to 1 – 4 digits HEX{1..4} SHEX{1..4} IHEX{1..4} ISHEX{1..4} BIN{1..16} SBIN{1..16} IBIN{1..16} ISBIN{1..
5: BASIC Stamp Command Reference – LCDIN Demo Program (LCDIN.bsp) NOTE: This example program can be used with the BS2p, BS2pe, and BS2px. This program uses conditional compilation techniques; see Chapter 3 for more information. ' LCDIN.bsp ' This program demonstrates initialization, printing and reading ' from a 2 x 16 character LCD display. ' {$STAMP BS2p} ' {$PBASIC 2.5} #IF ($STAMP < BS2P) #THEN #ERROR "Program requires BS2p, BS2pe or BS2px.
LCDIN – BASIC Stamp Command Reference Read_LCD_Screen: DEBUG "LCD now says: " LCDIN Lcd, LcdLine1, [STR char\16] DEBUG STR char\16, CR RETURN Page 262 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – LCDOUT LCDOUT BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px 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. The Pin argument serves a double purpose; specifying the first pin and, indirectly, the group of other required pins. See explanation below. All I/O pins will be set to output mode.
LCDOUT – BASIC Stamp Command Reference The LCDOUT command is used to send one instruction followed by at least one data byte to the LCD. The data that is output is written to the LCD's Character Generator RAM or Display Data RAM. The following is an example of the LCDOUT command: LCDOUT A SIMPLE LCDOUT EXAMPLE. 0, 1, ["Hello World!"] The above code will clear the LCD screen and then send "Hello World!" to the screen.
5: BASIC Stamp Command Reference – LCDOUT Table 5.50 and Table 5.51 list all the available conversion formatters and special formatters available to the LCDOUT command. See the DEBUG and SEROUT commands for additional information and examples of their use. Table 5.50: LCDOUT Conversion Formatters. Conversion Formatter DEC{1..5} SDEC{1..5} HEX{1..4} SHEX{1..4} IHEX{1..
LCDOUT – BASIC Stamp Command Reference LCDOUT 0, 13, ["Yo!"] Most of the time, you will want to send data without preceding it with a command. To do this, simply use 0 for the Command argument, as in: LCDOUT 0, 0, ["Hello there!"] Another use for the LCDOUT command is to access and create custom 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).
5: BASIC Stamp Command Reference – LCDOUT character 0's CGRAM data locations. Then it will place the cursor back on the display (DDRAM) and print the character on the screen. LCDOUT LCDOUT 0, 64+0, [00, 10, 00, 04, 17, 14, 00, 00] 0, 128+0, ["Custom Char: ", 0] The number 64 in the Command argument is the LCD's "Move to CGRAM Address" instruction and the 0 that is added to it is the location of the first row of data for the character 0.
LCDOUT – BASIC Stamp Command Reference LCDCMD Lcd, PAUSE 5 LCDCMD Lcd, PAUSE 0 LCDCMD Lcd, PAUSE 0 LCDCMD Lcd, LCDCMD Lcd, LCDCMD Lcd, LCDCMD Lcd, %00110000 ' send wakeup sequence to LCD ' pause required by LCD specs %00110000 ' pause required by LCD specs %00110000 %00100000 %00101000 %00001100 %00000110 ' ' ' ' ' pause required by LCD specs set data bus to 4-bit mode set to 2-line mode with 5x8 font display on without cursor auto-increment cursor LCDOUT Lcd, LcdCGRam, ' load custom character map [$0
5: BASIC Stamp Command Reference – LET LET 1 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px { LET } Variable = Value Function Sets Variable equal to the value of Value. • Value is a variable/constant/expression. (0-65535). • Variable is a variable which will be set equal to Value. Explanation LET is an optional instruction for the BASIC Stamp 1 that can be used with variable assignment statements, such as A = 5 and B = A + 2, etc. This instruction is not required and only exists on the BASIC Stamp 1.
LET – BASIC Stamp Command Reference dinner = salad + bread + soup DEBUG "Dinner = $",# lunch, "plus local tax.", CR Page 270 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – LOOKDOWN LOOKDOWN 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px LOOKDOWN Target, ( Value0, Value1, ...ValueN ), Variable LOOKDOWN Target, { ComparisonOp } [ Value0, Value1, ...ValueN ], Variable Function 1 NOTE: Expressions are not allowed as arguments on the BS1. All 2 Compare Target value to a list of values and store the index number of the first value that matches into Variable. If no value in the list matches, Variable is left unaffected.
LOOKDOWN – BASIC Stamp Command Reference SYMBOL SYMBOL value result value result = 17 = 15 = = B0 B1 1 LOOKDOWN value, (26, 177, 13, 1, 0, 17, 99), result DEBUG "Value matches item ", #result, "in list" -- or -value result value result VAR VAR = 17 = 15 Byte Nib All 2 LOOKDOWN value, [26, 177, 13, 1, 0, 17, 99], result DEBUG "Value matches item ", DEC result, " in list" DEBUG prints, “Value matches item 5 in list” because the value (17) matches item 5 of [26, 177, 13, 1, 0, 17, 99].
5: BASIC Stamp Command Reference – LOOKDOWN All 2 value result value result VAR VAR = = Byte Nib "f" 255 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”. LOOKDOWN CAN USE VARIABLES AND EXPRESSIONS IN THE VALUE LIST.
LOOKDOWN – BASIC Stamp Command Reference to the LOOKDOWN comparison operators. The bottom line is: Don’t used signed numbers with LOOKDOWN comparisons.
5: BASIC Stamp Command Reference – LOOKDOWN “_Medium” at which point DEBUG prints “Medium” on the PC screen then returns to the main loop. This is a powerful method for interpreting user input, and a lot neater than the alternative IF...THEN instructions. USING LOOKDOWN WITH LOOKUP TO "MAP" NON-CONTIGUOUS SETS OF NUMBERS. Table 5.54: NonContiguous Number Example. Another great use of LOOKDOWN is in combination with LOOKUP to "map" non-contiguous sets of numbers together.
LOOKDOWN – BASIC Stamp Command Reference ' ' ' ' LOOKDOWN.bs1 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. ' {$STAMP BS1} ' {$PBASIC 1.
5: BASIC Stamp Command Reference – LOOKUP LOOKUP 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px LOOKUP Index, ( Value0, Value1, ...ValueN ), Variable LOOKUP Index, [ Value0, Value1, ...ValueN ], Variable Function 1 NOTE: Expressions are not allowed as arguments on the BS1. 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.
LOOKUP – BASIC Stamp Command Reference index result VAR VAR Byte Byte All 2 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 number is 0. In the list above, item 0 is 26, item 1 is 177, etc. THE INDEX NUMBER OF THE FIRST ITEM IS 0, NOT 1. If index is beyond the end of the list, the result variable is unchanged.
5: BASIC Stamp Command Reference – LOOKUP USING LOOKUP WITH LOOKDOWN TO "MAP" NON-CONTIGUOUS SETS OF NUMBERS. A great use of LOOKUP is in combination with LOOKDOWN to "map" non-contiguous sets of numbers together. For example, you may have an application where certain numbers are received by the BASIC Stamp and, in response, the BASIC Stamp needs to send a specific set of numbers.
LOOKUP – BASIC Stamp Command Reference ' {$STAMP BS1} ' {$PBASIC 1.0} SYMBOL SYMBOL idx frame = B2 = B3 Spinner: LOOKUP idx, ("|/-\"), frame DEBUG CLS, "Spinner: ", #@frame idx = idx + 1 // 4 GOTO Spinner END ' ' ' ' lookup current frame character display update frame index (0..3) loop forever Demo Program (LOOKUP.bs2) ' ' ' ' ' All LOOKUP.bs2 This program uses LOOKUP to create a Debug-window animation of a spinning propeller. The animation consists of the four ASCII characters | / - \ which, when p
5: BASIC Stamp Command Reference – LOW LOW 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px LOW Pin Function 1 NOTE: Expressions are not allowed as arguments on the BS1. The range of the Pin argument on the BS1 is 0 – 7. Make the specified pin output low. • Pin is a variable/constant/expression (0 – 15) that specifies which I/O pin to set low. This pin will be placed into output mode. Quick Facts Table 5.57: LOW Quick Facts.
LOW – BASIC Stamp Command Reference Demo Program (LOW.bs2) ' ' ' ' LOW.bs2 This simple program sets I/O pin 0 high for 1/2 second and low for 1/2 second in an endless loop. Connect an LED to P0 for a simple blinker. ' {$STAMP BS2} Main: HIGH 0 PAUSE 500 LOW 0 PAUSE 500 GOTO Main END Page 282 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com 1 All 2 NOTE: This example program can be used with the BS1 and all BS2 models by changing the $STAMP directive accordingly.
5: BASIC Stamp Command Reference – MAINIO MAINIO BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px MAINIO Function Switch from control of auxiliary I/O pins to main I/O pins (on the BS2p40 only). Quick Facts Table 5.58: MAINIO Quick Facts. I/O pin IDs Special Notes BS2p, BS2pe, and BS2px 0 – 15 (just like auxiliary I/O, but after MAINIO command, all references affect physical pins 5 – 20). The 24-pin BS2p, BS2pe, and BS2px accept this command, however, only the BS2p40 gives access to the auxiliary I/O pins.
MAINIO – BASIC Stamp Command Reference Note that the main I/O and auxiliary I/O pins are independent of each other; the states of the main I/O pins remain unchanged while the program affects the auxiliary I/O pins, and vice versa. MAIN I/O AND AUXILIARY I/O PINS ARE INDEPENDENT AND UNAFFECTED BY CHANGES IN THE OPPOSITE GROUP. Other commands that affect I/O group access are AUXIO and IOTERM. 2 Demo Program (AUX_MAIN_TERM.bsp) p ' AUX_MAIN_TERM.
5: BASIC Stamp Command Reference – NAP NAP 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px NAP Duration Function 1 NOTE: Expressions are not allowed as arguments on the BS1. Enter sleep mode for a short time. Power consumption is reduced as indicated in Table 5.59 assuming no loads are being driven. • Duration is a variable/constant/expression (0 – 7) that specifies the duration of the reduced-power nap. The duration is (2^Duration) * 18 ms. Table 5.60 indicates the nap length for any given Duration.
NAP – BASIC Stamp Command Reference the actual timing to vary by as much as –50, +100 percent (i.e., a Duration 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. One great use for NAP is in a battery-powered application where at least a small amount of time is spent doing nothing.
5: BASIC Stamp Command Reference – NAP Figure 5.18: Example LED Circuit. 1 All 2 NOTE: This example program can be used with the BS1 and all BS2 models by changing the $STAMP directive accordingly. Demo Program (NAP.bs2) ' ' ' ' ' ' NAP.bs2 The program below lights an LED by placing a low on pin 0. This completes the circuit from +5V, through the LED and resistor, to ground. During the NAP interval, the LED stays lit, but blinks off for a fraction of a sec.
NAP – BASIC Stamp Command Reference Page 288 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – ON ON NOTE: ON requires PBASIC 2.5. All 2 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px ON Offset GOTO Address1, Address2, ...AddressN ON Offset GOSUB Address1, Address2, ...AddressN Function GOTO or GOSUB to the Address specified by Offset (if in range). ON is similar in operation to BRANCH with the exception that program execution can optionally return to the line following ON (if using ON…GOSUB).
ON – BASIC Stamp Command Reference You can use ON to organize each of these two examples into single statements: ON value GOTO Case_0, Case_1, Case_2 ' "GOTO" jump table - or ON value GOSUB Case_0, Case_1, Case_2 ' "GOSUB" jump table This works like the previous IF...THEN example. If the value isn’t in range (in this case if value is greater than 2), ON does nothing and the program continues with the next instruction after ON. See the GOTO and GOSUB command descriptions for more information.
5: BASIC Stamp Command Reference – ON All 2 NOTE: This example program can be used with all BS2 models by changing the $STAMP directive accordingly. Demo Program (ON-GOSUB.bs2) ' ' ' ' ' ' ' ON-GOSUB.bs2 This program demonstrates a simple task manager that can be used in a variety of applications. It is particularly useful in robotics and industrial applications.
ON – BASIC Stamp Command Reference Page 292 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – OUTPUT OUTPUT 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px OUTPUT Pin Function 1 NOTE: Expressions are not allowed as arguments on the BS1. The range of the Pin argument on the BS1 is 0 – 7. Make the specified pin an output. • Pin is a variable/constant/expression (0 – 15) that specifies which I/O pin to set to output mode. Quick Facts Table 5.62: OUTPUT Quick Facts.
OUTPUT – BASIC Stamp Command Reference ' to +5V puts a high (1) on the pin when it's an input. The BASIC Stamp ' can override this state by writing a low (0) to bit 7 of OUTS and ' changing the pin to output. ' {$STAMP BS1} ' {$PBASIC 1.0} Main: INPUT 7 DEBUG "State of P7: ", #PIN7, CR ' Make P7 an input PIN7 = 0 DEBUG "After 0 written to OUT7: " DEBUG #PIN7, CR ' Write 0 to output latch OUTPUT 7 DEBUG "After P7 changed to output: " DEBUG #PIN7 END ' Make P7 an output Demo Program (INPUT_OUTPUT.
5: BASIC Stamp Command Reference – OWIN OWIN BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px 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. This I/O pin will be toggled between output and input mode during the OWIN command and will be set to input mode by the end of the OWIN command.
OWIN – BASIC Stamp Command Reference This code will transmit a "reset" pulse to a 1-Wire device (connected to I/O pin 0) and then will detect the device's "presence" pulse and then receive one byte and store it in the variable result. 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.19 shows the meaning of each of the 4 bits of Mode. Table 5.
5: BASIC Stamp Command Reference – OWIN bitOne bitTwo VAR VAR Byte Byte OWIN 0, 6, [bitOne, bitTwo] 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 bitOne and bitTwo 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). RECEIVING FORMATTED DATA. The OWIN command’s InputData argument is similar to the SERIN command’s InputData argument.
OWIN – BASIC Stamp Command Reference \Conversion Formatter Type of Number DEC{1..5} SDEC{1..5} Decimal, optionally limited to 1 – 5 digits Signed decimal, optionally limited to 1 – 5 digits Hexadecimal, optionally limited to 1 – 4 digits HEX{1..4} SHEX{1..4} IHEX{1..4} ISHEX{1..4} BIN{1..16} SBIN{1..16} IBIN{1..16} ISBIN{1..
5: BASIC Stamp Command Reference – OWIN THE 1-WIRE PROTOCOL FORMAT. The 1-Wire protocol has a well-defined standard for transaction sequences. Every transaction sequence consists of four parts: 1) Initialization, 2) ROM Function Command, 3) Memory Function Command, and 4) 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.
OWIN – BASIC Stamp Command Reference Command Value (in Hex) Read ROM $33 Match ROM $55 Skip ROM $CC Search ROM $F0 Action Reads the 64-bit ID of the 1-Wire device. This command can only be used if there is a single 1-wire device on the line. This command, followed by a 64-bit ID, allows the BASIC Stamp to address a specific 1-Wire device. Address a 1-Wire device without its 64-bit ID. This command can only be used if there is a single 1-wire device on the line.
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 resistor is required for proper operation. Figure 5.22: DS1820 Circuit. NOTE: The 4.7 kΩ resistor is required for proper operation. Demo Program (OWIN_OWOUT.bsp) NOTE: This example program can be used with the BS2p, BS2pe and BS2px by changing the $STAMP directive accordingly. ' ' ' ' ' ' OWIN_OWOUT.
OWIN – BASIC Stamp Command Reference SDEC tempC, " C ", CR, SDEC tempF, " F " PAUSE 1000 LOOP END Get_Temperature: OWOUT DQ, 1, [SkipROM, CvrtTmp] DO PAUSE 25 OWIN DQ, 4, [tempIn] LOOP UNTIL (tempIn) OWOUT DQ, 1, [SkipROM, RdSP] OWIN DQ, 2, [tLo, tHi] tSign = sign tempC = tempIn >> 4 tempC.
5: BASIC Stamp Command Reference – OWOUT OWOUT BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px 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. This I/O pin will be toggled between output and input mode during the OWOUT command and will be set to input mode by the end of the OWOUT command.
OWOUT – BASIC Stamp Command Reference This code will transmit a "reset" pulse to a 1-Wire device (connected to I/O pin 0) and then will detect the device's "presence" pulse and then transmit one byte (the value $4E). 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.23 shows the meaning of each of the 4 bits of Mode. Table 5.69 shows just some of the 16 possible values and their effect.
5: BASIC Stamp Command Reference – OWOUT bitOne bitTwo VAR VAR Bit Bit bitOne = 0 bitTwo = 1 OWOUT 0, 5, [bitOne, bitTwo] In the code above, we chose the value "5" for Mode. This sets Bit transfer and Front-End Reset modes. Also, we could have chosen to make the bitOne and bitTwo 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). SENDING AND FORMATTING DATA.
OWOUT – BASIC Stamp Command Reference Conversion Formatter DEC{1..5} SDEC{1..5} HEX{1..4} SHEX{1..4} IHEX{1..4} Type of Number Notes Decimal, optionally fixed to 1 – 5 digits 1 Signed decimal, optionally fixed to 1 – 5 digits 1,2 Hexadecimal, optionally fixed to 1 – 4 digits 1,3 Signed hexadecimal, optionally fixed to 1 – 4 digits 1,2 Indicated hexadecimal, optionally fixed to 1 – 4 digits ($ prefix) 1 Signed, indicated hexadecimal, optionally fixed to 1 – 4 digits ISHEX{1..4} 1,2 ($ prefix) BIN{1..
5: BASIC Stamp Command Reference – OWOUT Resting State 15 - 60 µs Figure 5.24: OWOUT Reset and Presence Pulse. +5 (vdd) 0 (vss) BASIC Stamp’s Reset Pulse Apx. 564 µs Device’s Presence Pulse 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 in the OWOUT command.
OWOUT – BASIC Stamp Command Reference Refer to the 1-Wire device's data sheet for a list of the available Memory Function Commands. Finally, the Transaction/Data section is used to read or write data to the 1-Wire device. The OWOUT command will write data at this point in the transaction. A write is accomplished by generating a low-pulse of a varying width to indicate a 0 or a 1. This is called a "Write Slot" and must be at least 60 µs wide. Figure 5.
5: BASIC Stamp Command Reference – OWOUT Demo Program (OWIN_OWOUT.bsp) NOTE: This example program can be used with the BS2p, BS2pe, and BS2px by changing the $STAMP directive accordingly. ' ' ' ' ' ' OWIN_OWOUT.bsp This program demonstrates interfacing to a Dallas Semiconductor DS1822 1-Wire Digital Thermometer chip using the BS2p's 1-Wire commands. Connect the BS2p, BS2pe or BS2px to the DS1822 as shown in the diagram in the OWIN or OWOUT command description.
OWOUT – BASIC Stamp Command Reference tempF = (ABS tempC) * 9 / 5 IF (tSign) THEN tempF = 32 - tempF ELSE tempF = tempF + 32 ENDIF RETURN ' start F conversion ' finish F conversion ' C was negative ' C was positive Page 310 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – PAUSE PAUSE 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px PAUSE Duration Function 1 NOTE: Expressions are not allowed as arguments on the BS1. Pause the program (do nothing) for the specified Duration. • Duration is a variable/constant/expression (0 – 65535) that specifies the duration of the pause. The unit of time for Duration is 1 millisecond. Explanation PAUSE delays the execution of the next program instruction for the specified number of milliseconds.
PAUSE – BASIC Stamp Command Reference Page 312 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – POLLIN POLLIN BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px 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. • State is a variable/constant/expression (0 – 1) that specifies whether to poll the I/O pin for a low (0) or a high (1) level. Quick Facts Table 5.73: POLLIN Quick Facts.
POLLIN – BASIC Stamp Command Reference user program; giving the appearance that it is polling "in the background". 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: A SIMPLE POLLIN EXAMPLE. POLLIN 0, 0 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 low (0) state.
5: BASIC Stamp Command Reference – POLLIN pin 0 is set low, the BASIC Stamp will set I/O pin 1 high. It will continue to perform this operation, in-between each command in the loop, endlessly. DURATION OF THE PBASIC PROGRAM. It's important to note that, in this example, only the DEBUG and GOTO commands are being executed over and over again. The first three lines of code are only run once, yet their effects are "remembered" by the BASIC Stamp throughout the rest of the program.
POLLIN – BASIC Stamp Command Reference state). If either I/O pin 0 or 1 goes low, the BASIC Stamp will set I/O pins 2 and 3 high. 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. Polled-Inputs 0 1 0 0 0 1 1 0 1 1 Polled-Outputs 2 3 0 0 1 1 1 1 1 1 Normally, any polled-output pins reflect the state changes continuously, as described above.
5: BASIC Stamp Command Reference – POLLIN idx VAR Nib Setup: POLLIN FDoor, 0 POLLIN BDoor, 0 POLLIN Patio, 0 POLLOUT AlarmLed, 1 POLLMODE 10 DEBUG CLS, "Alarms Activated", CR Main: DO DEBUG "." PAUSE 50 LOOP UNTIL (AlarmLed = 1) GET 128, alarms POLLMODE 0 Report: DEBUG CLS, "Front Door : ", CR, "Back Door : ", CR, "Patio : ", CR FOR idx = 0 TO 2 DEBUG CRSRXY, 13, idx IF (alarms.LOWBIT(idx)) THEN DEBUG "Alarm", CR ELSE DEBUG "-", CR ENDIF NEXT DEBUG CR, "Press RESET to clear...
POLLIN – BASIC Stamp Command Reference Page 318 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – POLLMODE POLLMODE BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px 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.75: POLLMODE Quick Facts.
POLLMODE – BASIC Stamp Command Reference 1 2 3 Mode Effect 0 Deactivate polling, clear polled-input and output configuration. 1 Deactivate polling, save polled-input and output configuration. 2 Activate polling with polled-output action (and polled-wait) only. 1 3 Activate polling with polled-run action only. 2 4 Activate polling with polled-output/polled-wait and polled-run actions. 3 5 Clear polled-input configuration. 3 6 Clear polled-output configuration.
5: BASIC Stamp Command Reference – POLLMODE POLLIN 0, 0 POLLOUT 1, 1 POLLMODE 2 Main: DEBUG "Looping...", CR GOTO Main In this example, the first two lines configure I/O pin 0 as a polled-input (looking for a low state) and I/O pin 1 as a polled-output (going high if I/O pin 0 goes low, and vice versa). The third line, POLLMODE, initiates the polling process and configures polled-outputs to be active.
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. The first should be downloaded into program slot 0 and the second into program slot 1.
5: BASIC Stamp Command Reference – POLLMODE Table 5.77: Special Purpose Scratch Pad RAM Locations. Location 127 128 129 130 131 132 133 134 135 BS2p and BS2pe Bits 0-3, Active program slot #. Bits 4-7, program slot for READ and WRITE operations. Polled input trigger status of Main I/O pins 0-7 (0 = not triggered, 1 = triggered). Polled input trigger status of Main I/O pins 8-15 (0 = not triggered, 1 = triggered). Polled input trigger status of Auxiliary I/O pins 0-7 (0 = not triggered, 1 = triggered).
POLLMODE – BASIC Stamp Command Reference Setup: POLLIN FDoor, 0 POLLIN BDoor, 0 POLLIN Patio, 0 POLLOUT AlarmLed, 1 POLLMODE 10 DEBUG CLS, "Alarms Activated", CR Main: DO DEBUG "." PAUSE 50 LOOP UNTIL (AlarmLed = 1) GET 128, alarms POLLMODE 0 Report: DEBUG CLS, "Front Door : ", CR, "Back Door : ", CR, "Patio : ", CR FOR idx = 0 TO 2 DEBUG CRSRXY, 13, idx IF (alarms.LOWBIT(idx)) THEN DEBUG "Alarm", CR ELSE DEBUG "-", CR ENDIF NEXT DEBUG CR, "Press RESET to clear...
5: BASIC Stamp Command Reference – POLLOUT POLLOUT BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px 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. • State is a variable/constant/expression (0 – 1) that specifies whether to set the I/O pin low (0) or high (1) when a polled-input pin changes to its poll state. Quick Facts Table 5.78: POLLOUT Quick Facts.
POLLOUT – 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 POLLOUT command achieves one of three possible actions in 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: A SIMPLE POLLOUT EXAMPLE. POLLIN 0, 0 POLLOUT 1, 1 POLLMODE 2 Main: DEBUG "Looping...
5: BASIC Stamp Command Reference – POLLOUT INPUT 0 OUTPUT 1 Main: OUT1 = ~IN0 DEBUG "Looping...", CR OUT1 = ~IN0 GOTO Main 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. Clearly, using the polling commands is more efficient.
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. A clever use of the "latched" feature is to set a polled input on the same pin as a polled output.
5: BASIC Stamp Command Reference – POLLOUT It is important to note that during the time between the POLLOUT and POLLIN commands, I/O pin 0 will be set to an output direction. This can cause a temporary short within the circuitry connected to I/O pin 0, so it is vital that a large enough series resistor (perhaps 100 ohms or greater) be inserted on that pin to protect the external device and the BASIC Stamp. Demo Program (POLL.
POLLOUT – BASIC Stamp Command Reference "Front Door : ", CR, "Back Door : ", CR, "Patio : ", CR FOR idx = 0 TO 2 DEBUG CRSRXY, 13, idx IF (alarms.LOWBIT(idx)) THEN DEBUG "Alarm", CR ELSE DEBUG "-", CR ENDIF NEXT DEBUG CR, "Press RESET to clear..." DO : LOOP UNTIL (Rst = 0) GOTO Setup END ' scan alarm bits ' move cursor ' report each bit status ' wait until Rst pressed Page 330 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – POLLRUN POLLRUN BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px POLLRUN ProgramSlot Function Specify a program to run upon a polled-input event. • ProgramSlot is a variable/constant/expression (0 – 7) that specifies the program slot to run when a polled-input event occurs. Quick Facts Table 5.80: POLLRUN Quick Facts. Default ProgramSlot Special Notes Useful SPRAM locations Related commands BS2p, BS2pe, and BS2px The default polled-run slot is 0.
POLLRUN – BASIC Stamp Command Reference The following is a simple example of the POLLRUN command. POLLIN 0, 0 POLLRUN 1 POLLMODE 3 Main: DEBUG "Waiting in Program Slot 0...", CR GOTO Main The first line of the above code will set up I/O pin 0 as a polled-input pin looking for a low (0) state. The second line, POLLRUN, tells the BASIC Stamp that when I/O pin 0 goes low, it should switch execution over to the program residing in program slot 1.
5: BASIC Stamp Command Reference – POLLRUN Demo Program (POLLRUN0.bsp) NOTE: This example program can be used with the BS2p, BS2pe, and BS2px by changing the $STAMP directive accordingly. ' ' ' ' ' ' ' ' POLLRUN0.bsp This program demonstrates the POLLRUN command. It is intended to be downloaded to program slot 0, and the program called POLLRUN1.bsp should be downloaded to program slot 1. I/O pin 0 is set to watch for a low signal.
POLLRUN – BASIC Stamp Command Reference Page 334 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – POLLWAIT POLLWAIT BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px POLLWAIT Duration Function Pause program execution, in a low-power mode, in units of Duration until any polled-input pin reaches the desired poll state. • Duration is a variable/constant/expression (0 – 8) that specifies the duration of the low-power state. The duration is (2^Duration) * 18 ms. Table 5.82 on page 336 indicates the low-power length for any given Duration.
POLLWAIT – BASIC Stamp Command Reference polled-input pins. It "polls" these pins after the end of each PBASIC command and before it reads the next PBASIC command from the user program; giving the appearance that it is polling "in the background". This feature should not be confused with the concept of interrupts, as the BASIC Stamp does not support true interrupts. The POLLWAIT command is unique among the polling commands in that it actually causes execution to halt, until a polled-input pin event occurs.
5: BASIC Stamp Command Reference – POLLWAIT In this example, the POLLIN command sets I/O pin 0 to be a polled-input pin looking for a low (0) state. The Main routine immediately runs a POLLWAIT command and specifies a Duration of 2 (which results in a low-power state of 72 ms). This means that every 72 ms, the BASIC Stamp wakes-up and checks I/O pin 0 for a low. If I/O pin 0 is high, it goes back to sleep for another 72 ms.
POLLWAIT – BASIC Stamp Command Reference Page 338 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – POT POT 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px 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. • Scale is a variable/constant (0 – 255) used to scale the command's internal 16-bit result.
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. The amount by which the internal value must be scaled varies with the size of the resistor being used. Finding the best Scale value: 1. Build the circuit shown in Figure 5.
5: BASIC Stamp Command Reference – POT ' {$STAMP BS1} ' {$PBASIC 1.0} SYMBOL SYMBOL PotPin Scale = 0 = 111 ' pot connected to P0 ' scale value for test circuit SYMBOL level = B2 ' storage of pot "level" Main: POT PotPin, Scale, level DEBUG CLS, "Level = ", #level PAUSE 50 GOTO Main END ' ' ' ' read pot level display short delay repeat forever BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
POT – BASIC Stamp Command Reference Page 342 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – PULSIN PULSIN 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px PULSIN Pin, State, Variable Function 1 NOTE: Expressions are not allowed as arguments on the BS1. The range of the Pin argument on the BS1 is 0 – 7. Measure the width of a pulse on Pin described by State and store the result in Variable. • Pin is a variable/constant/expression (0 – 15) that specifies the I/O pin to use. This pin will be set to input mode.
PULSIN – BASIC Stamp Command Reference (greater than the Maximum Pulse Width shown in Table 5.83) PULSIN "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. Unless the pulse widths are known to be short enough to fit in an 8-bit result, it is recommended to use a word-sized variable.
5: BASIC Stamp Command Reference – PULSIN Main: PULSIN Pulse, 1, time IF time = 0 THEN Main DEBUG CLS, time GOTO Main END All 2 NOTE: This example program can be used with all BS2 models. This program uses conditional compilation techniques; see Chapter 3 for more information. ' measure positive pulse ' if 0, try again ' else display result Demo Program (PULSIN.bs2) ' ' ' ' ' ' ' ' PULSIN.bs2 This program uses PULSIN to measure a pulse generated by discharging a 0.1 uF capacitor through a 1K resistor.
PULSIN – BASIC Stamp Command Reference Page 346 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – PULSOUT PULSOUT 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px PULSOUT Pin, Duration Function 1 NOTE: Expressions are not allowed as arguments on the BS1. The range of the Pin argument on the BS1 is 0 – 7. Generate a pulse on Pin with a width of Duration. • Pin is a variable/constant/expression (0 – 15) that specifies the I/O pin to use. This pin will be set to output mode.
PULSOUT – BASIC Stamp Command Reference Figure 5.29b shows the sequence of events on that pin. Initially, pin 7 is high. Its output driver is turned off (because it is in input mode), so the 10 kΩ 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. (instruction executes) PULSOUT 7,5 Vdd 10 kΩ P7 Figure 5.29: Example Pulse Diagram.
5: BASIC Stamp Command Reference – PULSOUT Setup: HIGH 0 ' make P0 high (LED off) Main: PULSOUT 0, 2500 PAUSE 1000 GOTO Main END All 2 ' flash LED for 25 mS ' one second delay Demo Program (PULSOUT.bs2) ' PULSOUT.bs2 NOTE: This example program can be used with all BS2 models. This program ' This program blinks an LED on for 25 ms at 1-second intervals. Connect an uses conditional compilation techniques; ' LED (active-low) to I/O pin 0. see Chapter 3 for more information. ' {$STAMP BS2} ' {$PBASIC 2.
PULSOUT – BASIC Stamp Command Reference Page 350 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – PUT PUT BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px PUT Location, { WORD } Value { , { WORD } Value... } NOTE: The optional arguments require PBASIC 2.5. Function Write one or more values to the Scratch Pad RAM (SPRAM), starting at Location. • Location is a variable/constant/expression (0 – 62 for BS2e and BS2sx, and 0 – 126 for BS2p, BS2pe, and BS2px) that specifies the SPRAM location to write to.
PUT – BASIC Stamp Command Reference temp VAR byte PUT 25, 100 GET 25, temp DEBUG DEC temp ' put low byte ' read byte value ' display byte value When using the $PBASIC 2.5 directive, multiple sequential values may be stored to SPRAM, starting at Location, and the WORD modifier may be specified to store 16-bit values. ' {$PBASIC 2.
5: BASIC Stamp Command Reference – PUT DEBUG "Program Slot #", DEC value.NIB0, CR Main: FOR idx = 0 TO 9 value = (idx + 3) * 8 PUT idx, value DEBUG " Writing: ", DEC2 value, " to location: ", DEC2 idx, CR NEXT DEBUG CR RUN 1 END Demo Program (GET_PUT2.bsx) NOTE: This is written for the BS2sx but can be used with the BS2e, BS2p, BS2pe, and BS2px also. This program uses conditional compilation techniques; see Chapter 3 for more information. ' ' ' ' ' ' ' GET_PUT2.
PUT – BASIC Stamp Command Reference Page 354 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – PWM PWM 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px PWM Pin, Duty, Cycles Function 1 NOTE: Expressions are not allowed as arguments on the BS1. The range of the Pin argument on the BS1 is 0 – 7. Convert a digital value to analog output via pulse-width modulation. • Pin is a variable/constant/expression (0 – 15) that specifies the I/O pin to use. This pin will be set to output mode initially then set to input mode when the command finishes.
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 pulses and store the average voltage. The resistor/capacitor combination in Figure 5.31 will do the job. The capacitor will hold the voltage set by PWM even after the instruction has finished.
5: BASIC Stamp Command Reference – PWM state of the pin would change the voltage on the capacitor and undo the 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.
PWM – BASIC Stamp Command Reference ' as the capacitor discharges. Try varying the interval between PWM bursts ' (by changing the PAUSE value) and the number of PWM cycles to see their ' effect. ' {$STAMP BS1} ' {$PBASIC 1.0} Main: PWM 0, 100, 10 PAUSE 1000 GOTO Main END ' PWM at 100/255 duty (~50 ms) ' wait one second Demo Program (PWM.bs2) ' ' ' ' ' ' ' ' All PWM.
5: BASIC Stamp Command Reference – RANDOM RANDOM 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px 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. Each pass through RANDOM stores the next number, in the pseudorandom sequence, in Variable. Explanation RANDOM generates pseudo-random numbers ranging from 0 to 65535.
RANDOM – BASIC Stamp Command Reference SYMBOL result = W1 1 Setup: result = 11000 Main: RANDOM result DEBUG result GOTO Main -- or -result VAR Word All 2 Setup: result = 11000 Main: RANDOM result DEBUG DEC ? result GOTO Main Here, result is only initialized once, before the loop. Each time through the loop, the previous value of result, generated by RANDOM, is used as the next seed value. This generates a more desirable set of pseudorandom numbers.
5: BASIC Stamp Command Reference – RANDOM 1 Demo Program (RANDOM.bs1) ' ' ' ' ' RANDOM.bs1 Connect a button to I/O pin 7 as shown in the figure in the RANDOM command description 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. ' {$STAMP BS1} ' {$PBASIC 1.
RANDOM – BASIC Stamp Command Reference ' heads and tails thrown. ' {$STAMP BS2} ' {$PBASIC 2.5} Btn PIN 7 ' button input flip coin trials heads tails btnWrk VAR VAR VAR VAR VAR VAR Word flip.
5: BASIC Stamp Command Reference – RCTIME RCTIME All BS1 BS2 1 (See POT) 2 RCTIME Pin, State, Variable BS2e BS2sx BS2p BS2pe BS2px 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. This pin will be placed into input mode. • State is a variable/constant/expression (0 - 1) that specifies the desired state to measure.
RCTIME – BASIC Stamp Command Reference Figure 5.33 shows suitable RC circuits for use with RCTIME. The circuit in Figure 5.33a is preferred, because the BASIC Stamp's logic threshold is approximately 1.4 volts. This means that the voltage seen by the pin will start at 5V then fall to 1.4V (a span of 3.6V) before RCTIME stops. With the circuit of Figure 5.33b, the voltage will start at 0V and rise to 1.4V (spanning only 1.4V) before RCTIME stops.
5: BASIC Stamp Command Reference – RCTIME percent of the total change in voltage that they will undergo. More importantly, the value τ is used in the generalized RC timing calculation. Tau’s formula is just R multiplied by C: τ=RxC CALCULATING CHARGE AND DISCHARGE TIME.
RCTIME – BASIC Stamp Command Reference So it takes only 110 µ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.33: You may be wondering why the 220 Ω resistor is necessary at all. Consider what would happen if resistor R in Figure 5.33a were a pot, and were adjusted to 0 Ω. When the I/O pin went high to charge the cap, it would see a short direct to ground.
5: BASIC Stamp Command Reference – RCTIME Vdd Figure 5.34: Relay Circuit for Demo Program RCTIME2.bs2. relay coil P6 Vdd 10 kΩ Relay: 5 VDC reed relay with 20 mA coil, eg., Radio Shack #275-232 relay contact P7 Vss All 2 NOTE: This example program can be used with all BS2 models. This program uses conditional compilation techniques; see Chapter 3 for more information. Demo Program (RCTIME2.bs2) ' ' ' ' ' ' ' RCTIME2.BS2 This program illustrates the use of RCTIME as a fast stopwatch.
RCTIME – BASIC Stamp Command Reference DEC Result, CR HIGH Coil PAUSE 1000 LOOP END ' release relay ' wait one second Page 368 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – READ READ 1 NOTE: Optional arguments require PBASIC 2.5. All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px READ Location, Variable READ Location, { WORD } Variable {, { WORD } Variable... } Function 1 NOTE: Expressions are not allowed as arguments on the BS1. Read the value at Location in EEPROM and store the result in Variable. • Location is a variable/constant/expression (0 – 255 on BS1, 0 – 2047 on all BS2 models) that specifies the EEPROM address to read from.
READ – BASIC Stamp Command Reference The following READ command retrieves the value at location 100 and stores it into the variable called result: SYMBOL result = B2 A SIMPLE READ COMMAND. 1 READ 100, result --or-result VAR Byte All 2 READ 100, result The EEPROM is organized as a sequential set of byte-sized memory locations. The READ command normally only retrieves byte-sized values from EEPROM. This does not mean that you can't read word-sized values, however.
5: BASIC Stamp Command Reference – READ All 2 ' {$PBASIC 2.5} result VAR Word DATA Word 1125 READ 0, Word result DEBUG DEC ? result This code uses the EEPROM or DATA directive to write the low-byte and high-byte of the number 1125 into locations 0 and 1 during download. The BS1 code the uses two READ commands to read each of the bytes out of EEPROM and reconstructs them into a single word-sized variable. PBASIC 2.
READ – BASIC Stamp Command Reference Memory Map of the program before you download it. On all BS2 models you will need to view the Memory Map of the program before you download it, to determine the last EEPROM location used. See the "Memory Map Function" section in Chapter 3. On the BS2p, BS2pe, and BS2px, the READ and WRITE commands can affect locations in any program slot as set by the STORE command. See the STORE command for more information. Demo Program (READ.bs1) 1 ' READ.
5: BASIC Stamp Command Reference – READ All 2 NOTE: This example program can be used with all BS2 models by changing the $STAMP directive accordingly. Demo Program (READ.bs2) ' ' ' ' ' READ.bs2 This program reads a string of data stored in EEPROM. The EEPROM data is downloaded to the BS2 at compile-time and remains there (even with the power off) until overwritten. Put ASCII characters into EEPROM, followed by 0, which will serve as the end-of-message marker. ' {$STAMP BS2} ' {$PBASIC 2.
READ – BASIC Stamp Command Reference Page 374 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – RETURN RETURN 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px RETURN Function Return from a subroutine, assuming there was a previous GOSUB executed. Quick Facts Table 5.89: RETURN Quick Facts. Related Commands Maximum Number of RETURNS per Program 1 NOTE: On the BS1, a RETURN without a GOSUB will return the program to the last GOSUB (or will end the program if no GOSUB was executed). BS1 BS2 Models GOSUB GOSUB and ON Unlimited.
RETURN – BASIC Stamp Command Reference it would see the RETURN again (although it didn't GOSUB to that routine 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" a subroutine. 1 All 2 Demo Program (RETURN.bs2) ' ' ' ' ' ' ' ' RETURN.
5: BASIC Stamp Command Reference – REVERSE REVERSE 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px REVERSE Pin Function 1 NOTE: Expressions are not allowed as arguments on the BS1. The range of the Pin argument on the BS1 is 0 – 7. Reverse the data direction of the specified pin. • Pin is a variable/constant/expression (0 – 15) that specifies the I/O pin to use. This pin will be placed into the mode opposite its current input/output mode. Quick Facts Table 5.90: REVERSE Quick Facts.
REVERSE – BASIC Stamp Command Reference Demo Program (REVERSE.bs1) ' ' ' ' ' ' ' ' ' ' ' ' ' 1 REVERSE.bs1 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. When pin 0 is an input, current flows through R1, through the LED, through R2 to ground.
5: BASIC Stamp Command Reference – REVERSE Main: PAUSE 250 REVERSE 0 GOTO Main ' 1/4th second pause ' reverse pin 0 I/O direction ' do forever BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
REVERSE – BASIC Stamp Command Reference Page 380 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – RUN RUN BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px RUN ProgramSlot Function Switches execution to another BASIC Stamp program (in a different program slot). • ProgramSlot is a variable/constant/expression (0 – 7) that specifies the program slot to run. Quick Facts Table 5.91: RUN Quick Facts.
RUN – BASIC Stamp Command Reference ' Download this program to Slot 0 DEBUG "Hello " RUN 1 ' Download this program to Slot 1 DEBUG "World!" PAUSE 1000 RUN 0 The above two programs (assuming they have been downloaded into program slots 0 and 1, respectively) will display "Hello World!" on the screen. Program 0 is the first to run and it displays "Hello ", then issues a RUN 1 command. The BASIC Stamp then starts execution of program 1, from its first line of code, which causes "World!" to be displayed.
5: BASIC Stamp Command Reference – RUN When the Slot 1 program runs you may be surprised to see that cats and dogs are now zero and fleas are up to 259! – even though we didn't explicitly define them. What happened? The key to remember is that variable names are simply pointers to RAM addresses, and the PBASIC compiler assigns variable names to RAM in descending order by size.
RUN – BASIC Stamp Command Reference In the BASIC Stamp, the variable RAM is implicitly considered an array. What this line is doing, then, is moving the value in each RAM address (B0(1), B0(2), B0(3), ...) to the SPRAM address that corresponds with its byte index. The process is simply reversed to retrieve the RAM variable space. Any ProgramSlot specified above 7 will wrap around and result in running one of the 8 programs (RUN 8 will run program 0, RUN 9 will run program 1, etc).
5: BASIC Stamp Command Reference – RUN FOR idx = 0 TO 4 READ (slotNum * 5) + idx, value DEBUG DEC3 value, " " NEXT DEBUG CR PAUSE 1000 ' read/display table values RUN 1 ' run Slot 1 pgm Demo Program (RUN2.bsx) NOTE: This example program was written for the BS2sx but can be used with the BS2e, BS2p, BS2pe, and BS2px. This program uses conditional compilation techniques; see Chapter 3 for more information. ' ' ' ' ' ' ' RUN2.bsx This example demonstrates the use of the RUN command.
RUN – BASIC Stamp Command Reference Page 386 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – SELECT...CASE SELECT…CASE All NOTE: SELECT...CASE requires PBASIC 2.5. 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px SELECT Expression CASE Condition(s) Statement(s) { CASE Condition(s) Statement(s)... } { CASE ELSE Statement(s) } ENDSELECT Function Evaluate Expression and conditionally execute a code block based on comparison to Condition(s) then continue execution with line following ENDSELECT. • Expression is a variable, a constant, or an expression.
SELECT...CASE – BASIC Stamp Command Reference Explanation SELECT…CASE is an advanced decision-making structure that is often used to replace compound IF…THEN…ELSE structures. SELECT…CASE statements are good for performing one of many possible actions depending on the value of a single expression.
5: BASIC Stamp Command Reference – SELECT...CASE Value1 TO Value2 This indicates a range of Value1 to Value2, inclusive. For example, 20 TO 23 means 20, 21, 22 and 23. Similarly, “A” TO “F” means all the characters in the range “A” through “F”. Finally, multiple conditions can be included in a single CASE by separating them with commas ( , ).
SELECT...CASE – BASIC Stamp Command Reference Higher.” then continues after the ENDSELECT, displaying “Try again: “ on the screen and giving the user another guess. If guess is greater than 140, the second CASE is true, “Too high.” will be displayed followed by “Try again: “, etc. If the user guesses 123, they are congratulated and the program stops. You may have noticed a potential error in the code: both of the last two CASEs are true if guess is 123.
5: BASIC Stamp Command Reference – SELECT...CASE test sample odd even isLo isMid isHi VAR VAR VAR VAR VAR VAR VAR Byte Word Byte Byte Byte Byte Byte Main: sample = 11000 FOR test = 1 TO 100 RANDOM sample counter for tests random number to be tested odd throws even throws sample in lower third in middle thrid in upper third ' initialize seed ' "throw" 100 times ' randomize IF (sample.
SELECT...CASE – BASIC Stamp Command Reference Page 392 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – SERIN SERIN 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px SERIN Rpin, Baudmode, { ( Qualifier ), } { # } InputData SERIN Rpin { \Fpin }, Baudmode, { Plabel, } { Timeout, Tlabel, } [ InputData ] Function 1 NOTE: Expressions are not allowed as arguments on the BS1. The range of the Rpin argument on the BS1 is 0 – 7. Receive asynchronous serial data (e.g., RS-232 data).
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 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px Units in Timeout n/a 1 ms 1 ms 0.4 ms 0.4 ms 1 ms 0.4 ms Baud range 300, 600, 1200, and 2400 only 243 to 50K 243 to 50K 608 to 115.2K 608 to 115.2K 243 to 50K 972 to 115.2K 19.2K 19.2K 19.2K 19.2K 19.2K 19.
5: BASIC Stamp Command Reference – SERIN RS-232 is the electrical specification for the signals that PC serial ports use. Unlike normal logic, where 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. Most circuits that work with RS-232 use a line driver/receiver.
SERIN - BASIC Stamp Command Reference Figure 5.36 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 22 kΩ resistor 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. Note that PC serial ports are always male connectors.
5: BASIC Stamp Command Reference – SERIN Table 5.96: Baudmode calculation for all BS2 models. Add the results of steps 1, 2 and 3 to determine the proper value for the Baudmode argument. Table 5.97: BS2, BS2e, and BS2pe common baud rates and corresponding Baudmodes. Table 5.98: BS2sx and BS2p common baud rates and corresponding Baudmodes. Table 5.99: BS2px common baud rates and corresponding Baudmodes. Step 1: Determine the bit period (bits 0 – 11). Step 2: Set data bits and parity (bit 13).
SERIN - BASIC Stamp Command Reference that use a 7-bit data mode do so in order to take advantage of the parity feature. Parity can detect some communication errors, but to use it you lose one data bit. This means that incoming data bytes transferred in 7E (even-parity) mode can only represent values from 0 to 127, rather than the 0 to 255 of 8N (no-parity) mode. Usually a device requires only 1 stop bit per byte. Occasionally, however, you may find a device that requires 2 or more stop bits.
5: BASIC Stamp Command Reference – SERIN The SERIN command provides a formatter, called the decimal formatter, which will interpret this for us. Look at the following code: 1 SYMBOL serData = B2 SERIN 1, N2400, #serData -- or -All 2 Note: This is written with the BS2's Baudmode value. Be sure to adjust the value for your BASIC Stamp. DECIMAL FORMATTER SPECIFICS. serData VAR Byte SERIN 1, 16780, [DEC serData] Notice the decimal formatter in the SERIN command.
SERIN - BASIC Stamp Command Reference 2) Serial input: 123 (with no characters following it) Result: The BASIC Stamp halts at the SERIN command. It recognizes the characters “1”, “2” and “3” as the number one hundred twenty three, but since no characters follow the “3”, it waits continuously, since there’s no way to tell whether 123 is the entire number or not.
5: BASIC Stamp Command Reference – SERIN The SERIN command can also be configured to wait for specified data before it retrieves any additional input. For example, suppose a device that is attached to the BASIC Stamp is known to send many different sequences of data, but the only data you desire happens to appear right after the unique characters, “XYZ”. The BS1 has optional Qualifier arguments for this purpose. On all BS2 models, a special formatter called WAIT can be used for this.
SERIN - BASIC Stamp Command Reference The decimal formatter is only one of a whole family of conversion formatters available with SERIN on all the BS2 models. See Table 5.100 for a list of available conversion formatters. All of the conversion formatters work similar to the decimal formatter (as described in the “Decimal Formatter Specifics” section, above). The formatters receive bytes of data, waiting for the first byte that falls within the range of characters they accept (e.g.
5: BASIC Stamp Command Reference – SERIN Table 5.100: Conversion Formatters for all BS2 models. Conversion Formatter Type of Number DEC{1..5} SDEC{1..5} Decimal, optionally limited to 1 – 5 digits Signed decimal, optionally limited to 1 – 5 digits Hexadecimal, optionally limited to 1 – 4 digits HEX{1..4} SHEX{1..4} IHEX{1..4} ISHEX{1..4} BIN{1..16} SBIN{1..16} IBIN{1..16} ISBIN{1..
SERIN - BASIC Stamp Command Reference While very effective at filtering and converting input text, the formatters aren’t completely foolproof. As mentioned before, many conversion formatters will keep accepting text until the first non-numeric text arrives, even if the resulting value exceeds the size of the variable. After SERIN, a byte variable will contain the lowest 8 bits of the value entered and a word would contain the lowest 16 bits.
5: BASIC Stamp Command Reference – SERIN three bytes (elements). See the "Defining Arrays" section in Chapter 4 for more information on arrays. Here is an example that receives nine bytes through I/O pin 1 at 9600 bps, N81/inverted and stores them in a 10-byte array: All 2 NOTE: The rest of the code examples for this section are written for the BS2, using the BS2's BaudMode and Timeout values. Be sure to adjust the value for your BASIC Stamp.
SERIN - BASIC Stamp Command Reference bytes, it is case-sensitive—“sesame” or “SESAmE” or any other variation from “SESAME” would be ignored. SERIN can also wait for a sequence that matches a string stored in an array variable with the WAITSTR formatter. In the example below, we’ll capture a string with STR then have WAITSTR look for an exact match: serStr VAR Byte(10) serStr(9) = 0 SERIN 1, 16468, [STR serStr\9\"!"] DEBUG "Waiting for:", STR serStr, CR SERIN 1, 16468, [WAITSTR serStr] DEBUG "Password ac
5: BASIC Stamp Command Reference – SERIN The unwanted x data is stored in yOffset then replaced by the desired y data. This is a sneaky way to filter out a number of any size without using an extra variable. With a little creativity, you can combine the InputData modifiers to filter and extract almost any data. USING PARITY AND HANDLING PARITY Parity is a simple error-checking feature.
SERIN - BASIC Stamp Command Reference Bad_Data. Note that a parity error takes precedence over other InputData specifications (as soon as an error is detected, SERIN aborts and goes to the Plabel routine). In all the examples above, the only way to end the SERIN instruction (other than RESET or power-off) is to give SERIN the serial data it wants. If no serial data arrives, the program is stuck.
5: BASIC Stamp Command Reference – SERIN All 2 ' {$PBASIC 2.5} result VAR Word Main: DO SERIN 1, 24660, Bad_Data, 10000, No_Data, [DEC result] DEBUG CLS, ? result LOOP Bad_Data: DEBUG CLS, "Parity error" GOTO Main No_Data: DEBUG CLS, "Timeout error" GOTO Main When you design an application that requires serial communication between BASIC Stamp modules, you have to work within these limitations: • When the BASIC Stamp is sending or receiving data, it can’t execute other instructions.
SERIN - BASIC Stamp Command Reference When SERIN executes, I/O pin 1 (Rpin) is made an input in preparation for incoming data, and I/O pin 0 (Fpin) is made output low, to signal “go” to the sender. After SERIN finishes receiving, I/O pin 0 goes high to tell the sender to stop. If an inverted BaudMode had been specified, the Fpin’s responses would have been reversed. Here’s the relationship of serial polarity to Fpin states.
5: BASIC Stamp Command Reference – SERIN 2. 3. 4. 5. 6. b. Add more and more small pieces, testing them each time, as you go. c. Never write a large portion of code that works with serial communication without testing its smallest workable pieces first. Pay attention to timing. a. 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.
SERIN - BASIC Stamp Command Reference Stamp to continue. See Appendix C for example input data and the effects on formatters. Demo Program (SERIN.bs1) ' ' ' ' ' 1 SERIN.bs1 This program waits for the characters "A", "B", "C", and "D" to arrive at the serial input (inverted, 2400 baud, N81), followed by a number, then a carriage-return or some other non-number character. The number is then displayed in the Debug window. ' {$STAMP BS1} ' {$PBASIC 1.
5: BASIC Stamp Command Reference – SERIN T38K4 CON #CASE BS2SX, BS2P T1200 CON T2400 CON T9600 CON T19K2 CON T38K4 CON #CASE BS2PX T1200 CON T2400 CON T9600 CON T19K2 CON T38K4 CON #ENDSELECT 6 Inverted Open Baud $4000 $8000 T38K4 + Inverted CON CON CON 2063 1021 240 110 45 3313 1646 396 188 84 Main: DO SEROUT SO\FC, Baud, ["Hello!", CR] PAUSE 2500 LOOP END All 2 NOTE: This example program was written for the BS2 but it can be used with the BS2e, BS2sx, BS2p, BS2pe, and BS2px.
SERIN - BASIC Stamp Command Reference #CASE BS2SX, BS2P T1200 CON T2400 CON T9600 CON T19K2 CON T38K4 CON #CASE BS2PX T1200 CON T2400 CON T9600 CON T19K2 CON T38K4 CON #ENDSELECT 2063 1021 240 110 45 3313 1646 396 188 84 Inverted Open Baud CON CON CON $4000 $8000 T38K4 + Inverted letter VAR Byte Main: DO SERIN SI\FC, Baud, [letter] DEBUG letter PAUSE 1000 LOOP END ' ' ' ' receive one byte display on screen wait one second repeat forever Page 414 • BASIC Stamp Syntax and Reference Manual 2.
5: BASIC Stamp Command Reference – SEROUT SEROUT 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px SEROUT Tpin, Baudmode, ( {#} OutputData ) SEROUT Tpin { \Fpin }, Baudmode, { Pace, } { Timeout, Tlabel, } [ OutputData ] Function 1 NOTE: Expressions are not allowed as arguments on the BS1. The range of the Rpin argument on the BS1 is 0 – 7. Transmit asynchronous serial data (e.g., RS-232 data).
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 BS1 n/a BS2, BS2e 1 ms BS2sx 1 ms BS2p 1 ms BS2pe 1 ms BS2px 1 ms n/a 1 ms 0.4 ms 0.4 ms 1 ms 0.4 ms Baud range 300, 600, 1200, and 2400 only 243 to 50K 608 to 115.2K 608 to 115.2K 243 to 50K 972 to 115.2K Baud limit with flow control n/a 19.2K 19.2K 19.2K 19.2K 19.
5: BASIC Stamp Command Reference – SEROUT 1 All 2 Figure 5.38: Serial port diagram showing correct connections to a BASIC Stamp's I/O pin. All BASIC Stamp models (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 Stamp models). 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.
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.105 indicates the Baudmode value or symbols to use when selecting the desired mode.
5: BASIC Stamp Command Reference – SEROUT Table 5.107: BS2, BS2e and BS2pe common baud rates and corresponding Baudmodes. Table 5.108: BS2sx and BS2p common baud rates and corresponding Baudmodes.
SEROUT – BASIC Stamp Command Reference Here, SEROUT will transmit a byte equal to 65 (the ASCII value of the character "A") through pin 1. If the BASIC Stamp were connected to a PC running a terminal program (set to the same baud rate) the character "A" would appear on the screen (see the ASCII character chart in Appendix A).
5: BASIC Stamp Command Reference – SEROUT All 2 This is written with the BS2's Baudmode value. Be sure to adjust the value for your BASIC Stamp model. 1 USING SEROUT'S PACE ARGUMENT TO INSERT DELAYS BETWEEN TRANSMITTED BYTES. All 2 SEROUT 1, 16780, ["Hello", CR] SEROUT 1, 16780, ["Num = ", DEC 100] The above code will display "HELLO" on one line and "Num = 100" on the next line. Notice that you can combine data to output in one SEROUT command, separated by commas.
SEROUT – BASIC Stamp Command Reference indicated number of digits (in the case of the fixed length formatters) is translated. All BS2 models also have special formatters for outputting a string of characters, and repeated characters. See Table 5.111 for a list of these special formatters. Conversion Formatter DEC{1..5} SDEC{1..5} HEX{1..4} SHEX{1..4} IHEX{1..4} Type of Number Notes All 2 Table 5.110: Conversion Formatters for all BS2 models.
5: BASIC Stamp Command Reference – SEROUT same size. The string "ABC" could be stored in a byte array containing three bytes (elements). See the “Defining Arrays” section in Chapter 4 for more information on arrays. Here is an example that transmits five bytes (from a byte array) through I/O pin 1 at 9600 bps, N81/inverted: All 2 serStr Main: serStr(0) serStr(1) serStr(2) serStr(3) serStr(4) SEROUT 1, VAR Byte(5) = "H" = "E" = "L" = "L" = "O" 16468, [STR serStr\5] ' create 5-byte array ' fill array
SEROUT – BASIC Stamp Command Reference • • When the BASIC Stamp is sending or receiving data, it can’t execute other instructions. When the BASIC Stamp is executing other instructions, it can’t send or receive data. The BASIC Stamp does not have a serial buffer as there is in PCs. At most serial rates, the BASIC Stamp cannot receive data via SERIN, process it, and execute another SERIN in time to catch the next chunk of data, unless there are significant pauses between data transmissions.
5: BASIC Stamp Command Reference – SEROUT In Figure 5.39 below, I/O pin 0, Fpin, is pulled to ground through a 10k resistor. This is to ensure that the sender sees a stop signal (0 for inverted communications) when the receiver is being programmed. In the flow control examples above, the only way the SEROUT instruction will end (other than RESET or power-off) is if the receiver allows it to send the entire OutputData list. If Fpin permission never occurs, the program is stuck.
SEROUT – BASIC Stamp Command Reference themselves. Since the open baudmodes only drive in one state and float in the other, there's no chance of this kind of short. The polarity selected for SEROUT determines which state is driven and which is open as in Table 5.113. State (0) Open Driven Inverted Non-inverted State (1) Driven Open Resistor Pulled to Gnd (Vss) +5V (Vdd) Table 5.113: Open Baudmode States for all BS2 models.
5: BASIC Stamp Command Reference – SEROUT Figure 5.41: SEROUT OpenSource Circuit. This circuit is for use with the Open, Inverted baudmode. 1 kΩ Vss To other devices To other devices I/O Pin Gnd (Vss) BASIC Stamp SEROUT TROUBLESHOOTING. I/O Pin Gnd (Vss) BASIC Stamp Serial communication, because of its complexity, can be very difficult to work with at times.
SEROUT – BASIC Stamp Command Reference a. 5. Unmatched settings on the sender and receiver side will cause garbled data transfers or no data transfers. If the data you receive is unreadable, it is most likely a baud rate setting error. If data transmitted to the Stamp Editor's Debug Terminal is garbled, verify the output format. a. A common mistake is to send data with SEROUT in ASCII format. For example, SEROUT 16, 84, [ 0 ] instead of SEROUT 16, 84, [ DEC 0 ].
5: BASIC Stamp Command Reference – SEROUT ' would be long gone. With flow control, communication is flawless since ' the sender waits for the receiver to catch up. ' {$STAMP BS2} ' {$PBASIC 2.
SEROUT – BASIC Stamp Command Reference ' the sender waits for the receiver to catch up. ' {$STAMP BS2} ' {$PBASIC 2.
5: BASIC Stamp Command Reference – SHIFTIN SHIFTIN All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px 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. This pin will be set to input mode.
SHIFTIN – BASIC Stamp Command Reference At their heart, synchronous-serial devices are essentially shift-registers; trains of flip-flops that pass data bits along in a bucket brigade fashion to a single data output pin. Another bit is output each time the appropriate edge (rising or falling, depending on the device) appears on the clock line. The SHIFTIN instruction first causes the clock pin to output low and the data pin to switch to input mode.
5: BASIC Stamp Command Reference – SHIFTIN A SIMPLE SHIFTIN EXAMPLE. Here is a simple example: result VAR Byte SHIFTIN 0, 1, MSBPRE, [result] Here, the SHIFTIN command will read I/O pin 0 (Dpin) and will generate a clock signal on I/O 1 (Cpin). The data that arrives on Dpin depends on the device connected to it. Let's say, for example, that a shift register is connected and has a value of $AF (10101111) waiting to be sent.
SHIFTIN – BASIC Stamp Command Reference Demo Program (SHIFTIN.bs2) All ' SHIFTIN.bs2 ' This program uses the SHIFTIN instruction to interface with the ADC0831 ' 8-bit analog-to-digital converter from National Semiconductor. ' {$STAMP BS2} ' {$PBASIC 2.5} CS AData Clk PIN PIN PIN 0 1 2 ' chip select ' data pin ' clock pin adcRes VAR Byte ' ADC result Setup: HIGH CS ' ' ' ' ' ' ' deselect ADC In the loop below, just three lines of code are required to read the ADC0831.
5: BASIC Stamp Command Reference – SHIFTOUT SHIFTOUT All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px 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. This pin will be set to output mode.
SHIFTOUT – BASIC Stamp Command Reference serial protocol is commonly called Synchronous Peripheral Interface (SPI) and is used by controller peripherals like ADCs, DACs, clocks, memory devices, etc. 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.
5: BASIC Stamp Command Reference – SHIFTOUT A SIMPLE SHIFTOUT EXAMPLE. Here is a simple example: SHIFTOUT 0, 1, MSBFIRST, [250] Here, the SHIFTOUT command will write to I/O pin 0 (Dpin) and will generate a clock signal on I/O pin 1 (Cpin). The SHIFTOUT command will generate eight clock pulses while writing each bit (of the 8-bit value 250) onto the data pin (Dpin). In this case, it will start with the most significant bit first as indicated by the Mode value of MSBFIRST.
SHIFTOUT – BASIC Stamp Command Reference LEDs Vdd 470 Ω (all) 1 2 3 4 5 6 QB VCC QC QA QD DATA IN QE 74HC595 QF QG 7 QH 8 GND OE 16 15 14 To P0 13 LATCH 12 CLK 11 RESET 10 SQH Figure 5.44: Circuit for Demo Program SHIFTOUT.bs2. Vss Vdd To P2 To P1 9 Vss Demo Program (SHIFTOUT.bs2) ' ' ' ' ' ' ' ' ' ' ' ' ' All SHIFTOUT.bs2 This program uses the SHIFTOUT command to interface to the 74HC595 shift register as an 8-bit output port.
5: BASIC Stamp Command Reference – SHIFTOUT ' msb first so that the msb appears on pin QH and the lsb on QA. Changing ' MSBFIRST to LSBFIRST causes the data to appear backwards on the outputs. Main: DO SHIFTOUT Dpin, Clk, MSBFIRST, [counter] PULSOUT Latch, 1 PAUSE 100 counter = counter + 1 LOOP END ' ' ' ' send the bits transfer to outputs Wait 0.1 seconds increment counter BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
SHIFTOUT – BASIC Stamp Command Reference Page 440 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – SLEEP SLEEP 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px SLEEP Duration Function 1 NOTE: Expressions are not allowed as arguments on the BS1. Put the BASIC Stamp into low-power mode for a specified time. • Duration is a variable/constant/expression (1 – 65535) that specifies the duration of sleep. The unit of time for Duration is 1 second, though the BASIC Stamp rounds up to the nearest multiple of 2.3 seconds. Quick Facts Table 5.118: SLEEP Quick Facts.
SLEEP – BASIC Stamp Command Reference To ensure accuracy of SLEEP intervals, the BASIC Stamp periodically compares the watchdog timer to the more-accurate resonator time base. It calculates a correction factor that it uses during SLEEP. As a result, longer SLEEP intervals are accurate to approximately ±1 percent.
5: BASIC Stamp Command Reference – SLEEP Snooze: SLEEP 10 GOTO Snooze END ' sleep for 10 seconds BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
SLEEP – BASIC Stamp Command Reference Page 444 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – SOUND SOUND 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px SOUND Pin, ( Note, Duration { , Note, Duration…} ) (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. • Note is a variable/constant (0 – 255) specifying the type and frequency of the tone.
SOUND – BASIC Stamp Command Reference Driving an Audio Amplifier 1k 1k Amplifier (e.g., Radio Shack from I/O pin 0.1µF 0.01µF Vss Figure 5.46: Example RC filter circuits for driving an audio amplifier (top) or a speaker(bottom). 277-1008C) Vss Vss Driving a Speaker 10µF (both) from I/O pin + C1 + C2 ≥40Ω Speaker (or 8Ω in series with 33Ω resistor) Vss Vss Notes: C1 may be omitted for piezo speakers C2 is optional, but reduces high-frequency noise Demo Program (SOUND.bs1) ' SOUND.
5: BASIC Stamp Command Reference – STOP STOP All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px STOP Function Stop program execution. Quick Facts Table 5.120: STOP Quick Facts. All BS2 Models Related Command END Explanation STOP prevents the BASIC Stamp from executing any further instructions until it is reset. The following actions will reset the BASIC Stamp: 1. Pressing and releasing the RESET button on the development board. 2. Driving the RES pin low then letting it float (high). 3.
STOP – BASIC Stamp Command Reference Page 448 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – STORE STORE BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px STORE ProgramSlot Function Designate a program slot for the READ/WRITE instructions to operate upon. • ProgramSlot is a variable/constant/expression (0 – 7 on BS2p and BS2px, 0-15 on BS2pe) that specifies the program slot to use for READ and WRITE instructions. Quick Facts Table 5.121: STORE Quick Facts.
STORE – BASIC Stamp Command Reference Demo Program (STORE0.bsp) ' ' ' ' ' ' ' ' STORE0.bsp This program demonstrates the STORE command and how it affects the READ and WRITE commands. This program "STORE0.BSP" is intended to be downloaded into program slot 0. It is meant to work with STORE1.BSP and STORE2.BSP. Each program is very similar (they display the current Program Slot and READ/WRITE Slot numbers and the values contained in the first five EEPROM locations.
5: BASIC Stamp Command Reference – STORE Demo Program (STORE1.bsp) NOTE: This example program can be used with the BS2p, BS2pe, and BS2px by changing the $STAMP directive accordingly. ' STORE1.bsp ' {$STAMP BS2p} ' {$PBASIC 2.
STORE – BASIC Stamp Command Reference GOSUB Show_Slot_Info END Show_Slot_Info: GET 127, value DEBUG CR, "Pgm Slot: ", DEC value.NIB0, CR, "R/W Slot: ", DEC value.NIB1, CR, CR FOR idx = 0 TO 4 READ idx, value DEBUG "Location: ", DEC idx, TAB, "Value: ", DEC3 value, CR NEXT RETURN The next Demo program, STOREALL.bsp, is not related to the previous three programs. STOREALL.
5: BASIC Stamp Command Reference – STORE Main: DEBUG "Flat Memory", CR, "---------------------", CR, "First Slot..... ", DEC LoSlot, CR, "Last Slot...... ", DEC HiSlot, CR, "Flat EE Size... ", DEC MemSize, CR, CR PAUSE 2000 DEBUG "Writing to flat Memory...", CR PAUSE 1000 FOR eeAddr = 0 TO (MemSize - 1) STEP 128 value = eeAddr * 2 GOSUB Write_Word GET 127, slot DEBUG "--> Location: ", DEC5 eeAddr, " "Value: ", DEC5 value, " ", "(", DEC slot.NIB1, ")", CR NEXT DEBUG CR DEBUG "Reading from flat Memory...
STORE – BASIC Stamp Command Reference Page 454 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – TOGGLE TOGGLE 1 All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px TOGGLE Pin Function 1 NOTE: Expressions are not allowed as arguments on the BS1. The range of the Pin argument on the BS1 is 0 – 7. Invert the state of an output pin. • Pin is a variable/constant/expression (0 – 15) that specifies which I/O pin to switch logic state. This pin will be placed into output mode. Quick Facts Table 5.122: TOGGLE Quick Facts.
TOGGLE – BASIC Stamp Command Reference guarantee that the state actually changes, regardless of the initial input or output mode, do this: PIN2 = PIN2 TOGGLE 2 ' make output driver match input ' then toggle 1 ' make output driver match input ' then toggle All - or OUT2 = IN2 TOGGLE 2 2 Figure 5.47: Example LED Circuit for TOGGLE Demo Programs. Demo Program (TOGGLE.bs1) ' ' ' ' ' 1 TOGGLE.
5: BASIC Stamp Command Reference – TOGGLE All 2 NOTE: This example program can be used with all BS2 models by changing the $STAMP directive accordingly. Demo Program (TOGGLE.bs2) ' ' ' ' ' TOGGLE.bs2 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. The Debug window will show you the states of pins 0 through 3. ' {$STAMP BS2} ' {$PBASIC 2.
TOGGLE – BASIC Stamp Command Reference Page 458 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – WRITE WRITE 1 NOTE: Optional arguments require PBASIC 2.5. All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px WRITE Location, Value WRITE Location, { WORD } Value {, { WORD } Value... } 1 Function NOTE: Expressions are not allowed as arguments on the BS1. Write Value into Location in EEPROM. • Location is a variable/constant/expression (0 – 255 on BS1, 0 – 2047 on all BS2 models) that specifies the EEPROM address to write to.
WRITE – BASIC Stamp Command Reference The following WRITE command stores the value 245 at location 100: WRITE 100, 245 A SIMPLE WRITE COMMAND. 1 --or-WRITE 100, 245 All The EEPROM is organized as a sequential set of byte-sized memory locations. The WRITE command normally only stores byte-sized values into EEPROM. This does not mean that you can't write word-sized values, however. A word consists of two bytes, called a low-byte and a high-byte.
5: BASIC Stamp Command Reference – WRITE All 2 ' {$PBASIC 2.5} value VAR Word value = 1125 WRITE 0, Word value ' write two bytes When using PBASIC 2.5, a single WRITE command can write multiple bytes and words to sequential EEPROM locations. For example: All 2 ' {$PBASIC 2.5} value value2 VAR VAR Byte Word value = 18 value2 = 1125 WRITE 25, value, Word value2 SPECIAL NOTES FOR EEPROM USAGE.
WRITE – BASIC Stamp Command Reference On the BS1, location 255 holds the address of the last instruction in your program. Therefore, your program can use any space below the address given in location 255. For example, if location 255 holds the value 100, then your program can use locations 0–99 for data. You can read location 255 at run-time or simply view the Memory Map of the program before you download it.
5: BASIC Stamp Command Reference – WRITE All 2 NOTE: This example program can be used with all BS2 models by changing the $STAMP directive accordingly. Demo Program (WRITE.bs2) ' WRITE.bs2 ' This program writes some data to EEPROM and then reads them back out ' and displays the data in the Debug window. ' {$STAMP BS2} ' {$PBASIC 2.
WRITE – BASIC Stamp Command Reference Page 464 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
5: BASIC Stamp Command Reference – XOUT XOUT All 2 BS1 BS2 BS2e BS2sx BS2p BS2pe BS2px 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. This pin will be set to output mode.
XOUT – BASIC Stamp Command Reference assigned a house code and unit code by setting dials or switches on the module. To talk to a particular module, XOUT sends the appropriate house code and unit code. The module with the corresponding code listens for its house code again followed by a command (on, off, dim, or bright). X-10 signals are digital codes imposed on a 120 kHz carrier that is transmitted during zero crossings of the AC line.
5: BASIC Stamp Command Reference – XOUT Table 5.125 lists the XOUT command codes and their functions: Table 5.125: XOUT Commands and Their Function. Command Value Function UNITON %10010 Turn on the currently selected unit. UNITOFF %11010 Turn off the currently selected unit. UNITSONf %11100 Turn off all modules in this house code. LIGHTSON %10100 Turn on all lamp modules in this house code. DIM %11110 Reduce brightness of currently selected lamp.
XOUT – BASIC Stamp Command Reference The dim/bright commands support 19 brightness levels. Lamp modules may also be turned on and off using the standard UnitOn and UnitOff commands. In the example instruction above, we dimmed the lamp by 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) ' ' ' ' ' ' ' ' ' ' All XOUT.
5: BASIC Stamp Command Reference – XOUT ' This example shows the use of the optional Cycles argument. ' for 10 cycles. Here we DIM XOUT Mpin, Zpin, [HouseA\UNITOFF\2, HouseA\DIM\10] STOP BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
XOUT – BASIC Stamp Command Reference Page 470 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
Appendix A: ASCII Chart ASCII Chart (first 128 characters) Dec Hex Char Name / Function Dec Hex Char Dec Hex Char Dec Hex Char 0 00 NUL Null 32 20 space 64 40 @ 96 60 ` 1 01 SOH Start Of Heading 33 21 ! 65 41 A 97 61 a 2 02 STX Start Of Text 34 22 " 66 42 B 98 62 b 3 03 ETX End Of Text 35 23 # 67 43 C 99 63 c 4 04 EOT End Of Transmit 36 24 $ 68 44 D 100 64 d 5 05 ENQ Enquiry 37 25 % 69 45 E 101 65 e 6 06 ACK Acknowledge 38 26 & 70 46 F 102 66 f 7 07 BEL Bell 39 27 ' 71 47 G 103 67 g 8 08 BS Backspace 40 28
ASCII Chart Page 472 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
Appendix B: Reserved Words Reserved Words This appendix contains complete listings of the reserved words for PBASIC 1.0, PBASIC 2.0, and PBASIC 2.5, current with the BASIC Stamp Editor v2.1. The reserved word lists have been organized into 4 tables, because it varies with each BASIC Stamp model and version of PBASIC. Table B.1 shows the reserved words for the BASIC Stamp 1, using the required PBASIC 1.0. Table B.1: BS1 Reserved Words. AND B0..B13 BIT0..BIT15 BRANCH BSAVE BUTTON CLS CR DEBUG DIR0..
Reserved Words 2.5 #CASE 2.5 #DEFINE 2.5 #ELSE 2.5 #ENDIF 2.5 #ENDSELECT 2.5 #ERROR 2.5 #IF 2.5 #SELECT 2.5 #THEN $PBASIC $PORT $STAMP ABS AND ASC ATN B0...B25 BELL BIN BIN1...BIN16 BIT BIT0...BIT15 BKSP BRANCH BRIGHT BS1 BS2 BS2E BS2P BS2PE BS2SX BUTTON BYTE BYTE0 BYTE1 2.5 CASE 2.5 CLRDN 2.5 CLREOL CLS CON COS COUNT CR 2.5 CRSRDN 2.5 CRSRLF 2.5 CRSRRT 2.5 CRSRUP All BS2 Models 2.5 CRSRX INC 2.5 CRSRXY IND 2.5 CRSRY INH DATA INL DCD INPUT DEBUG INS 2.5 DEBUGIN ISBIN DEC ISBIN1...ISBIN16 DEC1...
Appendix B: Reserved Words There are some reserved words unique to specific BS2 models. The BS2e and BS2sx have all the reserved words shown in Table B.2, plus those shown in Table B.3. These additional words are reserved in both PBASIC 2.0 and PBASIC 2.5. Table B.3: Additional Reserved Words for the BS2e and BS2sx. GET BS2e and BS2sx PUT RUN The BS2p and BS2pe have all the reserved words shown in Table B.2, plus those shown in Table B.4. These additional words are reserved in both PBASIC 2.
Reserved Words Page 476 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
Appendix C: Conversion Formatters Conversion Formatters This appendix lists the Conversion Formatters available for the commands DEBUGIN, I2CIN, LCDIN, OWIN and SERIN and demonstrates, through various input/output data examples, exactly what will be received when using these formatters. The following tables show data examples (characters received) across the top and formatters across the left side, with the results of that combination shown in the target cell.
Conversion Formatters Hexadecimal Formatters HEX HEX1 HEX2 HEX3 HEX4 SHEX SHEX1 SHEX2 SHEX3 ⊗ ---------- 1F -1 1F ---1 1F -- 1F⊗ 1F 1 1F 1F 1F 1F 1 1F 1F -1F⊗ 1F 1 1F 1F 1F -1F -1 -1F -1F Characters Received ⊗1F⊗ 15AF⊗ 1F 15AF 1 1 1F 15 1F 15A 1F 15AF 1F 15AF 1 1 1F 15 1F 15A 10000⊗ 0 1 10 100 1000 0 1 10 100 3E517⊗ E517 3 3E 3E5 3E51 -1AE9 3 3E 3E5 Table C.2: Hexadecimal Formatters. NOTE: The HEX formatters are not case sensitive. For example, 1F is the same as 1f.
Appendix C: Conversion Formatters Table C.5: Additional Binary Formatters. Table C.6: NUM and SNUM with Decimal Data.
Conversion Formatters Page 480 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
Appendix D: BASIC Stamp Schematics BASIC Stamp 1 Schematic (Rev B) BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
BASIC Stamp Schematics BASIC Stamp 2 Schematic (Rev G) Page 482 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
Appendix D: BASIC Stamp Schematics BASIC Stamp 2e Schematic (Rev B) BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
BASIC Stamp Schematics BASIC Stamp 2sx Schematic (Rev E) Page 484 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
Appendix D: BASIC Stamp Schematics BASIC Stamp 2p24 Schematic (Rev C) BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
BASIC Stamp Schematics BASIC Stamp 2p40 Schematic (Rev B) Page 486 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
Appendix D: BASIC Stamp Schematics BASIC Stamp 2pe Schematic (Rev B) BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
BASIC Stamp Schematics BASIC Stamp 2px Schematic (Rev A) Page 488 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.
Index — # — #DEFINE, 71 #ERROR, 75 #IF...#THEN, 72 #SELECT...CASE, 74 — $ — $PBASIC Directive, 32, 44–45 Defaults, 44 required with syntax enhancements, 124 Toolbar Icons, 43 $PORT Directive, 45–46, 50 $STAMP Directive, 32, 43–44 Format, 43 Toolbar Icons, 43 with Multi-File Projects, 68 — . — .
Index BASIC Stamp Schematics, 481 BASIC Stamp Windows Editor, 35 Baud Mode (table), 396, 418 Baud Mode, Choosing, 397, 419 BELL, 168 BIN, 162, 163, 173, 220, 227, 260, 265, 298, 306, 403, 422 Binary Coded Decimal, 97 Binary Notation, 96 Binary Operators, 104, 109–21 Add (+), 109 AND (&), 109, 118 AND NOT (&/), 109, 120 Arctangent (ATN), 109, 114 Digit (DIG), 109, 117 Divide (/), 109, 113 Hypotenuse (HYP), 109, 115 Maximum (MAX), 109, 116 Minimum (MIN), 109, 115 Modulus (//), 109, 113 Multiply (*), 109, 110
Index #SELECT...
Index Defining Constants, 94–96 Defining Symbols, 85–91 Delaying Execution, 311 Developer Features, 75 DIG, 109, 117 Digit (DIG), 109, 117 Digital I/O, 129, 137, 143, 149, 215, 217, 225, 243, 247, 249, 257, 263, 281, 283, 293, 295, 303, 313, 325, 377, 393, 415, 431, 435, 455, 465 DIM, 467, See XOUT Direction (setting of I/O pins), 81, 83, 243, 293, 377 Directives.
Index — F — Favorite Directories, 63 Features for Developers, 75 File Associations, 42, 61 File List, 40, 41 File Management .
Index Accessing, 81, 83, 84 Auxiliary, 129, 247 Default State, 83 Default State (BS1), 82 Defining with PIN, 99 Directions, 81, 83, 243, 293, 377 Main, 247, 283 PIN Directive, 99–102 Pinouts BS1, 12 BS2, 14 BS2e, 15 BS2p, 20 BS2pe, 21 BS2px, 23 BS2sx, 18 Reading, 84 Reading (BS1), 81 Source/Sink BS1, 12 BS2, 14 BS2e, 15 BS2p, 20 BS2pe, 21 BS2px, 23 BS2sx, 18 Writing (BS1), 81 2 I C Protocol, 217–23, 225–30 I2CIN, 217–23 I2COUT, 225–30 IBIN, 163, 173, 220, 227, 260, 265, 298, 306, 403, 422 Identification Fun
Index Logic Level, TTL and CMOS (diagram), 144 Logic Operators AND, 235 NOT, 235 OR, 235 XOR, 235 Logic Threshold and BS2px, 143 CMOS, 144 TTL, 144 Logic Truth Tables, 235 LOOKDOWN, 133, 271–76 LOOKUP, 271, 277–80 LOOP. See DO...
Index OEMBS2sx, 17 ON, 289–90, 375, 387 Open Baud Modes, 425 Open From, 41 Open With, 62 Operation, General Theory, 7 Operators Binary, 104, 109–21 Comaprison (SELECT...CASE), 388 Comparison (IF...
Index BS2e, 15 BS2p, 20 BS2pe, 21 BS2px, 23 BS2sx, 18 Powerline Interface, 466 Program Debugging. See DEBUG, DEBUGIN Program Slot, 68, 93, 203, 316, 320, 331, 351, 372, 381, 449, 459 Programming Connections, 27 Programming Environment, 35 Projects.
Index — S — Save To, 41 SBIN, 163, 173, 220, 227, 260, 265, 298, 306, 403, 422 Schematic BS1, 481 BS2, 482 BS2e, 483 BS2p24, 485 BS2p40, 486 BS2pe, 487 BS2px, 488 BS2sx, 484 Schmitt Trigger, 143, 145, 150 (diagram), 145 Scratch Pad Ram Registers, 93 Scratch Pad RAM, 92, 203, 351–52 Registers, 205 Special Purpose Locations (POLLMODE), 323 SDEC, 163, 173, 220, 227, 260, 265, 298, 306, 403, 422 SELECT...
Index &, 118 &/, 120 *, 110 *, 109 **, 109, 111 */, 109, 112 /, 109, 113 //, 109, 113 ?, 163, 165, 228, 305, 422 @, 154, 161 ^, 119 ^/, 121 |, 118 |/, 120 ~, 105, 106 +, 96, 109 <, 232 <<, 117 <=, 232 <>, 232 =, 232 >, 232 >=, 232 >>, 117 SYNCHRONOUS SERIAL, 431–34, 435– 40, See also SHIFTIN, SHIFTOUT< I2CIN, I2COUT Syntax Conventions, 128 Syntax Enhancements for PBASIC 2.
Index and Identify Function, 48 — V — Variable Resistance, Measuring, 339– 40, 363–68 Variables Aliases, 89–91 Arrays, 87–89 Defining, 85–91, 269 Fixed, 84 Modifiers, 89–91 Sizes, 86 VDD, 12, 14, 15, 18, 20, 21, 23 Versions, 3 VIN, 12, 14, 15, 18, 20, 21, 23 Voltage comparison function, of BS2px, 141 VSS, 12, 14, 15, 18, 20, 21, 23 — W — W0-W6, 82 WAIT, 172, 259, 401, 404 WAITSTR, 172, 219, 259, 297, 404, 406 Warranty, 2 WHILE. See DO...