Upload
el-rayes
View
5.004
Download
2
Tags:
Embed Size (px)
DESCRIPTION
A starter guide how to use Microchip MPLAB IDE for PIC microcontrollers and related tools like MPLAB C18, C30 and C32 compilers, and how to MPLAB features to get connected and integrated with programmer/debugger devices and development kits from Microchip. for more discussion and articles about different microcontroller platforms and tutorials please visit: http://elrayescampaign.blogspot.ca/
Citation preview
MPLAB IDE Starter Guide
By: Karim El-Rayes
Software to be installed
• MPLAB IDE from Microchip®, its free of charge and you can download from Microchip® website.
• C18 or C30 or C32 compiler according to the microcontroller family you are using, you can download Trail version or Liteversion for students from Microchip® website.
• Notes: For PIC18 family you will need C18 C – compiler.For PIC24 and PIC33 families you will need C30 C – compiler.For PIC32 family you will need C32 C – compiler.• PIC18F4550 was used as an example in many cases, but
most of the material is applicable for all PIC18F family of microcontrollers.
Step 1
Click next
Step 2
Select microcontroller you will use from this list, then click “Next”
Step 3
Select compiler C18 from the list, don’t forget to select the other settings, then click “Next”
Step 4
Choose place to save your project, then click “Next”
Add any files to the project if you want, then clic k “Next”
Click “Finish”
Step 5
Click “New file” button to start writing your first code
Write your code here then click “Save file” button
Choose place to save your code and don’t forget to save it in *.c
Step 6
Right click on “Source Files” and select “Add Files”
Choose your code *.c file you saved it
Step 7 (optional)
Right click on “Linker script” and select “Add Files”
Go to C:\MCC18\bin\lkrAnd select linker script file of the microcontroller you are using in your project(in this example we are using microcontroller PIC18F4550)
In C18 compiler Version 3.36 and higher, the linker scripts are in C:\MCC18\bin\LKR
Step 8
Select “Release” if you want to download the generated .hex file on the microcontroller
Step 9
Click “Project” then go to “Build options” then select “Project”
Select “Library Search Path” from the directories drop list
Click “New” then write here the libraries file path then click “Apply” then “Ok”
Step 10
Click “Build All” button to build and compile your pr oject
Check your program either “Build succeeded” or watch the errors here
Hints: Setting microcontroller clock
Click “Configure” then select “Configuration Bits”
If you want to make settings from this window and not in your code don’t check this mark.
If you are using crystal higher than 4MHz choose “HS-PLL Enabled”.If you are using 4MHz crystal choose XT.
Disable “Watchdog timer” if you are not using it.
Hints: settings for PIC18F4550
Set the crystal you are using
If you are using a crystal higher than 4MHz select “HS” or “HS+PLL” Disable watchdog timer if
you are not using it.
How to Program your PICChoose programmer device from here (here we chose PICKit 3)
How to Program your PIC (cont.)
Step 1: Choose “Release” Option
Step 2: “Build” project
Step 3: “Program” the PIC
Note: After you program the PIC, disconnect the PIC programmer hardware from the microcontroller.
How to Debug your PICChoose debugger device from here (here we chose PICKit 2)
How to Debug your PIC (cont.)
Step 1: Choose “Debug” Option
Step 2: “Build” project
Step 4: “Run” to start debugging
Step 3: “Program” the PIC
Hardware example: Connecting PICkit 2/PICkit 3 programmer/debugger to PIC18F4550 microcontroller
+5v
Ground
Notes:• Pin 2 in PICkit2/3 “VDD/Target” has to be connected to themicrocontroller VDD supply, if you are using +3.3v supply based microcontrollers then VDD = +3.3v, and the same for +5v supply. • Pin 6 in PICkit 2 is “Not connected”, while in PICkit 3 is Low Voltage Programming pin “LVP”, leave it not connected in most cases if you are not using it.
Circuit schematic for PIC18F4550 microcontroller wi th USB module connection to PC
Notes:
• VCC = +5v, you can power the PICfrom the USB port itself.• You can replace the 8 MHz crystal with any value depending on your configuration.• The two 100nF capacitors on Pin 18 can be replaced with one 470nF capacitor.
Example code 1: Simple digital output using PIC18F4550 // In this example we will configure port D as outp ut and send some data to be //output on it
#include<p18f4550.h>void main(){
TRISD = 0x00; //set port D to output , also can be wr itten 0b00000000LATD = 0x00; //set latch of port D to 0x00
while(1) //while(1) loop is used to run the applicat ion forever{
PORTD = 0x0f; // output 00001111 on port D pins}
}
Example code 2: Simple digital input using PIC18F4550 // In this example we will configure port D as inpu t and read some data from and //store it to variable “i”
#include<p18f4550.h>int i = 0;void main(){
TRISD = 0xff; //set port D to input, also can be wri tten 0b11111111LATD = 0x00; //set latch of port D to 0x00
while(1) //while(1) loop is used to run the applicat ion forever{
i = PORTD; // read port D and save read value to variable i}
}
Using PIC32 Starter kit or PIC32 microcontrollers
PIC32 Starter kits
PIC32 Ethernet Starter kit PIC32 USB Starter kit II
Connecting PIC32 ESK board
PIC32 Ethernet Starter kit
PIC32 USB Starter kit II
Selecting PIC32 starter kit for debugging
Select “PIC32 Starter kit” from the debuggers list
Debugging
Step 1: set the debugger to “Debug” mode
Step 2: “Build” project Step 3: “Program” thePIC microcontroller
Step 4: “Start” debugging