software and documentation

30
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

Upload: lali

Post on 05-Feb-2016

62 views

Category:

Documents


2 download

DESCRIPTION

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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Software and documentation

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

Page 2: Software and documentation

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.

Page 3: Software and documentation

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.

Page 4: Software and documentation

Connection220 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

Page 5: Software and documentation

22

0 O

hm

OEM BASIC Stamp 2sx

Page 6: Software and documentation

OEM BASIC Stamp 2sx

Wiring diagram

Note:

- is connection to negative pole of the battery

22

0 O

hm

22

0 O

hm

22

0 O

hm

22

0 O

hm

Pushbutton

Buzzer

LED

LED LED

OUT

PIRMotionsensor

9 V battery

CO

M p

ort

Mic

rocon

troller

ch

ip

15

KO

hm

Page 7: Software and documentation

BASIC Stamp software

Stamp Mode: BS2sx“Run”

Your saved program files

“Identify”

Finds COM port with BASIC Stamp

connected

Page 8: Software and documentation

' 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”

Page 9: Software and documentation

' Example 01a' {$STAMP BS2sx}' {$PBASIC 2.5}

Red: 'Lable

LOW 4 'Makes pin 4 to have low voltagePAUSE 1000 'Pause 1 secondHIGH 4 'Makes pin 4 to have high voltagePAUSE 50 'Pause 0.05 sec

GOTO Red 'Makes program to go back to “Red” lable

END

Example 01a

File: “Example-01a.bsx”Red LED

Page 10: Software and documentation

' Example 01b' {$STAMP BS2sx}' {$PBASIC 2.5}

DO

LOW 4 'Makes pin 4 to have low voltagePAUSE 1000 'Pause 1 secondHIGH 4 'Makes pin 4 to have high voltagePAUSE 50 'Pause 0.05 sec

LOOP

END

Example 01b

File: “Example-01b.bsx”Red LED

Page 11: Software and documentation

' Example 01c' {$STAMP BS2sx}' {$PBASIC 2.5}

RedLED PIN 4 ' red LED is connected to pin 4IsOn CON 1 ' IsOn = 1(constant) LED is active high IsOff CON 0 ' IsOff = 0(constant) LED is active lowSetup: OUTPUT RedLED ' sets OUTPUT to be pin 4

Main: DO

RedLED = IsOn ' same as HIGH 4PAUSE 1000 ' pause 1 s = 1000 msRedLED = IsOff ' same as LOW 4PAUSE 1000 ' pause 1 s = 1000 ms

LOOP

END

Example 01cFile: “Example-01c.bsx”Red LED

Page 12: Software and documentation

' Example 02a' {$STAMP BS2sx}' {$PBASIC 2.5}

Green: ' label “green”DEBUG ? IN0, CR ' sends information to the PC

' about the status of input pin 0PAUSE 1000 ' pause 1 s = 1000 msGOTO Green ' return to label “green”

END

Example 02aFile: “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

Page 13: Software and documentation

' 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 ENDIFLOOP

Example 02bFile: “Example-02b.bsx”Red LED and pushbutton

Page 14: Software and documentation

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

Page 15: Software and documentation

' Example 04' {$STAMP BS2sx}' {$PBASIC 2.5}RedLED PIN 4 ' red LED is connected to pin 4YellowLED PIN 13 ' Yellow LED is connected to pin 13GreenLED PIN 15 ' Green LED is connected to pin 15IsOn CON 1 ' IsOn = 1(constant) LED is active highIsOff CON 0 ' IsOff = 0(constant) LED is active lowSetup: OUTPUT RedLED ' sets OUTPUT to be pin 4 OUTPUT YellowLED OUTPUT GreenLEDMain: 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 LOOPEND

Example 04 File: “Example-04.bsx”3 LEDs

Page 16: Software and documentation

' 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 05aFile: “Example-05a.bsx”Buzzer

Run the program. What do you hear?

Page 17: Software and documentation

' 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*3NEXT

END

Example 05b File: “Example-05b.bsx”Buzzer: SOS

Page 18: Software and documentation

