lsu 06/04/2007basic stamp editor1 the basic stamp editor programming unit, lecture 3

21
LSU 06/04/2007 BASIC Stamp Editor 1 The BASIC Stamp Editor Programming Unit, Lecture 3

Upload: mark-simmons

Post on 23-Dec-2015

219 views

Category:

Documents


1 download

TRANSCRIPT

LSU 06/04/2007 BASIC Stamp Editor 1

The BASIC Stamp Editor

Programming Unit, Lecture 3

LSU 06/04/2007 BASIC Stamp Editor 2

The BASIC Stamp Editor•Parallax, Inc. provides the BASIC Stamp Editor free of charge.

–CD’s containing the software and documentation are available.

–Download from www.parallax.com.

•Versions are available for–DOS

–Windows

–Linux

–Macintosh

LSU 06/04/2007 BASIC Stamp Editor 3

BASIC Stamp Development•What you need to design, develop and test BASIC Stamp systems

–BASIC Stamp Editor software

–A suitable host PC•Almost any PC can run the parallax software

•A serial port is required to download programs to the BASIC Stamp

•For machines without a serial port, a USB-to-Serial Adapter

–BASIC Stamp controller (for example, the BS2P24 module)

–Carrier board for the BASIC Stamp•Development boards are available from Parallax and other vendors.

•A custom designed carrier/prototyping board such as BalloonSat.

–Programming cable (typically a standard 9-pin straight-thru serial cable.

LSU 06/04/2007 BASIC Stamp Editor 4

Installation of BASIC Stamp Software

•Installation of the BASIC Stamp Editor is straight forward. Follow simple instructions on Parallax website.

•For PC’s not connected to the internet, A CD is available from Parallax, Inc.

•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.

LSU 06/04/2007 BASIC Stamp Editor 5

Running the BASIC Stamp EditorRunning 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

LSU 06/04/2007 BASIC Stamp Editor 6

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.

LSU 06/04/2007 BASIC Stamp Editor 7

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.

LSU 06/04/2007 BASIC Stamp Editor 8

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.

LSU 06/04/2007 BASIC Stamp Editor 9

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.

LSU 06/04/2007 BASIC Stamp Editor 10

PBASIC Help

Access HELP from the menu bar or press F1

Learn to use the Syntax Guide and PBASIC Command Reference.

LSU 06/04/2007 BASIC Stamp Editor 11

Checking and Running a PBASIC ProgramA 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.

LSU 06/04/2007 BASIC Stamp Editor 12

Number SystemsMicro-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

Binary Decimal0 01 1

10 211 3

100 4101 5110 6111 7

1000 81001 9

LSU 06/04/2007 BASIC Stamp Editor 13

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: Bit Number: 7 6 5 4 3 2 1 0

Power of 2: 27 26 25 24 23 22 21 20

Decimal Value: 128 64 32 16 8 4 2 1

LSU 06/04/2007 BASIC Stamp Editor 14

Other Number Systems•Hexadecimal (base 16) numbers are commonly used in the world of micro-controllers.

–Hex numbers are compact: each hex digit represents 4 bits.

–Easy to convert binary to hex and hex to binary.

Binary Decimal Hex0 0 01 1 1

10 2 211 3 3

100 4 4101 5 5110 6 6111 7 7

1000 8 81001 9 91010 10 A1011 11 B1100 12 C1101 13 D1110 14 E1111 15 F

LSU 06/04/2007 BASIC Stamp Editor 15

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.

Bit Number: 3 2 1 0

Power of 2: 23 22 21 20

Decimal Value: 8 4 2 1

Bit Number: 3 2 1 0BCD Hex

0 0 0 0 0 00 0 0 1 1 10 0 1 0 2 20 0 1 1 3 30 1 0 0 4 40 1 0 1 5 50 1 1 0 6 60 1 1 1 7 71 0 0 0 8 81 0 0 1 9 91 0 1 0 A1 0 1 1 B1 1 0 0 C1 1 0 1 D1 1 1 0 E1 1 1 1 F

LSU 06/04/2007 BASIC Stamp Editor 16

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 20 to 215 (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 representan unsigned value from 0 to 65535 -or- a signed valued from -32,768 to 32,767

LSU 06/04/2007 BASIC Stamp Editor 17

VariablesA 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.

Type Size Range of Values

Bit 1 bit 0 or 1Nibble 4 bits 0 to 15Byte 8 bits 0 to 255Word 16 bits 0 to 65,535

The BASIC Stamp has limited memory. Use the smallest variable type necessary for the application to conserve memory.

LSU 06/04/2007 BASIC Stamp Editor 18

Declaring and Naming VariablesIn 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.

LSU 06/04/2007 BASIC Stamp Editor 19

ConstantsConstants 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.

LSU 06/04/2007 BASIC Stamp Editor 20

Naming ConventionsNotice 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.

LSU 06/04/2007 BASIC Stamp Editor 21

ActivitiesStudents 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.