Presentation is loading. Please wait.

Presentation is loading. Please wait.

LSU 2004Introduction to Programming1 Introduction to Programming with the BASIC Stamp Programming Unit, Lecture 1.

Similar presentations


Presentation on theme: "LSU 2004Introduction to Programming1 Introduction to Programming with the BASIC Stamp Programming Unit, Lecture 1."— Presentation transcript:

1 LSU 2004Introduction to Programming1 Introduction to Programming with the BASIC Stamp Programming Unit, Lecture 1

2 LSU 2004Introduction to Programming2 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

3 LSU 2004Introduction to Programming3 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.

4 LSU 2004Introduction to Programming4 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

5 LSU 2004Introduction to Programming5 Size 1.2” x 0.6” Speed 20MHz ~12,000 instructions/sec 8x2K bytes EEPROM prog storage ~4,000 instructions 16 user I/O pins 2 I/O pins for serial comm 0 to 70 degrees C environment The BASIC Stamp BS2P24

6 LSU 2004Introduction to Programming6 BS2P24 Module 5 - 12 volts power supply Low power “sleep” mode RAM Size 128 Bytes scratchpad 26 variables

7 LSU 2004Introduction to Programming7 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

8 LSU 2004Introduction to Programming8 BASIC Stamp Development Systems BS2P Demo Board form Parallax, Inc. Connection to PC

9 LSU 2004Introduction to Programming9 BASIC Stamp Development Systems Parallax, Inc. Board of Education

10 LSU 2004Introduction to Programming10 BASIC Stamp Development Systems CANSAT v. 7 DC-DC converter Memory MODEM Expansion pins

11 LSU 2004Introduction to Programming11 BASIC Stamp Instruction Set Overview FLOW CONTROL EEPROM ACCESS RAM ACCESS NUMERICS TIME DEBUG POWER CONTROL DIGITAL I/O ASYNC SERIAL I/O SYNC SERIAL I/O PARALLEL I/O ANALOG I/O SOUND

12 LSU 2004Introduction to Programming12 FLOW CONTROL Instructions IF…THENCompare and conditionally branch. BRANCHBranch to address specified by offset. GOTOBranch to address. GOSUBBranch to subroutine at address. RETURNReturn from subroutine. RUNSwitch execution to another program page. POLLRUNSwitch execution upon polled interrupt. FOR..NEXTEstablish a FOR…NEXT loop.

13 LSU 2004Introduction to Programming13 MEMORY ACCESS Instructions DATAStore data in EEPROM READRead EEPROM data into variable WRITEWrite byte into EEPROM STORESwitch READ/WRITE access program slot. GETRead Scratch Pad RAM byte into variable. PUTWrite byte into Scratch Pad RAM.

14 LSU 2004Introduction to Programming14 NUMERICS Instructions LOOKUPLookup data specified by offset and store in variable. Used to create lookup table. LOOKDOWNFind target’s match number(0-N) and store in a variable. RANDOMGenerate a pseudo-random number.

15 LSU 2004Introduction to Programming15 TIME Instructions PAUSEPause execution for 0 - 65535 milliseconds. POLLWAITPause until a polled interrupt occurs.

16 LSU 2004Introduction to Programming16 DEBUG Instruction DEBUGSend information to the host PC for viewing.

17 LSU 2004Introduction to Programming17 POWER CONTROL Instructions NAPNap for a short period. Power consumption is reduced. SLEEPSleep for 1 - 65535 seconds. Power consumption is reduced. ENDSleep until the power cycles or the host PC connects. Power consumption is reduced.

18 LSU 2004Introduction to Programming18 DIGITAL I/O Instructions INPUTMake pin an input. OUTPUTMake pin an output. REVERSEReverse direction of a pin. LOWOutput a low logic level on pin. HIGHOutput a high logic level on pin. TOGGLEMake pin an output and toggle state. PULSINMeasure an input pulse. PULSOUTOutput a timed pulse by inverting a pin for some defined time.

19 LSU 2004Introduction to Programming19 DIGITAL I/O Instructions (cont’d) BUTTONDebounce button, perform auto-repeat, and branch to address if button is in target state. COUNTCount cycles on a pin for a given amount of time. XOUTGenerate X-10 power line control codes. POLLINSpecify pin and state for polled-interrupt. POLLOUTSpecify pin and state for output upon a polled- interrupt. POLLMODESpecifies the polled-interrupt mode.

20 LSU 2004Introduction to Programming20 ASYNCHRONOUS SERIAL I/O Instructions SERINInput data in an asynchronous serial stream. SEROUTOutput data in an asynchronous serial stream. OWINInput data from a “1-wire” device. OWOUTOutput data to a “1-wire” device.

21 LSU 2004Introduction to Programming21 SYNCHRONOUS SERIAL I/O Instructions SHIFTINShift data in from synchronous serial device. SHIFTOUTShift data out to synchronous serial device. I2CINInput data from I2C serial device. I2COUTOutput data to I2C serial device.

22 LSU 2004Introduction to Programming22 PARALLEL I/O Instructions LCDCMDWrite a command to a parallel LCD. LCDINRead data from an LCD. LCDOUTWrite data to an LCD.

23 LSU 2004Introduction to Programming23 ANALOG I/O Instructions PWMOutput pulse-width-modulated (PWM) signal then return pin to input state. Can be used to generate an analog voltage (0 - 5V). RCTIMEMeasure an RC charge-discharge time. Can be used to measure a resistance.

24 LSU 2004Introduction to Programming24 SOUND Instructions FREQOUTGenerate one or two sine waves of specified frequencies. DTMFOUTGenerate DTMF (Touch-tone) telephone tones.

25 LSU 2004Introduction to Programming25 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: MotorContrlPIN7

26 LSU 2004Introduction to Programming26 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: AlarmCodeCON13 Naming Variables –Begin variable names with lowercase and use mixed case, using uppercase letters at the beginning of new words within the name. –Example:waterLevelVARWord

27 LSU 2004Introduction to Programming27 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: AlarmCodeCON13 Naming Variables –Begin variable names with lowercase and use mixed case, using uppercase letters at the beginning of new words within the name. –Example:waterLevelVARWord

28 LSU 2004Introduction to Programming28 PBASIC Programming Style (cont’d) PBASIC Keywords use UPPERCASE Indent nested codetwo 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

29 LSU 2004Introduction to Programming29 BASIC Stamp Applications Learning fundamentals of programming Data acquisition Control Robotics Embedded micro-controllers

30 LSU 2004Introduction to Programming30 Activity Students 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.


Download ppt "LSU 2004Introduction to Programming1 Introduction to Programming with the BASIC Stamp Programming Unit, Lecture 1."

Similar presentations


Ads by Google