Introduction to Programming - Louisiana Space Consortium

Download Report

Transcript Introduction to Programming - Louisiana Space Consortium

The BASIC Stamp Editor
Programming Unit, Lecture 2
LSU 2004
BASIC Stamp Editor
1
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 2004
BASIC Stamp Editor
2
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 2004
BASIC Stamp Editor
3
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 2004
BASIC Stamp Editor
4
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
LSU 2004
BASIC Stamp Editor
5
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 2004
BASIC Stamp Editor
6
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 2004
BASIC Stamp Editor
7
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 2004
BASIC Stamp Editor
8
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 2004
BASIC Stamp Editor
9
PBASIC Help
Access HELP
from the menu
bar or press
F1
Learn to use
the Syntax
Guide and
PBASIC
Command
Reference.
LSU 2004
BASIC Stamp Editor
10
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.
LSU 2004
BASIC Stamp Editor
11
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
LSU 2004
BASIC Stamp Editor
Binary Decimal
0
0
1
1
10
2
11
3
100
4
101
5
110
6
111
7
1000
8
1001
9
12
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 leastsignificant-bit. These are the bit numbers and weighted values:
Bit Number:
7
6
5
Power of 2:
27 26 25
Decimal Value: 128 64 32
LSU 2004
4
3
2
1
0
24
16
23
8
22
4
21
2
20
1
BASIC Stamp Editor
13
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.
LSU 2004
BASIC Stamp Editor
Binary Decimal Hex
0
0
1
1
10
2
11
3
100
4
101
5
110
6
111
7
1000
8
1001
9
1010
10
1011
11
1100
12
1101
13
1110
14
1111
15
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
14
Other data types - the nibble
Bit Number:
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
Power of 2:
23
Decimal Value: 8
LSU 2004
2
1
0
22
4
21
2
20
1
BASIC Stamp Editor
3
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
2
0
0
0
0
1
1
1
1
0
0
0
0
1
1
1
1
1
0
0
1
1
0
0
1
1
0
0
1
1
0
0
1
1
0
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
BCD
0
1
2
3
4
5
6
7
8
9
Hex
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
15
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 represent
an unsigned value from 0 to 65535 -ora signed valued from -32,768 to 32,767
LSU 2004
BASIC Stamp Editor
16
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.
Type
Size
Range of Values
Bit
Nibble
Byte
Word
1 bit
4 bits
8 bits
16 bits
0 or 1
0 to 15
0 to 255
0 to 65,535
The BASIC Stamp has limited memory. Use the smallest variable
type necessary for the application to conserve memory.
LSU 2004
BASIC Stamp Editor
17
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.
LSU 2004
BASIC Stamp Editor
18
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.
LSU 2004
BASIC Stamp Editor
19
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.
LSU 2004
BASIC Stamp Editor
20
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.
LSU 2004
BASIC Stamp Editor
21