Presentation is loading. Please wait.

Presentation is loading. Please wait.

Software and documentation Download and install: “Setup-Stamp-Editor-Lrg-v2.2.6.exe” www.parallax.com  Downloads  BASIC Stamp software BASIC Stamp Syntax.

Similar presentations


Presentation on theme: "Software and documentation Download and install: “Setup-Stamp-Editor-Lrg-v2.2.6.exe” www.parallax.com  Downloads  BASIC Stamp software BASIC Stamp Syntax."— Presentation transcript:

1 Software and documentation Download and install: “Setup-Stamp-Editor-Lrg-v2.2.6.exe” www.parallax.com  Downloads  BASIC Stamp software BASIC Stamp Syntax and Reference Manual Version 2.2 (5.3 MB) Software for Windows: BASIC Stamp Windows Editor version 2.2.6 (~6.0 MB). Windows NT4/2K/XP. With BS1 Support! www.parallax.com  Downloads  Documentation

2 OEM module  The BASIC Stamp 2 OEM is a discreet component version of the BS2 which may be purchased in kit form.  The male header provides the means to ‘plug-it’ into your own board, or connect to other boards. Regulated 5V output (Vdd) Ground- 0V (Vss) 5.5 – 15V input (Vin) Reset Input (RES) P0-P15 I/O Power the board with EITHER: A) 5.5-15VDC on Vin. This will also provide 5 VDC regulated output on Vdd. B) Regulated 5V Input on Vdd.

3 Using the breadboard (Socket board) The bread board has many strips of metal (copper usually) which run underneath the board. The metal strips are laid out as shown in orange. The long top and bottom row of holes are usually used for power supply connections. To use the bread board, the legs of components are placed in the holes (the sockets). The holes are made so that they will hold the component in place. The circuit is built by placing components and connecting them together with jumper wires.

4 Connection 220 Ohm resistor should be connected to pin P4 of the OEM Basic Stamp 2sx. “+” (long) lead of LED should be connected to opposite side of the resistor. The other (short) lead of the LED goes to “-” 220 Ohm LED 9 V battery

5 220 Ohm OEM BASIC Stamp 2sx

6 Wiring diagram Note: - is connection to negative pole of the battery 220 Ohm Push button Buzzer LED OUT PIR Motion sensor 9 V battery COM port Microcontroller chip 15 KOhm

7 BASIC Stamp software Stamp Mode: BS2sx “Run” Your saved program files “Identify” Finds COM port with BASIC Stamp connected

8 ' My first program ' {$STAMP BS2sx} ' {$PBASIC 2.5} DEBUG "Hello, is anybody home?" END Example 0 Your first program: Run this program when your BS2sx microcontroller is powered and connected to the computer via COM port. What do you see on the screen? File: “Example-00.bsx”

9 ' Example 01a ' {$STAMP BS2sx} ' {$PBASIC 2.5} Red:'Lable LOW 4'Makes pin 4 to have low voltage PAUSE 1000'Pause 1 second HIGH 4'Makes pin 4 to have high voltage PAUSE 50'Pause 0.05 sec GOTO Red'Makes program to go back to “Red” lable END Example 01a File: “ Example-01a.bsx” Red LED

10 ' Example 01b ' {$STAMP BS2sx} ' {$PBASIC 2.5} DO LOW 4 'Makes pin 4 to have low voltage PAUSE 1000 'Pause 1 second HIGH 4 'Makes pin 4 to have high voltage PAUSE 50 'Pause 0.05 sec LOOP END Example 01b File: “ Example-01b.bsx” Red LED

11 ' Example 01c ' {$STAMP BS2sx} ' {$PBASIC 2.5} RedLED PIN 4' red LED is connected to pin 4 IsOn CON 1' IsOn = 1(constant) LED is active high IsOff CON 0' IsOff = 0(constant) LED is active low Setup: OUTPUT RedLED' sets OUTPUT to be pin 4 Main: DO RedLED = IsOn' same as HIGH 4 PAUSE 1000' pause 1 s = 1000 ms RedLED = IsOff' same as LOW 4 PAUSE 1000' pause 1 s = 1000 ms LOOP END Example 01c File: “ Example-01c.bsx” Red LED

