In this tutorial we will see how to setup a Mplabx project to generate .hex file for Pic16f877a
Keil Setup Steps
Step1: Open the MPLABx software and select the New project from File Menu as shown below.
Step2: Selcet the Standalone option for the project.
Step3: Choose the Controller(PIC16f877A) from the device drop down.
Step4: Select the required programmer. In this case it is Pickit2 the IC(PIC16f877A) from the drop down.
Step5: Choose the xC8/Hitech compiler which ever is installed.
Step6: Provide the project name and select the project project folder.
Step7: Now the required project is created. Create a new .c/main.c to write the code.
Step8: Save the file with C extension.
Step9: Type the code or Copy paste the below code snippet and save it
#include <lpc17xx.h> | |
void delay_ms(unsigned int ms) | |
{ | |
unsigned int i,j; | |
for(i=0;i<ms;i++) | |
for(j=0;j<20000;j++); | |
} | |
/* start the main program */ | |
int main() | |
{ | |
SystemInit(); //Clock and PLL configuration | |
LPC_PINCON->PINSEL4 = 0x000000; //Configure the PORT2 Pins as GPIO; | |
LPC_GPIO2->FIODIR = 0xffffffff; //Configure the PORT2 pins as OUTPUT; | |
while(1) | |
{ | |
LPC_GPIO2->FIOSET = 0xffffffff; // Make all the Port pins as high | |
delay_ms(100); | |
LPC_GPIO2->FIOCLR = 0xffffffff; // Make all the Port pins as low | |
delay_ms(100); | |
} | |
} |
Step10: Build the project and fix the compiler errors/warnings if any.
Step11: Code is compiled with no errors. The .hex file is generated.
Uploading the Hex file
After generating the .hex file check this tutorial for uploading Hex and Bin files.