際際滷

際際滷Share a Scribd company logo
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
PIC16F88
   Microchip
   8 bit
   Memory
       68 bytes of RAM Execution Memory
       68 bytes of EEPROM Program Memory
            Retention > 40 years
   2-5.5v
   18 Pins
       13 I/O pins                 www.microchip.com
I/O
Programming Languages
   ASM                     C
       Low level               Most used
       Full Control            HiTech C
   BASIC, Forth, LOGO          Microchip C
       Interpreted             CCS PIC C
       Easy to use
                                     We will this
       Slow
Program Example: Loop
/* pulses pin PORTB<3>   /* pulses pin PORTB<3>
eight times */            eight times */

pulse:                   void pulse()
movlw 0x08               {
movwf counter               int i;
                            for (i=0; i<8; i++)
pulse_lp0:                    { output_high(PIN_B3);
bsf     PORTB, 3                 output_low(PIN_B3);
                                 }
bcf     PORTB, 3
                           return;
decfsz counter, F
                         }
goto    pulse_lp0
return

   ASM Code                       C Code
Compilers Inefficiency
 /* pulses pin PORTB<3>                          /* pulses pin PORTB<3> eight
                                                    times */
 eight times */
                                                       0005:     CLRF      21
                                                       0006:     MOVF      21,W
 0000: movlw      0x8                                  0007:     SUBLW     07
                                                       0008:     BTFSS     03,0
                   0001: movwf                         0009:     GOTO      014
 0x20                                                  000A:     BSF       03,5
    0002: bsf          0x6,0x3                         000B:     BCF       06,3
                          0003:                        000C:     BCF       03,5
                                                       000D:     BSF       06,3
 bcf    0x6,0x3
                                                       000E:     BSF       03,5
           0004: decfsz                                000F:     BCF       06,3
 0x20                                                  0010:     BCF       03,5
                                                       0011:     BCF       06,3
                                                       0012:     INCF      21,F
                                                       0013:     GOTO      006


   Our Code                                          Compilers ASM Code
               See http://www.ccsinfo.com/picc.shtml for compilers info
IRX Board
   PIC16F84
   RS-232 Serial Port
   Visible LED
   Infrared LED
   Infrared Detector
   8 I/O Available
   Prototyping Area
Microcontrollers
What you need
   PIC C/ASM Compiler   http://www.ccsinfo.com/
   PIC Programmer
   MPLAB IDE
          Free          http://www.microchip.com
What is the Process ?
1.   Write you program                      4.   Insert your PIC
           MPLAB                                   Face pin 1 to resistor
           C or ASM


2.   Compile your program                   4.   Power it Up
                CCS PCM
                                                    Connect 9V Battery
3.   Transfer your program
           Puts HEX file into the PIC      4.   Debug your program
           Use PICSTART and MPLAB                  Never works a the first time
           Burns your app into the PIC
                                            4.   Repeat step 1
Tips

        Programming                         Debugging

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

   Make an led flash out a pattern
   LED / Photdiode pair to measure something
       a. variables and values
       b. 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.

More Related Content

Microcontrollers

  • 1. Microcontrollers A Practical Approach Ernesto Arroyo earroyo@media.mit.edu
  • 2. What is a Microcontroller? Mini-Computer Microprocessor The Brains Arithmetic Logic Unit (ALU) Control Unit Program/ Data Storage Peripherals (Input/Output) Low-Cost
  • 3. Why Important? Embedded Inside: Automotive systems Airplanes Toys Medical Devices Furniture Billions of units
  • 13. PIC16F88 Microchip 8 bit Memory 68 bytes of RAM Execution Memory 68 bytes of EEPROM Program Memory Retention > 40 years 2-5.5v 18 Pins 13 I/O pins www.microchip.com
  • 14. I/O
  • 15. Programming Languages ASM C Low level Most used Full Control HiTech C BASIC, Forth, LOGO Microchip C Interpreted CCS PIC C Easy to use We will this Slow
  • 16. Program Example: Loop /* pulses pin PORTB<3> /* pulses pin PORTB<3> eight times */ eight times */ pulse: void pulse() movlw 0x08 { movwf counter int i; for (i=0; i<8; i++) pulse_lp0: { output_high(PIN_B3); bsf PORTB, 3 output_low(PIN_B3); } bcf PORTB, 3 return; decfsz counter, F } goto pulse_lp0 return ASM Code C Code
  • 17. Compilers Inefficiency /* pulses pin PORTB<3> /* pulses pin PORTB<3> eight times */ eight times */ 0005: CLRF 21 0006: MOVF 21,W 0000: movlw 0x8 0007: SUBLW 07 0008: BTFSS 03,0 0001: movwf 0009: GOTO 014 0x20 000A: BSF 03,5 0002: bsf 0x6,0x3 000B: BCF 06,3 0003: 000C: BCF 03,5 000D: BSF 06,3 bcf 0x6,0x3 000E: BSF 03,5 0004: decfsz 000F: BCF 06,3 0x20 0010: BCF 03,5 0011: BCF 06,3 0012: INCF 21,F 0013: GOTO 006 Our Code Compilers ASM Code See http://www.ccsinfo.com/picc.shtml for compilers info
  • 18. IRX Board PIC16F84 RS-232 Serial Port Visible LED Infrared LED Infrared Detector 8 I/O Available Prototyping Area
  • 20. What you need PIC C/ASM Compiler http://www.ccsinfo.com/ PIC Programmer MPLAB IDE Free http://www.microchip.com
  • 21. What is the Process ? 1. Write you program 4. Insert your PIC MPLAB Face pin 1 to resistor C or ASM 2. Compile your program 4. Power it Up CCS PCM Connect 9V Battery 3. Transfer your program Puts HEX file into the PIC 4. Debug your program Use PICSTART and MPLAB Never works a the first time Burns your app into the PIC 4. Repeat step 1
  • 22. Tips Programming Debugging Flash LED at start up for Make sure the PIC is 500 mSec or longer inserted properly and pin 1 Program all unused I/O pins facing the resistor to be outputs Verify you have power Check the oscillator
  • 23. Hands on Make an led flash out a pattern LED / Photdiode pair to measure something a. variables and values b. 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.