' Example 04' {$STAMP BS2sx}' {$PBASIC 2.5}RedLED PIN 4 ' red LED is connected to pin 4YellowLED PIN 13 ' Yellow LED is connected to pin 13GreenLED PIN 15 ' Green LED is connected to pin 15IsOn CON 1 ' IsOn = 1(constant) LED is active highIsOff CON 0 ' IsOff = 0(constant) LED is active lowSetup: OUTPUT RedLED ' sets OUTPUT to be pin 4 OUTPUT YellowLED OUTPUT GreenLEDMain: 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 LOOPEND

Example 05c File: “Example-05c.bsx”3 LEDs and buzzer

Page 19: Software and documentation

Format of variables

1. Bit 0 or 1

2. Nibble (Nib) 0-15

3. Byte 0-255

4. Word 0-65535 or -32768 to + 32767

Mouse VAR BIT ' Value can be 0 or 1.Cat VAR NIB ' Value can be 0 to 15.Dog VAR BYTE ' Value can be 0 to 255.Rhino VAR WORD ' Value can be 0 to 65535.

Example of variables:

Page 20: Software and documentation

' {$STAMP BS2sx}' {$PBASIC 2.5}

TOTAL VAR ByteX CON 20TOTAL = 0TOTAL = TOTAL +100DEBUG ? TOTALTOTAL= TOTAL/3DEBUG ? TOTALDEBUG ? X

END

Example 06Performing calculations File: “Example-06.bsx”

Run the program. What do you see?

Page 21: Software and documentation

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.

Page 22: Software and documentation

22

Start

MeasureTemperature

Temp.< 100

EnergizeHeater

Temp.> 102

EnergizeFan

Yes

No

Yes

No

Flow Chart

Page 23: Software and documentation

23

Sequential Flow ExamplePseudo-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

FlowchartFlowchart::

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

Code:Code:

Start

Turn OFF LED1

Turn OFF LED2

2 Second Pause

Turn ON LED1

Turn ON LED2

2 Second Pause

End

Page 24: Software and documentation

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

Page 25: Software and documentation

25

Looping Flow ExamplePseudo-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 >>>> '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

Page 26: Software and documentation

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.

Page 27: Software and documentation

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

Page 28: Software and documentation

28

“IF-THEN” Example: AlarmThis 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 >>>> '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 1Pressed

Main

Speaker2000Hz for1 second

Main

TrueFalse

Page 29: Software and documentation

' Example 07' {$STAMP BS2sx}' {$PBASIC 2.5}

RedLED PIN 4 ' red LED is connected to pin 4YellowLED PIN 13 ' yellow LED is connected to pin 13PushButton PIN 0 ' push button is connected to pin 0IsOn CON 1 ' IsOn = 1(constant) LED is active highIsOff CON 0 ' IsOff = 0(constant) LED is active lowX 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 MainAMainB: ' label “MainB” YellowLED = IsOff RedLED = IsOn X = IN0 IF X = 0 THEN GOTO MainA ELSE GOTO MainB

END

Example 07IF…THEN…ELSE File: “Example-07.bsx”

Page 30: Software and documentation

' File: Example-PIR.bsx' {$STAMP BS2sx}' {$PBASIC 2.5}

' -----[ I/O Definitions ]-------------------------------------------------PIR PIN 7 ' I/O Pin For PIR SensorRED PIN 4 ' I/O Pin For RED LEDGREEN PIN 15 ' I/O Pin For GREEN LEDYELLOW PIN 13 ' I/O Pin For YELLOW LED' -----[ Variables ]-------------------------------------------------------counter VAR Byte ' Trip Counter' -----[ Initialization ]--------------------------------------------------DEBUG CLS ' Clear DEBUG ScreenLOW REDLOW GREENHIGH YELLOWFOR counter = 20 TO 0 ' Wait 40 Seconds For PIR Warm-Up DEBUG HOME, "WARMING UP:", DEC2 counter PAUSE 1000 ' Display Counter Every SecondNEXTLOW YELLOWcounter = 0 ' Clear Counter VariableDEBUG 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 PIRPIR - sensor File: “Example-PIR.bsx”