12 ' Example 02a ' {$STAMP BS2sx} ' {$PBASIC 2.5} Green:' label “green” DEBUG ? IN0, CR' sends information to the PC ' about the status of input pin 0 PAUSE 1000' pause 1 s = 1000 ms GOTO Green' return to label “green” END Example 02a File: “ Example-02a.bsx” Run program. Press the pushbutton. What do you see on the screen? Release the pushbutton. What do you see on the screen? Red LED and pushbutton

13 ' Example 02b ' {$STAMP BS2sx} ' {$PBASIC 2.5} DO DEBUG ? IN0' sends information to the PC ' about the status of input pin 0 IF (IN0 = 1) THEN HIGH 4 PAUSE 50 LOW 4 PAUSE 50 ELSE PAUSE 100 ENDIF LOOP Example 02b File: “ Example-02b.bsx” Red LED and pushbutton

14 ' Example 03 ' {$STAMP BS2sx} ' {$PBASIC 2.5} myNumber VAR Nib DO DEBUG CR, "Enter a number (from 1 to 5)? --> " DEBUGIN DEC1 myNumber IF ((myNumber >= 1) AND (myNumber <= 5)) THEN DEBUG CR, " -- You entered: ", DEC1 myNumber ELSE DEBUG CR, " -- Sorry, your number is out of range" ENDIF LOOP END Example 03 File: “ Example-03.bsx” Input from the PC

15 ' Example 04 ' {$STAMP BS2sx} ' {$PBASIC 2.5} RedLED PIN 4 ' red LED is connected to pin 4 YellowLED PIN 13 ' Yellow LED is connected to pin 13 GreenLED PIN 15 ' Green LED is connected to pin 15 IsOn CON 1 ' IsOn = 1(constant) LED is active high IsOff CON 0 ' IsOff = 0(constant) LED is active low Setup: OUTPUT RedLED ' sets OUTPUT to be pin 4 OUTPUT YellowLED OUTPUT GreenLED Main: DO RedLED = IsOn PAUSE 100 RedLED = IsOff PAUSE 10 YellowLED = IsOn PAUSE 100 YellowLED = IsOff PAUSE 10 GreenLED = IsOn PAUSE 100 GreenLED = IsOff PAUSE 500 LOOP END Example 04 File: “ Example-04.bsx” 3 LEDs

16 ' Example 05a ' {$STAMP BS2sx} ' {$PBASIC 2.5} FREQOUT 1,3000,1900 PAUSE 1000 FREQOUT 1,3000,1900,2533 PAUSE 1000 FREQOUT 1,3000,1900,1903 END Example 05a File: “ Example-05a.bsx” Buzzer Run the program. What do you hear?

17 ' Example 05b ' {$STAMP BS2sx} ' {$PBASIC 2.5} Dit CON 90 ' Short span of time in milliseconds. Dah CON 3*Dit ' Longer time, 3 times the above. index VAR Nib ' Index. sos VAR Nib FOR sos=1 TO 3 FOR index=1 TO 3 ' Send 5 sounds. FREQOUT 1, Dit, 1900 ' Send a dit. PAUSE Dit ' Short silence. NEXT PAUSE Dah ' Longer silence between digits. FOR index=1 TO 3 ' Send 5 sounds. FREQOUT 1, Dah, 1900 ' Send a Dah. PAUSE Dah ' Short silence. NEXT FOR index=1 TO 3 ' Send 5 sounds. FREQOUT 1, Dit, 1900 ' Send a dit. PAUSE Dit ' Short silence. NEXT PAUSE Dah*3 NEXT END Example 05b File: “ Example-05b.bsx” Buzzer: SOS

