90005 Parallax Inc, 90005 Datasheet - Page 15

KIT BASIC STAMP ACTIVITY

90005

Manufacturer Part Number
90005
Description
KIT BASIC STAMP ACTIVITY
Manufacturer
Parallax Inc
Series
BASIC Stamp®r
Type
MCUr
Datasheet

Specifications of 90005

Contents
Board, cable, components, manual and software
Interface Type
RS-232
Lead Free Status / RoHS Status
Contains lead / RoHS non-compliant
For Use With/related Products
BASIC Stamp® 2 and Board of Education
For Use With
900-00014 - SERVO CONTROLLER PICO GWS28824 - SERVOPAL SERVO PULSER TIMER130-28029 - KIT PARTS SMART SENSORS28029PAR - KIT PARTS SMART SENSORS W/TEXT28030 - ADAPTER USB TO SERIAL RS23290005 - KIT BASIC STAMP ACTIVITY805-00006 - CABLE USB A TO MINI B28325 - EXPANDER DB-TO-SIP BASIC STAMP27937 - MEMORY STICK DATALOGGER658-1021-5 - PROGRAMMER TEACLIPPER/STAMP30010 - BASIC STAMP LOGIC ANALYZER28119 - KIT UNDERSTANDING SIGNALS28022 - KIT DS2760 THERMOCOUPLE28128 - KIT BASIC ANALOG/DIGI PARTS ONLY27963 - SOLUTIONS CUBED: MEMKEY27964 - UNIPOLAR STEPPER MOTOR 12VDC27220 - BOOK STAMPWORKS27938 - MOTOR CONTROLLER LITTLE STEP-U27330 - PROGRAMMER STACHE BASIC STAMP27218 - MANUAL BASIC STAMP VER 2.0
Lead Free Status / RoHS Status
Lead free / RoHS Compliant, Contains lead / RoHS non-compliant
Next, we make the LED control pin go to zero volts with
current can flow and it turns off. Again, we use
Finally, we start the process over by jumping to the line labeled
Download and run the program – you should see the LED blink happily on and off. If you don't, double-check
your connections; especially the orientation of the LED. If it doesn't blink you may have it in backward.
Now, as exciting as that was, we can do more and write "better" code. Better code is code that not only works,
but is easy for us and others to understand. Let's improve our little program just a bit. Take a look at Listing 1b.
' {$STAMP BS2}
' Program: LED Blink.BS2 (Version B)
' Purpose: Blinks an LED connected to the BASIC Stamp
' ---------------------------------------------------------------
LedPin
' ---------------------------------------------------------------
Start:
In this version we introduce constant (
that doesn't change. There a couple of good reasons for using constants in our program:
Okay, so I'll bet you're wondering just how constants work.. They're actually used by the editor when the program
is being compiled to run on the BASIC Stamp. At the beginning of the compilation process the editor will replace
all the appearances of a constant name with its defined value. In our program,
HIGH 15
process used by the compiler – our source code listing will not be changed.
Give it a try. You'll see that the program runs exactly the same as it did the first time. This time, though, our listing
makes a bit more sense. Ready for more?
One of the things that makes
right, two. You see, to control a Stamp output pin we have to deal with two internal registers. The first is called
Dirs
start-up), the associated I/O pin will be an input. When we make a
output.
The other register that we need to concern ourselves with is called
case, the bits in
Parallax, Inc. • BASIC Stamp HomeWork Board ver 1.1
HIGH LedPin
PAUSE 500
LOW LedPin
PAUSE 500
GOTO Start
. The
1. If we need to change the pin that controls the LED, we only have to change one place in the program.
2. By using a constant, we now have more of an idea of what is being controlled.
and the program will work just as in our first version. And don't worry, this replacement is an internal
Using constants prevents program errors by not catching all the changes required when circuit
connections
controlling anything; a light, a bell, a heater. We're forced to explain the process of our program in
comments. By using the constant name
and we can spend less energy explaining with comments.
Dirs
CON
register is 16 bits wide; one bit for each I/O pin. When a bit in the
Outs
15
are connected to the I/O pins when the associated
' do it again
' turn LED on
' wait one-half second
' wait one-half second
' turn LED off
' LED control pin
HIGH
and
CON
LOW
) values. Constants give us a way to assign a useful name to a value
easy is that each command actually does two operations – that's
PAUSE
LedPin
to create a delay so that we can actually see that it is off.
LOW
, others reading our code know what is being controlled
. With zero volts on both sides of the LED, no
are
Start
Outs
Dirs
with the
bit a one, the associated I/O pin will be an
. Like
Dirs
bits are set to one. When a bit in
GOTO
Dirs
HIGH LedPin
Dirs
,
Outs
command.
register is zero (default at
is 16 bits wide. In this
will be replaced with
HIGH 15
modified.
could be
Page 15

Related parts for 90005