The BASIC Stamp Editor Programming Unit, Lecture 2
The BASIC Stamp Editor <ul><li>Parallax, Inc. provides the BASIC Stamp Editor free of charge. </li></ul><ul><ul><li>CD’s containing the software and documentation are available. </li></ul></ul><ul><ul><li>Download from www.parallax.com. </li></ul></ul><ul><li>Versions are available for </li></ul><ul><ul><li>DOS </li></ul></ul><ul><ul><li>Windows </li></ul></ul><ul><ul><li>Linux </li></ul></ul><ul><ul><li>Macintosh </li></ul></ul>
BASIC Stamp Development <ul><li>What you need to design, develop and test BASIC Stamp systems </li></ul><ul><ul><li>BASIC Stamp Editor software </li></ul></ul><ul><ul><li>A suitable host PC </li></ul></ul><ul><ul><ul><li>Almost any PC can run the parallax software </li></ul></ul></ul><ul><ul><ul><li>A serial port is required to download programs to the BASIC Stamp </li></ul></ul></ul><ul><ul><ul><li>For machines without a serial port, a USB-to-Serial Adapter </li></ul></ul></ul><ul><ul><li>BASIC Stamp controller (for example, the BS2P24 module) </li></ul></ul><ul><ul><li>Carrier board for the BASIC Stamp </li></ul></ul><ul><ul><ul><li>Development boards are available from Parallax and other vendors. </li></ul></ul></ul><ul><ul><ul><li>A custom designed carrier/prototyping board such as BalloonSat . </li></ul></ul></ul><ul><ul><li>Programming cable (typically a standard 9-pin straight-thru serial cable. </li></ul></ul>
Installation of BASIC Stamp Software <ul><li>Installation of the BASIC Stamp Editor is straight forward. Follow simple instructions on Parallax website. </li></ul><ul><li>For PC’s not connected to the internet, A CD is available from Parallax, Inc. </li></ul><ul><li>The only difficulties usually encountered involve configuring the PC’s serial port. Make sure there is an available serial port or use a USB-to-Serial adapter. </li></ul>
Running the BASIC Stamp Editor Running the BASIC Stamp Editor should yield a screen like this. The area to the left allows you to explore files on the PC. The large window on the right is where you will enter your BASIC Stamp program for editing, checking and downloading to the BASIC Stamp hardware
Configuring the BASIC Stamp Editor The Editor can be configured but the default settings will usually work fine. Pull down the Editor tab and select Preferences to access the configurable options. The software will usually default to the AUTO option for the COM port, shown at right.
Configuring the COM Port The COM port can be set to any of the PC’s available COM ports. If a COM port does not appear in the list of known ports it is likely assigned to another device or is not configured properly in the PC’s BIOS.
Configuring the Stamp Type Parallax makes a number of different BASIC Stamp micro-controllers. The BASIC Stamp Editor should be configured for the particular type of controller being used, for example a BS2p. Mouse-over the stamp icons chose then click.
Configuring the Stamp Type The Stamp mode can also be set by using the Directive pull-down menu. The $STAMP Directive is automatically inserted in the source file. There is also a $PORT Directive available from the pull-down menu for selecting the COM port.
PBASIC Help Access HELP from the menu bar or press F1 Learn to use the Syntax Guide and PBASIC Command Reference .
Checking and Running a PBASIC Program A PBASIC program can be checked for errors from the Run pull down menu. Select Check Syntax . A BASIC Stamp does not have to be connected. When any syntax errors have been corrected, selecting Run downloads and executes the program on the attached BASIC Stamp hardware.
Number Systems Micro-controllers operate with digital logic that has two states (0V for logic 0 and +5 for logic 1). It is natural then to use a binary number system (base 2) consisting of only two digits, 0 and 1. Binary numbers are represented by collections of bits (binary digits). Leading 0’s can be added without changing the value. 00000101 = 101 or decimal 5
Bits and Bytes The bit is the smallest unit of data. Numerically it can be either 0 or 1 but can represent other useful quantities such as TRUE or FALSE , ON or OFF , RED or GREEN , etc. A byte consists of eight bits and is convenient for representing numerical quantities (0 to 255) or characters. Bit 0 is the least-significant-bit. These are the bit numbers and weighted values:
Other Number Systems <ul><li>Hexadecimal (base 16) numbers are commonly used in the world of micro-controllers. </li></ul><ul><ul><li>Hex numbers are compact: each hex digit represents 4 bits. </li></ul></ul><ul><ul><li>Easy to convert binary to hex and hex to binary . </li></ul></ul>
Other data types - the nibble The nibble is a collection of four bits. It is useful for representing BCD (binary coded decimal) and hexadecimal (base 16) numbers.
Word data type The word is a collection of sixteen bits. The individual bits are numbered from 0 (least significant bit) to 15 (most significant bit) and the bits have weighted values from 2 0 to 2 15 (or 32,768 decimal). A word can also be viewed as two bytes. Bits 0 through 7 form the low order byte , bits 8 through 15 form the high order byte . A word sized number value can represent an unsigned value from 0 to 65535 -or- a signed valued from -32,768 to 32,767
Variables A variable is a memory location for storage and retrieval of a number. In PBASIC a variable has a fixed size depending upon the desired range of values needed for a given application. The BASIC Stamp has limited memory. Use the smallest variable type necessary for the application to conserve memory.
Declaring and Naming Variables In PBASIC a variable is declared by assigning a name for the variable and by defining the type ( size ). For example, for the BS2 a variable declaration might look like ageYrs var byte ageYrs is the name of the variable which might refer to the age of a person in years. The keyword var is used to declare a variable. In this instance the size of the variable is 1 byte which can take on values of 0 to 255 which is a reasonable size and range of values for the intended application (age of a person). The value of a variable can change as the result of program execution.
Constants Constants do not change values. The value is assigned when the program is written but does not change during program execution. Constants are named in a manner similar to variables, for example NumButtons CON 5 A constant named NumButtons is declared by the keyword CON with a value of 5. This constant might hold the number of buttons on a control panel or it could be the number of buttons on a shirt. In any case, we name the constant to reflect its meaning in a program.
Naming Conventions Notice that in the examples for declaring variables and constants we name them using the following convention: Variable names start with a lowercase letter , for example ageYrs . Constant names start with uppercase letters , for example NumButtons. Words within a name are capitalized for improved readability. The PBASIC language does not care about these conventions. They are used only for aiding in the documentation and troubleshooting of programs. Perhaps most importantly, use meaningful names that help to explain program logic and operation.
Activities Students will correct any soldering defects found their Stage 1 BalloonSat boards. The BASIC Stamp Editor will be installed on the lab computer. Students will become familiar with running the software and become proficient in using the PBASIC Help utility. Students will establish a communications link between BalloonSat and the lab computer.