Microcontrollers

A Practical Approach
Ernesto Arroyo earroyo@media.mit.edu

What is a Microcontroller? 

Mini-Computer
±

Microprocessor 
 

The Brains Arithmetic Logic Unit (ALU) Control Unit

Program/ Data Storage  Peripherals (Input/Output) Low-Cost 

Why Important?  Embedded Inside: ± ± ± ± ± Automotive systems Airplanes Toys Medical Devices Furniture  Billions of units .

iSphere .

Augmented Reality Kitchen .

Augmented Reality Kitchen .

Talking Trivet .

WaterBot .

EyeR .

Thermo Mouse Pad .

Spatula .

Spatula .

5v 18 Pins ± 13 I/O pins www.PIC16F88    Microchip 8 bit Memory ± ± 68 bytes of RAM Execution Memory 68 bytes of EEPROM Program Memory  Retention > 40 years   2-5.com .microchip.

I/O .

Forth.Programming Languages  ASM ± ±  C ± ± ± ± Low level Full Control Interpreted Easy to use Slow  BASIC. LOGO ± ± ± Most used HiTech C Microchip C CCS PIC C  We will this .

} return. F goto pulse_lp0 return /* pulses pin PORTB<3> eight times */ void pulse() { int i. 3 decfsz counter.Program Example: Loop /* pulses pin PORTB<3> eight times */ pulse: movlw 0x08 movwf counter pulse_lp0: bsf PORTB. i<8. for (i=0. } ASM Code C Code . 3 bcf PORTB. i++) { output_high(PIN_B3). output_low(PIN_B3).

0 014 03.com/picc.3 03.3 03.5 06.ccsinfo.5 06.0x3 0x20 /* pulses pin PORTB<3> eight times */ 0005: 0006: 0007: 0008: 0009: 000A: 000B: 000C: 000D: 000E: 000F: 0010: 0011: 0012: 0013: CLRF MOVF SUBLW BTFSS GOTO BSF BCF BCF BSF BSF BCF BCF BCF INCF GOTO 21 21.5 06.W 07 03.5 06.Compilers¶ Inefficiency /* pulses pin PORTB<3> eight times */ 0000: 0001: 0002: 0003: 0004: movlw movwf bsf bcf decfsz 0x8 0x20 0x6.3 21.shtml for compiler¶s info .0x3 0x6.3 03.F 006 Our Code Compiler¶s ASM Code See http://www.

IRX Board        PIC16F84 RS-232 Serial Port Visible LED Infrared LED Infrared Detector 8 I/O Available Prototyping Area .

.

What you need    PIC C/ASM Compiler PIC Programmer MPLAB IDE  http://www.microchip.ccsinfo.com .com/ Free http://www.

3. Insert your PIC ± MPLAB C or ASM Face pin 1 to resistor 2. Write you program   4. Power it Up ± Transfer your program   Connect 9V Battery Never works a the first time Puts HEX file into the PIC Use PICSTART and MPLAB 6. Debug your program ±  ³Burns your app into the PIC´ 7.What is the Process ? 1. Compile your program ‡ CCS PCM 5. Repeat step 1 .

Tips Programming   Debugging  Flash LED at start up for 500 mSec or longer Program all unused I/O pins to be outputs   Make sure the PIC is inserted properly and pin 1 facing the resistor Verify you have power Check the oscillator .

calibration phase 4. make a context aware something: ideas? sunshine alarm headlight alarm finger bend back slouch measurer curve into a paint program (button and bendy black tube) door stop release when light turned out.Hands on Make an led flash out a pattern LED / Photdiode pair to measure something a. . variables and values b.