18 ' Example 04 ' {$STAMP BS2sx} ' {$PBASIC 2.5} RedLED PIN 4 ' red LED is connected to pin 4 YellowLED PIN 13 ' Yellow LED is connected to pin 13 GreenLED PIN 15 ' Green LED is connected to pin 15 IsOn CON 1 ' IsOn = 1(constant) LED is active high IsOff CON 0 ' IsOff = 0(constant) LED is active low Setup: OUTPUT RedLED ' sets OUTPUT to be pin 4 OUTPUT YellowLED OUTPUT GreenLED Main: DO RedLED = IsOn PAUSE 100 RedLED = IsOff PAUSE 10 YellowLED = IsOn PAUSE 100 YellowLED = IsOff PAUSE 10 GreenLED = IsOn PAUSE 100 GreenLED = IsOff PAUSE 500 LOOP END Example 05c File: “ Example-05c.bsx” 3 LEDs and buzzer

19 Format of variables 1.Bit 0 or 1 2.Nibble (Nib)0-15 3.Byte0-255 4.Word0-65535 or -32768 to + 32767 MouseVARBIT' Value can be 0 or 1. CatVARNIB' Value can be 0 to 15. DogVARBYTE' Value can be 0 to 255. RhinoVARWORD' Value can be 0 to 65535. Example of variables:

20 ' {$STAMP BS2sx} ' {$PBASIC 2.5} TOTAL VAR Byte X CON 20 TOTAL = 0 TOTAL = TOTAL +100 DEBUG ? TOTAL TOTAL= TOTAL/3 DEBUG ? TOTAL DEBUG ? X END Example 06 Performing calculations File: “ Example-06.bsx” Run the program. What do you see?

21 Pseudo Code Start of program Measure temperature -Is temperature < 100 F ? Yes, Turn on heat -Is temperature > 102 F ? Yes, Turn on cooling fan Go back to start.

22 22 Start Measure Temperature Temp. < 100 Energize Heater Temp. > 102 Energize Fan Yes No Yes No Flow Chart

23 23 Sequential Flow Example Pseudo-Code: Start of program  Turn off LED 1  Turn off LED 2  Pause for 2 seconds  Light LED 1  Pause for 2 seconds  Light LED 2  End of program Flowchart: ' <<<< INSERT COMMON ' CIRCUIT DECLARATIONS >>>>CIRCUIT DECLARATIONS 'Prog 6A: Example of sequential flow ' ****** Main program ******** LED1 = LED_Off'Turn off LED 1 LED2 = LED_Off'Turn off LED 2 PAUSE 2000'Pause for 2 sec. LED1 = LED_On'Light LED 1 PAUSE 2000'Pause for 2 sec. LED2 = LED_On'Light LED 2 END Code: Start Turn OFF LED1 Turn OFF LED2 2 Second Pause Turn ON LED1 Turn ON LED2 2 Second Pause End

24 Branching Overview “GOTO” Branching is the act of breaking out of a sequence to perform code in another location of the program. The simplest form of branching is to use the GOTO instruction: GOTO label

25 25 Looping Flow Example Pseudo-Code: Start of program  Turn off LED 1  Turn off LED 2  Pause for 2 seconds  Light LED 1  Pause for 2 seconds  Light LED 2  Go back to start ' <<<< INSERT COMMON ' CIRCUIT DECLARATIONS >>>>CIRCUIT DECLARATIONS 'Prog 6B: Example of sequential ' flow with looping ' ****** Main program ********** Main: LED1 = LED_Off 'Turn off LED 1 LED2 = LED_Off 'Turn off LED 2 PAUSE 2000 'Pause for 2 sec. LED1 = LED_On 'Light LED 1 PAUSE 2000 'Pause for 2 sec. LED2 = LED_On 'Light LED 2 GOTO Main'Repeat sequence Code: : Flowchart : Start Turn OFF LED1 Turn OFF LED2 2 Second Pause Turn ON LED1 Turn ON LED2 2 Second Pause

26 Conditionals Overview The previous example is an unconditional branch; the program will branch back to Main regardless of any code parameters. In a conditional branch a decision is made based on a current condition to branch or not to branch. As humans, we constantly make decisions based on input as to what to perform. Shower too cold? Turn up the hot. Shower too hot? Turn down the hot water. Microcontrollers can be programmed to act based on condition.

