MPLAB C18 Tutorial - Setting up a new C18 project and creating an application - Creating the main code file

Creating the main code file

Finally, after all that setup, we are ready to start writing some code. At first, we need to cover some basics and write a shell of a program that really does nothing except build without errors. Once that is accomplished, we can expand our application to do some things but we need to know the basics are covered and the application builds without errors.

NOTE: Up to this point, I've held your hand a bit by showing images of some menu commands in the MPLAB IDE. At this point, it is assumed that you know how to navigate the menu commands so I'll simply say "File / New" when I want you to navigate to that command.

It just so happens that is exactly what I want you to do, but fortunately there is a shortcut for that. You can click on File / New or simply press CONTROL-N to bring up a blank document within the MPLAB IDE. Once it is displayed, I want you to immediately save it. No, CONTROL-S doesn't work yet, not sure why Microchip left that out. I have suggestions posted to their site. Anyway, you have to go to File / Save As to save it.

One annoying issue with MPLAB is that it remembers the last folder you were at, even if it wasn't in the IDE. In my opinion, the MPLAB IDE should start at the project's folder first and make you navigate out of it. Since that isn't done, MAKE ABSOLUTELY SURE you are saving this file in your project folder.

Name the file main.c and save it. Once you have saved it, you need to add a reference to it in your SOURCE FILES folder in the IDE.

In the IDE, if you do not see a project window, open it up for viewing by clicking View on the menu and making sure Project is checked.

view

Figure 1 - PICkit 2 Settings

 

Now that it is visible, right click on 'Source Files' and select 'add files...'. When the browsing dialog window appears, click your new file 'main.c' and then click ok. If you did it right, you will see what is shown if Figure 2.

project view

Figure 2 - Project View: main.c is added

Now we are ready to add some setup code to main.c and it's about time isn't it? =)