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/
2. 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 Lite
version 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.
16. Go to
C:MCC18binlkr
And 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:MCC18binLKR
17. Step 8
Select “Release” if you want to
download the generated .hex file
on the microcontroller
24. 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.
25. 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.
26. How to Program your PIC
Choose programmer
device from here (here
we chose PICKit 3)
27. 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.
28. How to Debug your PIC
Choose debugger
device from here (here
we chose PICKit 2)
29. 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
30. 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 the
microcontroller 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.
31. Circuit schematic for PIC18F4550 microcontroller with
USB module connection to PC
Notes:
• VCC = +5v, you can power the PIC
from 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.
32. Example code 1:
Simple digital output using PIC18F4550
// In this example we will configure port D as output and send some data to be
//output on it
#include<p18f4550.h>
void main()
{
TRISD = 0x00; //set port D to output , also can be written 0b00000000
LATD = 0x00; //set latch of port D to 0x00
while(1) //while(1) loop is used to run the application forever
{
PORTD = 0x0f; // output 00001111 on port D pins
}
}
33. Example code 2:
Simple digital input using PIC18F4550
// In this example we will configure port D as input 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 written 0b11111111
LATD = 0x00; //set latch of port D to 0x00
while(1) //while(1) loop is used to run the application forever
{
i = PORTD; // read port D and save read value to variable i
}
}