27 “IF…THEN” The “IF-THEN” is the primary means of conditional branching. IF condition THEN addressLabel If the condition is evaluated to be true, execution will branch to the named address label. If the condition is not true, execution will continue to the next step in the program sequence. A condition is typically an equality: value1 = value2 value1 > value2 value1 < value2 IN8 = 1 Note: Compared to many versions of BASIC and other languages, the PBASIC 2.0 implementation of the IF-THEN is fairly limited. See the PBASIC 2.5 appendix for new implementations of IF-THEN.

28 28 “IF-THEN” Example: Alarm This program will sound the alarm as long as pushbutton 1 is pressed. Start: Is button 1 pressed? Yes, Go sound Alarm No, Go back to start Alarm: Sound speaker Go back to start of program ' <<<< INSERT SECTION 5 COMMON ' CIRCUIT DECLARATIONS >>>> CIRCUIT DECLARATIONS 'Prog 6C: Conditional Branching Alarm Main: ' If pushbutton 1 is pressed, ' then go sound alarm IF PB1 = PB_On THEN Alarm GOTO Main Alarm: 'Sound the alarm FREQOUT Speaker, 1000, 2000 GOTO Main Pseudo-Code Flowchart Program Code Button 1 Pressed Main Speaker 2000Hz for 1 second Main TrueFalse

29 ' Example 07 ' {$STAMP BS2sx} ' {$PBASIC 2.5} RedLED PIN 4 ' red LED is connected to pin 4 YellowLED PIN 13 ' yellow LED is connected to pin 13 PushButton PIN 0 ' push button is connected to pin 0 IsOn CON 1 ' IsOn = 1(constant) LED is active high IsOff CON 0 ' IsOff = 0(constant) LED is active low X VAR Bit Setup: OUTPUT RedLED ' sets OUTPUT to be pin 4 OUTPUT YellowLED ' sets OUTPUT to be pin 4 MainA: ' label “MainA” RedLED = IsOff YellowLED = IsOn X = IN0 IF X = 0 THEN MainA MainB: ' label “MainB” YellowLED = IsOff RedLED = IsOn X = IN0 IF X = 0 THEN GOTO MainA ELSE GOTO MainB END Example 07 IF…THEN…ELSE File: “ Example-07.bsx”

30 ' File: Example-PIR.bsx ' {$STAMP BS2sx} ' {$PBASIC 2.5} ' -----[ I/O Definitions ]------------------------------------------------- PIR PIN 7 ' I/O Pin For PIR Sensor RED PIN 4 ' I/O Pin For RED LED GREEN PIN 15 ' I/O Pin For GREEN LED YELLOW PIN 13 ' I/O Pin For YELLOW LED ' -----[ Variables ]------------------------------------------------------- counter VAR Byte ' Trip Counter ' -----[ Initialization ]-------------------------------------------------- DEBUG CLS ' Clear DEBUG Screen LOW RED LOW GREEN HIGH YELLOW FOR counter = 20 TO 0 ' Wait 40 Seconds For PIR Warm-Up DEBUG HOME, "WARMING UP:", DEC2 counter PAUSE 1000 ' Display Counter Every Second NEXT LOW YELLOW counter = 0 ' Clear Counter Variable DEBUG HOME, "WAITING... " ' Display Waiting Message ' -----[ Program Code ]---------------------------------------------------- Main: HIGH GREEN DO IF PIR = 1 THEN ' Motion Detected? counter = counter + 1 ' Update Trip Counter LOW GREEN HIGH RED ' Light LED DEBUG HOME, "TRIPPED...", DEC3 counter DO : LOOP UNTIL PIR = 0 ' Wait For PIR To Clear DEBUG HOME, "CLEARED...", DEC3 counter LOW RED ' Turn Off LED HIGH GREEN ENDIF LOOP Example PIR PIR - sensor File: “ Example-PIR.bsx”


Download ppt "Software and documentation Download and install: “Setup-Stamp-Editor-Lrg-v2.2.6.exe” www.parallax.com  Downloads  BASIC Stamp software BASIC Stamp Syntax."

Similar presentations


Ads by Google