100% found this document useful (1 vote)
378 views

Getting Started With PIC18F4550 and MPLABX IDE - PIC Controllers

This document provides instructions for setting up an LED blinking project using the MPLABX IDE, XC8 compiler, and PICkit2 programmer for a PIC18F4550 microcontroller. It describes downloading the required software, creating a new project, configuring configuration bits, writing the main code, and building and loading the program to make an LED blink on and off.

Uploaded by

Krishanu Modak
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
378 views

Getting Started With PIC18F4550 and MPLABX IDE - PIC Controllers

This document provides instructions for setting up an LED blinking project using the MPLABX IDE, XC8 compiler, and PICkit2 programmer for a PIC18F4550 microcontroller. It describes downloading the required software, creating a new project, configuring configuration bits, writing the main code, and building and loading the program to make an LED blink on and off.

Uploaded by

Krishanu Modak
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Getting started with PIC18F4550 and MPLABX IDE

Introduction
There are various development environments available for the PIC18f4550 controller.

We can use the following IDEs for development:

MPLABX IDE
MikroC

C Compilers for PIC 18f4550

XC8
Hi-Tech
C18

After code development, for loading flash memory we can use this kit

PIC kit1
PIC kit2
PIC kit3
ICD

Here we are going to develop a simple LED blinking project using MPLABX IDE with XC8 compiler and flash the PIC18f4550
chip using PIC kit2.

MPLABX IDE is an Integrated Development Environment that is developed by Microchip.

It is used to develop a code for PIC microcontrollers.

Let’s start with MPLABX IDE.

1. Download compiler XC8 and Install it.

Here: http://www.microchip.com/mplab/compilers

2. Download MPLABX IDE and install it also.

Here: http://www.microchip.com/mplab/mplab-x-ide

3. There are many hardware Programmer available for PIC like PicKit2, PicKit3, USBPicProg.

Here PickKit2 is used to download the program into the device.

4. Now Open MPLABX IDE.


5. Now Create a new project for LED blinking.

Select File -> New Project

6. After selecting new project following window will pop-up.

Select Microchip Embedded -> Select Standalone and click to next.


7. Select Device and their Family

Here PIC18 family is used and PIC18F4550 device. After selecting click on next.
8. Window for selecting tool will Pop-up after clicking on next 

Here PicKit2 Program downloading tool is used. Then click on Next.

9. Now select Compiler. Here XC8 is used and click Next.


10. Name a Project e.g. LED_Blinking_demo also set Path for Project Folder and Click on Finish.

Now our project is displayed in Project window.


 

The source file contains Main Code and other supporting files for a header (optional). 
Now in PIC18f4550, we need to configure some registers or bits like WDT, MCLRE’, FOSC, etc.
We can write these configurations in our C code as follows:

              #pragma config FOSC = INTOSC_EC

              #pragma config WDT = OFF

              #pragma config MCLRE = OFF

But PIC18F4550 has more configuration Registers so they are set to default and the compiler generates warnings for these
registers. So to configure these registers MPLABX provides one simple way which is as follows:

11. Go to Window -> PIC Memory Views -> Select Configuration Bits
Then window Popup as follows:

Configure these bits according to requirement and click on the button “Generate Source Code to Output” given on the bottom
side.
Copy the Generated Source Code and paste it in a header file.

12. To do this 1st Create a Header file

Right Click on Header in project -> Select new -> Select C Header File

Name Header File and click on Finish


Now we have to write the main code for LED blinking.

13. Create the Main file for developing code.

Right Click on Source in the project -> Select new -> Select C Main File
To write code in Assembly, select the ASM file.

Give name to C file and click on finish.


14. Now write a simple application Code.

Simple C Program for LED blinking.

Program
/*

Led blinking using PIC18F4550

http://www.electronicwings.com

*/

#include "Configurations_Header_File.h" /*Header file for Configuration Bits*/

#include <pic18f4550.h> /*Header file PIC18f4550 definitions*/

void MSdelay(unsigned int);

void main()

OSCCON=0x72; /* Use internal oscillator of 8MHz Frequency */

TRISB=0x00; /* Set direction of PORTB as OUTPUT to which LED is connected */

while(1)

LATB = 0xFF; /* Turn ON LED for 500 ms */

MSdelay (500);

LATB = 0x00; /* Turn OFF LED for 500 ms */

MSdelay (500);

void MSdelay(unsigned int val)

unsigned int i,j;

for(i=0;i<val;i++)

for(j=0;j<165;j++); /*This count Provide delay of 1 ms for 8MHz Frequency */

 
15. Now Build Project.

There is one Hammer like shape, click on it to build a project.

After building a Project, output Window appears which gives errors and warnings if any otherwise gives message Build
Successful.

Following is generated Hex File which needs to load in PIC device.

 After uploading the above program connect LED to the PIC microcontroller, it will start blinking as shown below.

LED Blinking

You might also like