introduction to programming with the basic stamp
DESCRIPTION
Introduction to Programming with the BASIC Stamp. Programming Unit, Lecture 1. What is a micro-controller? (microcomputer, microprocessor, embedded controller). Microcomputer with self contained ROM & RAM Read Only Memory for program storage (Flash or OTP) - PowerPoint PPT PresentationTRANSCRIPT
LSU 2004 Introduction to Programming 1
Introduction to Programmingwith the BASIC Stamp
Programming Unit, Lecture 1
LSU 2004 Introduction to Programming 2
What is a micro-controller?(microcomputer, microprocessor, embedded controller)
•Microcomputer with self contained ROM & RAM–Read Only Memory for program storage (Flash or OTP)–Random Access Memory for data storage–CPU for logical and arithmetic operations–Interfaces for external connections
•Micro-controllers are everywhere–About 3 for every person on earth–A BMW 7-series automobile has 65 microprocessors
LSU 2004 Introduction to Programming 3
Why do I need a micro-controller?•A small, inexpensive alternative to a PC.
–Ideal for battery operated applications.–Easier to program than a PC.–Easy to interface to other electronics.
•More flexible than “hardwired” logic.–Changes made by editing software v. soldering iron.–Can emulate many logic IC’s and other components.–Additional functionality can be easily added.
LSU 2004 Introduction to Programming 4
Micro-controllers•Micro-controllers are manufactured by numerous companies. Many target specific applications
–automotive–industrial–consumer appliance
•Some micro-controllers are particularly useful in prototype or educational environments.
–BASIC Stamp–PIC (Microchip, Inc.)–Rabbit (Rabbit Semiconductor)–Atmel
LSU 2004 Introduction to Programming 5
Size 1.2” x 0.6”Speed 20MHz~12,000 instructions/sec8x2K bytes EEPROM prog storage
~4,000 instructions16 user I/O pins
2 I/O pins for serial comm0 to 70 degrees C environment
The BASIC Stamp BS2P24
LSU 2004 Introduction to Programming 6
BS2P24 Module5 - 12 volts power supplyLow power “sleep” mode
RAM Size 128 Bytes scratchpad 26 variables
LSU 2004 Introduction to Programming 7
BASIC Stamp Development System
•Hardware platform for BASIC Stamp–Power supply–Prototyping area–Connection for downloading compiled code
•Host PC–STAMP Editor–Documentation
•CD•on-line from www.parallax.com
LSU 2004 Introduction to Programming 8
BASIC Stamp Development Systems
•BS2P Demo Board form Parallax, Inc.
Connection to PC
LSU 2004 Introduction to Programming 9
BASIC Stamp Development Systems•Parallax, Inc. Board of Education
LSU 2004 Introduction to Programming 10
BASIC Stamp Development SystemsCANSAT v. 7
•DC-DC converter
•Memory
•MODEM
•Expansion pins
LSU 2004 Introduction to Programming 11
BASIC Stamp Instruction Set OverviewFLOW CONTROL
EEPROM ACCESSRAM ACCESS
NUMERICS
TIME DEBUG
POWER CONTROL
DIGITAL I/O
ASYNC SERIAL I/OSYNC SERIAL I/O
PARALLEL I/O
ANALOG I/O
SOUND
LSU 2004 Introduction to Programming 12
FLOW CONTROL Instructions•IF…THEN Compare and conditionally branch.•BRANCH Branch to address specified by offset.•GOTO Branch to address.•GOSUB Branch to subroutine at address.•RETURN Return from subroutine.•RUN Switch execution to another program page.•POLLRUN Switch execution upon polled interrupt.
•FOR..NEXT Establish a FOR…NEXT loop.
LSU 2004 Introduction to Programming 13
MEMORY ACCESS Instructions•DATA Store data in EEPROM•READ Read EEPROM data into variable•WRITE Write byte into EEPROM•STORE Switch READ/WRITE access program slot.
•GET Read Scratch Pad RAM byte into variable.•PUT Write byte into Scratch Pad RAM.
LSU 2004 Introduction to Programming 14
NUMERICS Instructions•LOOKUP Lookup data specified by offset and store in
variable. Used to create lookup table.
•LOOKDOWN Find target’s match number(0-N) and store in a variable.
•RANDOM Generate a pseudo-random number.
LSU 2004 Introduction to Programming 15
TIME Instructions•PAUSE Pause execution for 0 - 65535 milliseconds.
•POLLWAIT Pause until a polled interrupt occurs.
LSU 2004 Introduction to Programming 16
DEBUG Instruction•DEBUG Send information to the host PC for viewing.
LSU 2004 Introduction to Programming 17
POWER CONTROL Instructions•NAP Nap for a short period. Power consumption is
reduced.
•SLEEP Sleep for 1 - 65535 seconds. Power consumption is reduced.
•END Sleep until the power cycles or the host PC connects. Power consumption is reduced.
LSU 2004 Introduction to Programming 18
DIGITAL I/O Instructions•INPUT Make pin an input.•OUTPUT Make pin an output.•REVERSE Reverse direction of a pin.•LOW Output a low logic level on pin.•HIGH Output a high logic level on pin.•TOGGLE Make pin an output and toggle state.•PULSIN Measure an input pulse.•PULSOUT Output a timed pulse by inverting a pin for
some defined time.
LSU 2004 Introduction to Programming 19
DIGITAL I/O Instructions (cont’d)•BUTTON Debounce button, perform auto-repeat, and
branch to address if button is in target state.•COUNT Count cycles on a pin for a given amount of
time.•XOUT Generate X-10 power line control codes.•POLLIN Specify pin and state for polled-interrupt.•POLLOUT Specify pin and state for output upon a polled-
interrupt.•POLLMODE Specifies the polled-interrupt mode.
LSU 2004 Introduction to Programming 20
ASYNCHRONOUS SERIAL I/O Instructions
•SERIN Input data in an asynchronous serial stream.•SEROUT Output data in an asynchronous serial stream.
•OWIN Input data from a “1-wire” device.•OWOUT Output data to a “1-wire” device.
LSU 2004 Introduction to Programming 21
SYNCHRONOUS SERIAL I/O Instructions
•SHIFTIN Shift data in from synchronous serial device.•SHIFTOUT Shift data out to synchronous serial device.
•I2CIN Input data from I2C serial device.•I2COUT Output data to I2C serial device.
LSU 2004 Introduction to Programming 22
PARALLEL I/O Instructions
•LCDCMD Write a command to a parallel LCD.
•LCDIN Read data from an LCD.
•LCDOUT Write data to an LCD.
LSU 2004 Introduction to Programming 23
ANALOG I/O Instructions
•PWM Output pulse-width-modulated (PWM) signal then return pin to input state. Can be used to generate an analog voltage (0 - 5V).
•RCTIME Measure an RC charge-discharge time. Can be used to measure a resistance.
LSU 2004 Introduction to Programming 24
SOUND Instructions
•FREQOUT Generate one or two sine waves of specified frequencies.
•DTMFOUT Generate DTMF (Touch-tone) telephone tones.
LSU 2004 Introduction to Programming 25
PBASIC Programming Style
•Do it right the first time–The “I’ll fix it later” part usually never gets fixed.–Sloppy code will be difficult to understand and debug later.
•Use meaningful names–Meaningful names will reduce the need for comments–Name variables, constants and program labels (up to 32 chars)
•Name I/O pins–example: MotorContrl PIN 7
LSU 2004 Introduction to Programming 26
PBASIC Programming Style (cont’d)
•Naming Constants–Begin constant names with uppercase and use mixed case, using uppercase letters at the beginning of new words within the name.–Example: AlarmCodeCON 13
•Naming Variables–Begin variable names with lowercase and use mixed case, using uppercase letters at the beginning of new words within the name.–Example: waterLevel VAR Word
LSU 2004 Introduction to Programming 27
PBASIC Programming Style (cont’d)
•Naming Constants–Begin constant names with uppercase and use mixed case, using uppercase letters at the beginning of new words within the name.–Example: AlarmCodeCON 13
•Naming Variables–Begin variable names with lowercase and use mixed case, using uppercase letters at the beginning of new words within the name.–Example: waterLevel VAR Word
LSU 2004 Introduction to Programming 28
PBASIC Programming Style (cont’d)
•PBASIC Keywords use UPPERCASE
•Indent nested code two spaces per indent is recommended
•Enclose condition statements in parenthesis–Example: ...IF (waterTemp >= setPoint) THEN…
•Use white space to improve legibility–two blank lines before subroutines for example
LSU 2004 Introduction to Programming 29
BASIC Stamp Applications
•Learning fundamentals of programming•Data acquisition•Control•Robotics•Embedded micro-controllers
LSU 2004 Introduction to Programming 30
ActivityStudents will inventory the BalloonSat kit of components and review the BalloonSat documentation.
Students will begin construction of BalloonSat and complete assembly to the Stage 1 level.
Students will inspect BalloonSat and correct any defects in workmanship.