–Creating .HEX file from C code

—————————————————————-

 

In this post we shall see how to create the .HEX file ,which is finally fused on to the PIC microcontroller.

To start with create a new folder , say PICTEST inside , D:\ drive

Image 1 

Inside this folder you can organize all your PIC projects.Create another folder inside this , say LEDBLINK , which is our first project.

Open the MPLAB IDE .

Click on Project Wizard under Project.

 

Image 2

 

Select the PIC controller IC you’ve picked up for the project.Here it is PIC16F877A from the dropdown menu. Click Next.

 

Image 3 

 

Next window is selection of Language suite.We’ve already installed HITECH C separately on C:\ drive.Now MPLAB IDE detects it automatically & displays under drop down list of Active Toolsuite.

Select HITECH Universal Toolsuite  & its location is automatically displayed.

Click on Next.

 

 Image 4

 

Click on Browse & locate the project folder you created earlier in D:\ drive.

 

 Image 5

 

Provide a name (without any extension) for your project & Save it under the project folder.

 

Image 6

 

Click Next

 

Image 7

Next window is to add any existing files to the project.For this test project , nothing to be added .So click Next.

Image 8

 

Final Summary of your project will be displayed , with IC selected ,location of project & the Tool Suite used.

Image 9  

Click Finish to see the Project window of MPLAB , where you see you project with .mcp extension.

 

  Image 10

 

To write your C code you need to open the built in  Text editor of MPLAB IDE by clicking

FILE –> NEW

Image 11

 

An untitled text editor window opens.

 

Image 12

 

Before typing into your C code save the file  by clicking File –> Save As & then provide a name to your code file .Ensure that the file has an extension .c

 

Image 13   Image 14

Now inside the project folder  you can see the .c file along with other 3 files created automatically by the MPLAB IDE.  The file with .mcp extension is the project file , the one with .mcw is the Workspace file & .mcs is Make file.

Image 16 

 

Type in your C code .Your C code should comply with syntax of HITECH C Compiler.Learn to use the #include header files & Define statements from the help file of HITECH C Compiler.

 

Image 17

 

After typing in the C code press ctrl+s to save the file.Now the * mark over blinkled.c disappears indicating the file is saved.

Right click Source Files & select Add Files..

Image 18

 

Browse to the location where you stored the .c file & select Open.

 

  Image 19

 

The blinkled.c file will appear under Source Files.

Image 20

 

Build the project by pressing F10  or by selecting BUILD under Project.

 

Image 21

 

If there is no error in your C code the BUILD will be Successful & .HEX file is generated along with other support files.

Image 22

Open the project folder in D:\ drive to see the .HEX file

This is the file we’re going to fuse on to the target PIC controller IC.

Image 23

 

 

Watch this video on creating the .HEX file :

 

Creating .HEX File

 

Continue to the next post “Hands on Hardware “

 

cooltext1137713216