Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Help with c code compile error in mplab

Status
Not open for further replies.

Jack_Rider

New Member
Hi fellas. I need serious help here with mplab. I've googled everything i can and searched many forums for similar questions like this but none of them solved my problem. I just installed pic c lite version 9.5 and mplab version 7.0. The instruction in pic c lite told me that it supports only mplab 6.5 and higher so i know my version should have no problems. However, when i create a new project in mplab and set the usual settings, i get "build failed" when i click on BUILD ALL. Here are the exact steps i followed:
1: I installed mplab 7.0.
2: I installed pic c lite 9.5 and clicked "integrate picc-lite with microchip mplab". I also clicked "Add to environment path".
3: Now in mplab, i entered project wizard, chose 16f877. For the toolsuite contents, all of them are already pointing to picl.exe in the location.
4: I chose a project name, selected a c source file "blink.c", of which the source code is as shown:

#include<htc.h>
#define _XTAL_FREQ 8000000
void main()
{
TRISB=0x00;
PORTB=0x00;
while(1)
{
PORTB=0xFF;
_delay_ms(100);
PORTB=0x00;
_delay_ms(100);
}
}

In configuration bits i set oscillator as XT, Watchdog timer off, power-up timer on. The rest i left unchanged. In the pic c compiler tab under build options, i enabled assembler optimization as level 9. Now after everything, and all the sweating and several re-installations, i still get the same thing:


Clean: Deleting intermediary and output files.
Clean: Done.
Executing: "C:\Program Files (x86)\HI-TECH Software\PICC-Lite\9.50\BIN\PICL.EXE" -C -E"blink.cce" "blink.c" -O"blink.obj" -Zg9 -O -ASMLIST -Q -MPLAB -16F877
Executing: "C:\Program Files (x86)\HI-TECH Software\PICC-Lite\9.50\BIN\PICL.EXE" -E"try.lde" "C:\Users\OZIEGBE\Desktop\XYX781227\Microcontrollers\Pic projects\blink.obj" -M"try.map" -O"try.cof" -O"try.hex" -Q -MPLAB -16F877
BUILD FAILED: Sun Dec 01 21:05:15 2013


Just for extra info, here's something i discovered: while reading the mplab manual, pic 18f452 was used as example on how to put a template file and the appropriate linker and compile. It worked. But when i tried the same thing for pic 16f877 i got "BUILD FAILED" so i wonder if the entire problem is from the pic itself.

I understand that there are much higher versions of mplab right now, but the filesizes are too huge for what i can afford to download right now so i gotta find how to do it with mplab 7.0. I'll appreciate it if someone could compile the c code successfully and tell me the exact steps used in doing so, and if the code is faulty, help me with a correct version as i only want to get this thing to work for now. And yea...sorry if my post is too long but i just had to explain the problem in detail. I'll appreciate any help whatsoever. Thanks.
 
Thanks for replying. I followed the tutorial but unfortunately pic c lite doesn't have 16f628a in the ini file so i got an error. All the same, i think you must be right about my pic c lite version being too new. But despite the error, i do get an obj file. How can i convert this into hex file using objtohex.exe that comes with pic c lite?
 
Jack said:
pic c lite doesn't have 16f628a in the ini file so i got an error.
Should be.... Its quite a dated chip now.... Besides you want the header file... You don't need to specify it as HTC.H fetches it anyway...

Why can't you download the latest versions? Slow broadband or what?
 
Worse than slow broadband. Very costly internet subscription. I guess it'll be till January before i can download everything. My school's got free internet flying around everywhere.
 
microchip cd's are out of date they sent me one with ICD3 and it was about 4 versions out of date!
 
Wow, giddy!!! I finally downloaded Mplab 8.92. I was still getting the same "build failed" when using a single c source file until i decided to alter the c code. Then i got "build successful". The code is very short. Here it is:

#include<htc.h>
#include<pic.h>
#define _XTAL_FREQ 8000000
void main()
{
TRISB=0x00;
PORTB=0x00;
while(1)
{
PORTB=0xFF;
_delay_ms(100);
PORTB=0x00;
_delay_ms(100);
}
}

As it is above, it wasn't working. So what i did was remove both "_delay_ms(100)" lines from the code, and then it built successfully. But i know that this means there won't be a delay. I'm wondering if there's any correct syntax for causing a delay that i can use.
 
Usually when a compiler tells you that "build failed" it also tells you the reason why it failed. If it doesn't, then it is a crappy compiler.
 
Last edited:
misterT yea, i was using mplab 7.0 then, and it doesn't give the reason for the error.
Ian Rogers the __delay_ms() function still doesn't work for me, i don't know why. But i use a primitive way of timing it. Like this:
int a;
for(a=0;a<10000;a++){;;}
This stays where the __delay_ms(100) was, and takes advantage of the little timing between each cycle in the for loop. And i noticed something else--
Declaring a variable (int a; in this case) must be done as the first thing in the braces after void main() or else it would result in "build failed".
 
it doesn't give the reason for the error.
Sorry, but I just can't believe that. It must give you something more than "build failed". If it really doesn't give any reason, then quit using that compiler.
Anyway, the problem is that you have either misspelled the function name or that you have not included the necessary library (header file).
Or, for some strange reason, it refuses to compile if you have not defined your clock frequency (properly). Delay functions always need to know your clock frequency. Usually they use some default value if the user fails to define one.
 
Last edited:
I got it guys!! Remember i'm using pic c lite(9.5 to be specific). After much testing, i found out what works for me is DelayMs().
But first, i needed to add a file called delay.c in the source files, and then in the code all i needed do was write #include "delay.h". That's all! But it seems the code varies for different people, and i found mine was DelayMs() only by studying the delay.c and delay.h file's function definitions. That's where the problem was.
 
I got it guys!! Remember i'm using pic c lite(9.5 to be specific). After much testing, i found out what works for me is DelayMs().
But first, i needed to add a file called delay.c in the source files, and then in the code all i needed do was write #include "delay.h". That's all! But it seems the code varies for different people, and i found mine was DelayMs() only by studying the delay.c and delay.h file's function definitions. That's where the problem was.

I hope you understand what was the problem and learned something. The DelayMs() is a function that somebody else has written for you. And when you say #include "delay.h", you include that code into your project. Without the "#include" statement the compiler does not find the function you are trying to call.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top