PIC Microcontroller Software Setup MPlab

In this tutorial we will see how to setup a Mplabx project to generate .hex file for Pic16f877a

Pic16F877A MplabX Setup0.png

MPLABx Setup Steps

Step1: Open the MPLABx software and select the New project from File Menu as shown below.
Pic16F877A MplabX Setup01.png

Step2: Select the Standalone option for the project.Pic16F877A MplabX Setup02.png

Step3: Choose the Controller(PIC16f877A) from the device drop down.Pic16F877A MplabX Setup03.png

Step4: Select the required programmer. In this case it is Pickit2 or Pickit3.Pic16F877A MplabX Setup04.png

Step5: Choose the xC8/Hitech compiler which ever is installed.Pic16F877A MplabX Setup05.png

Step6: Provide the project name and project location.Pic16F877A MplabX Setup06.png

Step7: Now the required project is created. Create a new .c/main.c to write the code.Pic16F877A MplabX Setup07.png

Step8: Save the file with C extension.Pic16F877A MplabX Setup08.png

Step9: Type the code or Copy paste the below code snippet and save it

Pic16F877A MplabX Setup09.png 

 Program:

 /* Program By Udaya Prakash Jayaraman */
    #include <pic16f877a.h>
    void delay(unsigned int k)
    {
        unsigned int i,j;
        for(i=0;i<k;i++)
        {
            for(j=0;j<1000;j++);
        }
    }

    int main()
    {
      /* Configure all the ports as Output */
        TRISA = 0x00;
        TRISB = 0x00;
        TRISC = 0x00;
        TRISD = 0x00;

        while(1)
        {
            PORTA = 0xff; /* Turn ON all the leds connected to Ports */
            PORTB = 0xff;
            PORTC = 0xff;
            PORTD = 0xff;
            delay(100);
           
            PORTA = 0x00; /* Turn OFF all the leds connected to Ports */
            PORTB = 0x00;
            PORTC = 0x00;
            PORTD = 0x00;
            delay(100);
        }
        return (0);
    } 


Step10: Build the project and fix the compiler errors/warnings if any.
Pic16F877A MplabX Setup10.png

Step11: Code is compiled with no errors. The .hex file is generated.
Pic16F877A MplabX Setup11.png
Step12: Upload program to controller using pickit3
 

Related Posts:

  • C - File I/O The last chapter explained the standard input and output devices handled by C programming language. This chapter cover how C programmers can create, open, close text or binary files for their data storage. A file represent… Read More
  • C - Input and Output When we say Input, it means to feed some data into a program. An input can be given in the form of a file or from the command line. C programming provides a set of built-in functions to read the given input and feed it… Read More
  • C - typedef The C programming language provides a keyword called typedef, which you can use to give a type a new name. Following is an example to define a term BYTE for one-byte numbers − typedef unsigned char BYTE; Af… Read More
  • C - Header Files A header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source files. There are two types of header files: the files that the programmer … Read More
  • C - Preprocessors The C Preprocessor is not a part of the compiler, but is a separate step in the compilation process. In simple terms, a C Preprocessor is just a text substitution tool and it instructs the compiler to do required … Read More