Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

1 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

2 Identifying the BASIC Stamp

3 Writing the Program DEBUG “Hello World”

4 Once a program is entered, the Run button (or Ctrl-R) is used to tokenize and download the program to the BASIC Stamp. Downloading or Running Code  The Editor will request you indicate the style of BASIC Stamp you are using.  The style may be selected from the menu, or by selecting your ‘color’ of your BASIC Stamp on the button bar. DEBUG “Hello World” ‘{$STAMP BS2} DEBUG “Hello World”  A directive will be added to the top of your code.

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

6 Commenting Code Comments, or remarks, are descriptions or explanations the programmer puts in the code to clarify what it is doing.

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

8 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. 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. Connected on P8. Angle of shot makes it appear to be on P9. Vdd, NOT Vin. Note cathode: the ‘flat side’ of LED 220 ohm = RED RED BROWN GOLD

9 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

10 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

11 '** 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?

12 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

13 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

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

15 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

16 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

17 กด Switch แล้ววิ่งไปกลับ

18 7 segment


Download ppt "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."

Similar presentations


Ads by Google