I'm a newbie trying to lean PIC, i downloaded MPLAB and MPLAB X ide . Ihave done this around 100 times and looked over web enough before asking this question, but my code is not compiled and it is failed always. Here is what i did:-
- Created a new project using PROJECT WIZARD
- Edited the code
- Copied the "16F871.H" library in both folder (i created the project in) and added it to the header files in MPLAB IDE.
Here's my code
*> // IFIN.C Tests an input
#include " 16F877A.h "
void main()
{
int x; // Declare variable
output_D(0); // Clear all outputs
while(1) //
{
x = input(PIN_C0); // Get input state
if(x = = 1)output_high(PIN_D0); // Change output
}
}*
But on compiling the code i'm getting error a this Executing:
"C:\Program Files\PICC\Ccsc.exe" +FM "NEW.c" #_DEBUG=1 +ICD +DF +LN +T +A +M +Z +Y=9 +EA #_16F877A=TRUE
* Error 18 "NEW.c" Line 2(10,23): File can not be opened
Not in project "C:\Users\jatin\Desktop\DHAKKAN PIC\ 16F877A.h " Not in "C:\Program Files\PICC\devices\ 16F877A.h " Not in "C:\Program Files\PICC\drivers\ 16F877A.h "
* Error 128 "NEW.c" Line 2(10,17): A #DEVICE required before this line
* Error 12 "NEW.c" Line 6(9,10): Undefined identifier -- output_D
* Error 12 "NEW.c" Line 9(10,11): Undefined identifier -- input
* Error 51 "NEW.c" Line 10(8,9): A numeric expression must appear here
5 Errors, 0 Warnings. Build Failed. Halting build on first failure as requested. BUILD FAILED: Mon Jul 08 15:09:17 2013
I would be grateful to you if you could help me.
1 Answer 1
The most immediate problem I can see is the following line of code:
#include " 16F877A.h "
You should remove the spaces because it's trying to open a file that contains spaces which is why you're getting multiple errors related to that file. While in general extra whitespace doesn't matter a lot in C / C++ code for any literals enclosed in quotes it certainly does.
Another area where you shouldn't insert extra spaces is also between operators such as ==
so the space between those two characters should be removed from line 10 as well so it should look like this:
if(x == 1) output_high(PIN_D0); // Change output