Programming PIC18F4450 with Proteus | applied electronics engineering

Latest

Programming PIC18F4450 with Proteus

By Applied Electronics - Friday, April 21, 2017 No Comments
In this tutorial we will show how to program PIC18F4450 with Proteus microcontroller simulation software. For the demonstration purpose we will make a simple LED blinking program.We will also tell you how to download MPLAB IDE and XC compiler needed for compiling the C program code. Also you need to configure Proteus to use the compiler.

The process is to first download and install MPLAB X IDE, download and install XC compiler, optionally you can also download and install the MPLAB code configurator. Then you need to configure the proteus to use the MPLAB compiler. After all these, you create a schematic with a LED connected to the PIC18F4450 and then write led blinking C program code.

What you should expect is the following LED blinking simulation.



The steps are as follows.

1. Download and Install MPLAB X IDE

Go to microchip website and download the MPLAB X IDE which is for free.

2. Download XC compiler

The IDE needs compiler. The microchip compiler for MPLAB X IDE has 8-bit, 16-bit and 32-bit compiler. Depending upon your requirement download the compiler from the following web link:

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


Once you have downloaded the compiler, just click it to start installation.


3. Install MPLAB MCC(MPLAB Code Configurator)

This is optional step but if you want to work with MPLAB in long term, it is good idea to install this plugin since you are already installing MPLAB for the first time. Open MPLAB X IDE. Go to tools and select Plugins. In the Plugin window, go to Available Plugins and select MPLAB Code Configurator then install it.

Now you are ready to write code for PIC microcontrollers.

4. Configure Proteus

Open proteus and place the PIC18F4550 microcontroller into schematic. Then double click it to open its properties. Then select Edit Firmware.


Then in the window that shows up, click on compiler button.

In the MPLAB XC8 field, edit the path to your MALAB XC8 installation folder. In this case it is C:\Program Files\Microchip\xc8\v1.41
The click ok.

Now you will be able to select MPLAB XC8 compiler as follows.


You will see a default C program code in the code editor window.


We need to write our C program in this editor. Write the following C program code to blink a LED connected to the pin 0 of port B.

#include<p18f4550.h>  

#pragma config PLLDIV = 5 , CPUDIV = OSC1_PLL2 , USBDIV = 2
#pragma config FOSC = INTOSCIO_EC
#pragma config FCMEN = OFF                             
#pragma config BORV = 3
#pragma config WDT = OFF
#pragma config CPB = OFF
#pragma config CPD = OFF

void mydelay(void)
      {
     int i, j;
     for(i=0;i<5000;i++)
        {
           for(j=0;j<2;j++)
                      {      }   
        }  
      }
                         
void main(void)
         {
        TRISB = 0 ;
    
           while(1)
          {
         LATBbits.LATB0 = 1;
         mydelay();
         LATBbits.LATB0 = 0;
         mydelay();
         }
     }

Build the project. this will compile the C code to hex code and upload the hex file into the PIC18F4450 microcontroller.


You should see Compiled Successfully message at the bottom message pane.

Now connect a LED to the port B pin 0 as shown below and also connect the active low MCLR pin to +5V supply via 4.7kOhm resistor. Then click on the Run button for simulation. The LED should blink now.


No Comment to " Programming PIC18F4450 with Proteus "