Download presentation
Presentation is loading. Please wait.
Published byGregory Colding Modified over 9 years ago
1
Slides created by: Professor Ian G. Harris PIC Development Environment MPLAB IDE integrates all of the tools that we will use 1.Project Manager -Groups together all files and data related to a project 2.Editor – Standard text editor to write code with 3.Assembler and Linker – Stand-alone or to group several sources/libraries 4.Debugger – Standard debugger, used with simulator or in-circuit emulator 5.Execution Engines – Instruction-level simulators for PIC devices 6.Programmer – Transfers the executable to the PIC part Cross-Compiler generates PIC machine code from a high-level language We need a C cross-compiler, will use HI-TECH C for PIC10/12/16
2
Slides created by: Professor Ian G. Harris Downloading/Installing Tools PICKit 1 comes with CDs but you should download the newest versions MPLAB IDE – Go to www.microchip.com, select MPLAB IDE link – Select MPLAB IDE v8.50 Full Release Zipped Installation link – Unzip and install – During the installation you will be prompted to download/install Hi-Tech C Compiler HI-TECH C Compiler – You may need to install this directly – Go to www.htsoft.com – Select PIC10/12/16 MCUs – Download lite mode v9.70 – Include PICC path in your path when prompted
3
Slides created by: Professor Ian G. Harris Development Example How to Make a Project 1. Write some C code using an editor, save it in a directory Try blinking-LED code on course webpage 2. Create a new project using Project > Project Wizard 3. Select device PIC16F684 4. Prompt: Select a language toolsuite, choose HI-TECH Universal Toolsuite 4. Choose a name and directory for your project 5. Prompt: Add Existing Files, add your C source file Select the C source file on the left, click Add button 6. Select Finish if everything looks OK
4
Slides created by: Professor Ian G. Harris Compiling and Programming 1. Select Project > Build to compile the project - You should see a window and eventually a “Build Successful” msg 2. Plug in the PICKit 1 3. Choose board with Select Programmer > PICKit 1 4. Program the PIC with Programmer > Program Device The program should run after a few seconds.
5
Slides created by: Professor Ian G. Harris Simulation with MPLAB Simulation is useful to try before hooking up real hardware Simulation is not perfectly accurate – No understanding of analog effects Debugger > Select Tool > MPLAB Sim to start simulator Basic Debugger Operations (via new buttons) – Run – Pause – Animate – run slowly – Step In – step to next line – Step Over – step past a function – Step Out – complete current function – Reset – start simulation at beginning
6
Slides created by: Professor Ian G. Harris Breakpoints, Timing, Watching Breakpoints Set breakpoints by double-clicking on the line of code Manage breakpoints using Debugger > Breakpoints Stopwatch Debugger > Stopwatch shows cycle count and time Useful to make delays with loops Watch Window Watch window shows register and variable contents Add SFR to add a register, Add Symbol to add a variable
7
Slides created by: Professor Ian G. Harris Blinking LEDs on PICKit 1 Image taken from PICkit™ 1 Flash Starter Kit User’s Guide, Microchip Technology Inc. RA1 (12) RA2 (11) RA5 (2) RA4 (3) PIC16F684 has 12 I/O pins Port A (RA0 – RA5) and Port C (RC0 - RC5) LEDs are connected across RA1, RA2, RA4, and RA5
8
Slides created by: Professor Ian G. Harris Blinking LED Code #include __CONFIG (FCMDIS & IESODIS & BORDIS & UNPROTECT & MCLRDIS & PWRTEN & WDTDIS & INTIO); main (){ int i; PORTA = 0; TRISA4 = 0; TRISA5 = 0; while (1 == 1) { for(i=0; i < 25000; i++); RA4 = RA4 > 1; }
9
Slides created by: Professor Ian G. Harris Blinking Light Code Components Include required libraries #include defines the memory mapping of all special registers Set the Configuration Bits of the microcontroller These bits control processor functions (clock source, watchdog, etc. Use __CONFIG macro to set them in C Be careful with these Initialize I/O pins – input or output? Initialize values Infinite while loop – Common in embedded systems Delay loop – Needed to slow system to match human perception
10
Slides created by: Professor Ian G. Harris Controlling Digital I/O Pins PORTA is a 6 bit bi-directional port TRISA is the corresponding direction register Setting a TRISA pin = 1 makes the corresponding PORTA pin an input Clearing a TRISA pin makes the corresponding PORTA pin an output Reading the PORTA register shows the status of the pins Writing to PORTA writes to the pins (if they are outputs) Can refer to individual bits in the PORTA and TRISA registers TRISA0 = 0; RA0 = 1;
11
Slides created by: Professor Ian G. Harris Length of Delay Loop for (i=0; i<25000; i++) ; How long is this loop? 25000 clocks? Loop needs to compare i to 25000 and to increment i. 25000 is larger than 8 bits. Need to see the assembly code to know for sure. Clock freq = 4MHz, Period = 250 ns
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.