PIC Development Environment MPLAB IDE integrates all of
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 PIC 10/12/16
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 v 8. 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 PIC 10/12/16 MCUs – Download lite mode v 9. 70 – Include PICC path in your path when prompted
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 PIC 16 F 684 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
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.
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
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
Blinking LEDs on PICKit 1 PIC 16 F 684 has 12 I/O pins Port A (RA 0 – RA 5) and Port C (RC 0 - RC 5) LEDs are connected across RA 1, RA 2, RA 4, and RA 5
Blinking LED Code #include <pic. h> __CONFIG (FCMDIS & IESODIS & BORDIS & UNPROTECT & MCLRDIS & PWRTEN & WDTDIS & INTIO); main (){ int i; PORTA = 0; TRISA 4 = 0; TRISA 5 = 0; while (1 == 1) { for(i=0; i < 25000; i++); RA 4 = RA 4 > 1; } }
Blinking Light Code Components Include required libraries #include<pic. h> 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
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 TRISA 0 = 0; RA 0 = 1;
Length of Delay Loop for (i=0; i<25000; i++) ; Clock freq = 4 MHz, Period = 250 ns 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.
- Slides: 11