Let's Make Robots!

PIC programming C language (using MPLAB IDE v8.88)


So I've made a topic in the MPLAB section, but no one seemed to answer, so I thought, maybe it belongs in here, since I'm pretty newb at the moment.


I bought a PCKit2 and looked at the 12 examples, they're pretty neat. But I would like to learn to program the PIC's in C-language.

I have found a guide on the MPLAB CD-ROM that came with this PICKit2, but it doesn't seem to work.

Then I've tried a tutorial on the internet, and here's what that gave me:

I've just made a source file with just a small main like this (using a PIC16F690):

#include <p16F690.h>

void main()


and it gives a building error because it can't find the file to include (p16F690.h), and I can't seem to find the include directory anywhere either. (using MPLAB v8.88)

Here's the link of the tutorial btw: http://www.pic18f.com/18f4550-c-tutorial/2009/11/16/tutorial-4-hello-world-program-in-c/

Does anyone have experience with this? Or knows where to find a better toturial? I found another C tutorial, but it will cost me $85. Anyone got something else? :)


Thanks in advance!


Comment viewing options


@merser: "Do you have a C compiler installed. If in doubt go and download here"

Lol, I had downloaded it, but I seemed to have deleten it because it wasn't working the first time... I downloaded it, used pic.h instead of p16f690.h (as rick said) and now it's working! At least the basic program is ^^

Back to the study table now! :)

Thanks for your help everyone!

"It appears you don't need to add p16F690.h to projects using this compiler but just htc.h instead."

Did you try htc.h at all? Anyway glad to hear you are making progress.

Yes, I just tried to include htc.h instead of pic.h and this also works, but to be honest, I don't know what's the difference. So I'm just glad that it works for now :)

I had a look at both header files and it appears htc.h is the top tier which will include pic.h if you are using the compiler option  Hitech C for 10/12/16 MCU's. If you instead omit htc.h but include pic.h this header file includes htc.h

Then pic.h in turn includes chip_select.h which is where it determines which header to include for your chip. In your case it finds pic16F690.h and includes it.

I'm not a C guru but I'll try to help . I assume you selected  HiTech Universal Tool Suite while setting up the project with the Mplab Project Wizard . Also you should have selected the 16f690 as the device in the Project Wizard . Try changing  the #include <p16F690.h> to #include <pic.h> . In the file pic.h it checks to see if  _16F690 is defined and includes the file pic16f685.h if it is . This file has the defines for the 16f690 . It is in the directory C:\Program Files (x86)\HI-TECH Software\PICC\PRO\9.65\include on my computer . Hope this helps .

Good Luck


he does have a project up that he wrote some C for a PIC


Yes, here it is: http://letsmakerobots.com/node/34273

I've followed all 4 of them, it's working. But the problem is: it's assembly language instead of C language. If i try and write code like in the top post, it gives an error, that it can't include the file (p16F690.h)(error 105: Cannot open file (Include File "p16F690.h" not found))

In the tutorial, p16F690.INC is used, if I try that, together with the void main program, it gives an error, 'illegal opcode', so I guess, the software thinks it should be written in assembly?


Not that I use C to program pics but I'll try to help. *INC is an assembly file include you need a *.h file. Unless you have a full installation of a c compiler you may be missing the necesary files.

Do you have a C compiler installed. If in doubt go and download here. It's the latest one and it's free. Once this is installed you should have all the .h files you need. There should be a hitech folder under program files on windows.

It appears you don't need to add p16F690.h to projects using this compiler but just htc.h instead. There are sample in a folder in this directory but they are for a different chip. There is also a 364 page manual for the compiler in the docs directory.



merser has a few tutorials here that talk about getting started with MPLABX (I think).

Unfortunately they are of no use Birdmun. They are assembly tutorials for MPLAB8. I have only just downloaded and investigated MPLABX.
At this stage I can't see any benefits for me to change from MPLAB8. Other than minor improvements to the editor it seems to be just like moving the furniture. I think the main changes are only beneficial to the professional sector. They seem to be moving slowly with both adding all the features from MPLAB8 and documentation. I'm suspiscious they will never complete it to the same quality of MPLAB8.
I started a simple project using a template file and tried to build and got the "No rule to make " error. Which after googling appears to be fairly common. But there is not just one reason for getting this error. In my case the IDE does not copy the file you add to the project into the project directory???. I have to go to the template files directory and copy and paste into the project directory.
I've posted in the forums at microchip but got no reply.
If you create a new file everything is ok but you start with a completely blank page. Funny thing is you can build this if you add an end staement to the file.
While I won't criticize MPLABX, for me I'm just comfortable to keep using MPLAB8 for now.