200 likes | 711 Views
PIC Overview ELG4911 Raymond Peterkin Edited by: Misbah Islam Outline Introduction to PIC Developing code for PIC MPLAB IDE Project Creation Updating Source Code Building Projects Programming the PIC References: www.microchip.com
E N D
PIC Overview ELG4911 Raymond Peterkin Edited by: Misbah Islam
Outline • Introduction to PIC • Developing code for PIC • MPLAB IDE • Project Creation • Updating Source Code • Building Projects • Programming the PIC • References: www.microchip.com
Introduction to PIC: Peripheral Interconnect Microcontrollers Basically meant to develop and run ASM programs More than One billion 8bit processors have been sold • 8 Bit Family PIC10, PIC12, PIC14, PIC16, PIC 18 • < $20 , Memory 8K-256 K, 48 MHz, 6-100 Pins PIC 18 Features: • 9-Ports, 80 pins, Parallel I/O, PWM, 10bit ADC, USART, CAN, Timers • On chip memory 64KB, External Off-chip 2 MB (EMI uses 38 pins) • 16 Bit family • (ASM, C) PIC24, PIC32
ASM and C • To run C you need cross compilers • MPLAB with Lite-C or MCC18 compilers need models PIC18 and over • With commercial systems, e.g. CCS and Hi-TECH you can compile C programs on all models • http://ww1.microchip.com/downloads/en/DeviceDoc/51025e.pdf (pp.44) Code Examples: http://microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1408 http://microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=2623 http://ww1.microchip.com/downloads/en/DeviceDoc/51519B.pdf
Developing Code for PIC, ASM example MPLAB IDE: • Free integrated development environment (IDE) from Microchip to implement code for PICs • Latest version 8.0 (recommended), In Lab 7.6 • IDE and documentation (user guide) can be downloaded from the Microchip website • To open MPLAB IDE • StartAll ProgramsMicrochipMPLAB IDE v8.00MPLAB IDE
What are these? • IDE: Integrated Development Environment Software package that lets you assemble, compile, link, export and debug programs. • ICE: In Circuit Emulator: Hardware that allows you to test the developed programs on non-real (emulated) hardware. To test ICE you need IDE • Programmer: Is a piece of hardware, e.g. PICkit 2, PM3 that allow the export of executable .hex files (load) files to the PIC processor’s memory directly. It is driven by the IDE.
MPLAB IDE Projects • A project must be created for implementation • Specify your device • Create and edit your files • Compile and link your project • Program the device • To create a project • ProjectProject Wizard…
MPLAB IDE Project Creation (1/4) • Begin project and specify device
MPLAB IDE Project Creation (2/4) • Step 2: Select Microchip MPASM Toolsuite • Step 3: Create New Project File
MPLAB IDE Project Creation (3/4) • Step 4: Add project files • ASM file • Starting point for assembly code • <device name>tmpo.asm • Linker script • <device name>.lkr • Example: Device PIC16F917 • C:\Program Files\Microchip\MPASM Suite\Template\Object\16f917tmpo.asm • C:\Program Files\Microchip\MPASM Suite\16f917.lkr
MPLAB IDE Project Creation (4/4) • Finish project creation and return to IDE • View project details • ViewProject
Updating Source Code • Modify .asm files • Under ‘Source Files’ folder in project window • Open and edit files to implement new functionality • Additional files can be created and added
Building a Project • ProjectBuild All (or Ctrl+F10) • Output window indicates success or failure • HEX file generated when project is built • Used to program the device
Programming the PICDirectly Downloading Hex files to the PIC Memory • Used to transfer HEX file to the PIC and begin program execution • Two methods (HEX file must be generated) • MPLAB IDE • ProgrammerSelect ProgrammerPICKit2 • PICkit2 • Separate program • StartAll ProgramsMicrochipPICkit 2 v2.11
Option a.Programming PIC with MPLAB IDE (1/3) • Connect PIC to computer through PICkit2 Hardware • Select the PICkit 2 from the Programmer menu • ProgrammerSelect Programmer PICkit 2
Programming PIC with MPLAB IDE (2/3) • New ‘PICkit’ 2 tab appears in the output window • New options appear in the Programmer menu and tool bar
Programming PIC with MPLAB IDE (3/3) • Transfer HEX file to PIC • ProgrammerProgram
Option b. Programming PIC with PICkit 2 (1/2) • Connect PIC to computer through PICkit2 • Start PICkit2 programmer software StartProgramsMicrochipPICkit2 v 2.40 • Device is listed • PIC is detected
Programming PIC with PICkit 2 (2/2) • Import HEX file • FileImport Hex • Transfer HEX file to PIC • Click ‘Write’ button • Memory contents are updated with new program
References • Microchip website • www.microchip.com • Main source of information with several documents • MPLAB IDE User’s Guide (under MPLAB IDE description) • Chapters 2 and 3 contain tutorials, page 44 http://ww1.microchip.com/downloads/en/DeviceDoc/51025e.pdf Good Tutorial: p 45 summary http://ww1.microchip.com/downloads/en/DeviceDoc/51519B.pdf • PICkit 2 Microcontroller Programmer User’s Guide • PIC data sheets