180 likes | 357 Views
BASIC Stamp Editor. Once installed, the Stamp Editor will be available on your desktop, and as a menu option under Start Program Files Parallax Inc. Identifying the BASIC Stamp. Writing the Program. DEBUG “Hello World”. ‘{$STAMP BS2} DEBUG “Hello World”. Downloading or Running Code.
E N D
BASIC Stamp Editor • Once installed, the Stamp Editor will be available on your desktop, and as a menu option underStart Program Files Parallax Inc
Writing the Program DEBUG “Hello World”
‘{$STAMP BS2} DEBUG “Hello World” Downloading or Running Code • Once a program is entered, the Run button (or Ctrl-R) is used to tokenize and download the program to the BASIC Stamp. • The Editor will request you indicate the style of BASIC Stamp you are using. DEBUG “Hello World” • The style may be selected from the menu, or by selecting your ‘color’ of your BASIC Stamp on the button bar. • A directive will be added to the top of your code.
Tokenizing and Errors • When a program is ‘Ran’ the PBASIC code is converted to symbolic format called tokens. These are stored in ROM memory on your BASIC Stamp. • In order to tokenize your program, the code must to conform to the rules of syntax for the language.
Commenting Code • Comments, or remarks, are descriptions or explanations the programmer puts in the code to clarify what it is doing.
DEBUG Window • Programs may contain a DEBUG instruction. This instruction sends serial data back to the computer on the serial cable. • When DEBUG is present in a program, a DEBUG window will open in the Editor to view the returning data. • The DEBUG button may be used to manually open a DEBUG window.
Output - Connecting an LED • Connect an LED to P8 as shown: • In this configuration a LOW, or 0V, at P8 will allow current to flow through the LED to Vdd (+5V) lighting it. When P8 is HIGH (+5V), no current will flow and the LED will not light. The LED is Active Low. Vdd, NOT Vin. Note cathode: the ‘flat side’ of LED Connected on P8. Angle of shot makes it appear to be on P9. 220 ohm = RED RED BROWN GOLD An LED is a diode, meaning electrons can flow in only one direction, so polarity is important. The LED should have a flat side indicating the cathode or negative terminal. Also, the anode (positive terminal) generally has a longer lead than the cathode.
Blinking the LED with HIGH, LOW • Use the Stamp Editor to enter the following program: • Download or run the program. • Monitor the LED. It should blink at a rate of 1 second OFF, 5 seconds ON. If not, check your configuration and code. ‘Prog 4A: Blink LED program Main: HIGH 8 'Turn off LED PAUSE 1000 'Wait 1 second LOW 8 'Turn on LED PAUSE 5000 'Wait 5 seconds GOTO Main 'Jump back to beginning
LED Cycling • Code a program to perform the following sequence (use HIGH and LOW): • LED1 on P8 ON, LED2 on P9 OFF • Wait 2 seconds • LED1 on P8 ON, LED2 on P9 ON • Wait 1 second • Both LEDs OFF • Wait one-half second • Repeat
'** 4B Challenge Solution – Blink both LEDs ** Main: LOW 8 'LED1 HIGH 9 'LED2 PAUSE 2000 'Wait 2 seconds LOW 9 'LED2 ON (P9 LED stays on) PAUSE 1000 'Wait 1 second HIGH 8 'LED1 off HIGH 9 'LED1 off PAUSE 500 'Wait one-half second GOTO Main Did you waste code memory by turning on an already on P8 LED?
Digital Inputs • Just as P0 – P15 on the BASIC Stamp can act as outputs to control devices, they can act as inputs to read devices, such as switches. • By default, the BASIC Stamp I/O pins will act as inputs unless specifically set to be an output. In our code we specify the I/O as inputs out of good programming habits. • INPUT pin • INPUT 10
Connecting an Active-Low Switch The push-buttons used in this tutorial have 4 terminals. 2 are electrically connected on one side of the button, and the other 2 on the other side. By wiring to opposing corners we ensure the proper connection independent of button rotation. 1K = Brown Black Red Gold
Active-High Push-Button Switch The BASIC Stamp has uncommitted inputs. That is, when an I/O pin is not connected and acting as an input, it cannot be assured to be either HIGH or LOW. Pull-up and pull-down resistors are needed to commit the input to the non-active (open) state for switches. The 1K resistor is used to prevent a short-circuit between Vdd and Vss when the switch is closed.
Reading the Switch 'Prog 4E: Display the status of PB1 on P10 INPUT 10 'Set P10 to be an input Main: DEBUG ? IN10 'Display status of P10 PAUSE 500 'Short pause GOTO Main 'Jump back to beginning
Controlling Outputs with Inputs 'Prog 4F: Controlling LED1 with input PB1 INPUT 10 'Set P10 to be an input OUTPUT 8 'Set P8 to be an output Main: OUT8 = IN10 'Set LED1 = PB1 GOTO Main 'Jump back to beginning