1 / 30

Software and documentation

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

lali
Télécharger la présentation

Software and documentation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. OEM module Reset Input (RES) 5.5 – 15V input (Vin) Ground- 0V (Vss) Regulated 5V output (Vdd) • 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. 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 metal strips are laid out as shown in orange. The long top and bottom row of holes are usually used for power supply connections. The bread board has many strips of metal (copper usually) which run underneath the board. 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 9 V battery LED

  5. OEM BASIC Stamp 2sx 220 Ohm

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

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

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

  9. Example 01a Red LED File: “Example-01a.bsx” ' 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

  10. Example 01b Red LED File: “Example-01b.bsx” ' 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

  11. Example 01c File: “Example-01c.bsx” Red LED ' 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

  12. Example 02a File: “Example-02a.bsx” Red LED and pushbutton ' 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 Run program. Press the pushbutton. What do you see on the screen? Release the pushbutton. What do you see on the screen?

  13. Example 02b File: “Example-02b.bsx” Red LED and pushbutton ' 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

  14. Example 03 File: “Example-03.bsx” Input from the PC • ' 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

  15. Example 04 3 LEDs File: “Example-04.bsx” ' 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

  16. Example 05a Buzzer File: “Example-05a.bsx” ' 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 Run the program. What do you hear?

  17. Example 05b Buzzer: SOS File: “Example-05b.bsx” ' 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

  18. Example 05c 3 LEDs and buzzer File: “Example-05c.bsx” ' 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

  19. Format of variables • Bit 0 or 1 • Nibble (Nib) 0-15 • Byte 0-255 • Word 0-65535 or -32768 to + 32767 Example of variables: 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.

  20. Example 06 Performing calculations File: “Example-06.bsx” ' {$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 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. Flow Chart Start MeasureTemperature Temp.< 100 Yes EnergizeHeater No Temp.> 102 Yes EnergizeFan No 22

  23. Sequential Flow Example Start Turn OFF LED1 Turn OFF LED2 2 Second Pause Turn ON LED1 2 Second Pause Turn ON LED2 End 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: Code: ' <<<< INSERT COMMON ' 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 23

  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. Looping Flow Example Start Turn OFF LED1 Turn OFF LED2 2 Second Pause Turn ON LED1 2 Second Pause Turn ON LED2 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 Flowchart: Code: ' <<<< INSERT COMMON ' 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 25

  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.IFconditionTHENaddressLabel • 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 = value2value1 > value2value1 < value2IN8 = 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. “IF-THEN” Example: Alarm Main Button 1Pressed False True Speaker2000Hz for1 second Main This program will sound the alarm as long as pushbutton 1 is pressed. Pseudo-Code • Start: • Is button 1 pressed? • Yes, Go sound Alarm • No, Go back to start • Alarm: • Sound speaker • Go back to start of program Program Code ' <<<< INSERT SECTION 5 COMMON ' 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 Flowchart 28

  29. Example 07 IF…THEN…ELSE File: “Example-07.bsx” ' 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

  30. Example PIR PIR - sensor File: “Example-PIR.bsx” ' 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

More Related