Build Failures after updating MPLabX and XC8

Thread Starter

ke5nnt

Joined Mar 1, 2009
384
Good Day All,

I recently updated to newer versions of MPLabX and XC8 C compiler. C compiler was version 1.12, updated that to 1.33B. I don't remember what version MPLab X was prior to updating, but it is now version 2.26. I backed up my project files and all prior to updating, and then uninstalled MPLAB, XC8, PICC, etc. Then I installed MPLabX and then finally installed the XC8 compiler (that was my update order).

After doing so, I attempted to write an extremely simple program to demonstrate the software to someone and am now getting failure on build. The program is below, as are the failures. At first, I had noticed that the xc.h file was still pointing to the 1.12 version folder, so I updated those to the new location, which solved those errors. I also changed the compiler setting in the MPLAB options to the new 1.33 version, so that should not be the cause of the issue. Maybe it has just been a while since I wrote a program and my code is the issue, however, I basically copied from an old program that I know used to compile with no issues in the older versions, which is now not compiling. Any ideas? Thanks!

Please note that the __delay_ms(500) seems to be the cause of the failure. Compiles fine without that, but I've checked the user manual and seem to be meeting all the requirements for using it. I've also checked the pic.h file which includes notes about using __delay_ms(x).
This code was written for the PIC12F629

Code:
#include <xc.h>

#pragma config BOREN = OFF, MCLRE = OFF, PWRTE = ON, WDTE = OFF, FOSC = INTRCIO

#define _XTAL_FREQ = 4000000

void main()
{
  TRISIO = 0b00001000;
  GPIO = 0;

  while(1)
  {
  GP0 = 1;
  __delay_ms(500);
  GP0 = 0;
  }
}
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Users/Ryan/MPLABXProjects/learnc_test.X'
make -f nbproject/Makefile-default.mk dist/default/production/learnc_test.X.production.hex
make[2]: Entering directory 'C:/Users/Ryan/MPLABXProjects/learnc_test.X'
"C:\Program Files (x86)\Microchip\xc8\v1.33\bin\xc8.exe" --pass1 --chip=12F629 -Q -G --double=24 --float=24 --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -obuild/default/production/learnc_test.p1 learnc_test.c
learnc_test.c:15: error: (195) expression syntax
learnc_test.c:15: error: (187) too few function arguments
learnc_test.c:15: error: (194) ")" expected
learnc_test.c:15: error: (195) expression syntax
(908) exit status = 1
make[2]: *** [build/default/production/learnc_test.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
nbproject/Makefile-default.mk:94: recipe for target 'build/default/production/learnc_test.p1' failed
make[2]: Leaving directory 'C:/Users/Ryan/MPLABXProjects/learnc_test.X'
nbproject/Makefile-default.mk:78: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/Ryan/MPLABXProjects/learnc_test.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed

BUILD FAILED (exit value 2, total time: 541ms)
 

djsfantasi

Joined Apr 11, 2010
5,621
What happens if you use a parameter less than 500? 255 for example. There often are limits on the delay functions and it may be causing you problems. Try it!

Spinnaker beat me to it :)
 

Thread Starter

ke5nnt

Joined Mar 1, 2009
384
Yes I had thought of that prior to posting the issue, attempting to use a smaller argument. I attempted 5, and 50, and 500, all of which produced the same errors. Should have mentioned that in the original post.
 

spinnaker

Joined Oct 29, 2009
7,815
Are you certain __delay_ms is in one of your header files?

If it is, does the function in the header have the signature that you expect?

What are the lines causing the errors? All you list is line numbers and that is of no help.
 

Thread Starter

ke5nnt

Joined Mar 1, 2009
384
All errors point to line 15, which is the __delay_ms(500);
I have successfully used 500 in several other programs prior to my updating the software. Seems that during my uninstall/update cycle, I had uninstalled the Hi-Tech PICC lite package. Looking through the header files, I included <xc.h> which #includes <htc.h> which includes this:
Code:
/* HI-TECH PICC / PICC-Lite compiler */
#if   defined(__PICC__) || defined(__PICCLITE__)
#include <pic.h>
#endif
Not sure if XC8 includes PICC but if it does not, it may be possible that the <pic.h> file is not included, and this is causing the issue?
<pic.h> is the file which defines the delay routines.
Code:
#ifdef __PICC__
/****************************************************************/
/* Built-in delay routine           */
/****************************************************************/
#pragma intrinsic(_delay)
extern __nonreentrant void _delay(unsigned long);
// NOTE: To use the macros below, YOU must have previously defined _XTAL_FREQ
#define __delay_us(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000000.0)))
#define __delay_ms(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000.0)))
#endif
Searching for PICC brings me to a microchip.com page which specifies "Microchip highly recommends the MPLAB XC8 C Compiler (SW006021-2) for new designs."
 

JohnInTX

Joined Jun 26, 2012
3,810
#define _XTAL_FREQ = 4000000
.. should not have the = sign. _XTAL_FREQ is a macro that will be substituted as raw text - in this case '= 4000000' where the delay functions/macros expect a simple number.

Welcome back, by the way.
 

Thread Starter

ke5nnt

Joined Mar 1, 2009
384
Spinnaker, thank you for all the assistance in trying to help me solve the issue.

.. should not have the = sign. _XTAL_FREQ is a macro that will be substituted as raw text - in this case '= 4000000' where the delay functions/macros expect a simple number.

Welcome back, by the way.
Oh dear God, I can't believe it was that simple. I guess when you take a break from programming like that, it does indeed involve a learning curve. Thanks for noticing my return, great to hear from you!

Moral of this story, the error is my fault. Goes to show how frustrating programming can be. I've spent 3 hours trying to fix an equals sign.
 

spinnaker

Joined Oct 29, 2009
7,815
Oh dear God, I can't believe it was that simple. I guess when you take a break from programming like that, it does indeed involve a learning curve. Thanks for noticing my return, great to hear from you!

Moral of this story, the error is my fault. Goes to show how frustrating programming can be. I've spent 3 hours trying to fix an equals sign.

Don't feel bad. I did not see it either. And I have made the same dumb mistake. :)
 

JohnInTX

Joined Jun 26, 2012
3,810
Moral of this story, the error is my fault. Goes to show how frustrating programming can be. I've spent 3 hours trying to fix an equals sign.
Don't be too hard on yourself. There isn't any direct connection at the source level and sometimes its not immediately apparent how library routines are constructed and what macros they use. I happen to know how _delay works at the code level. Now you do as well.
Nice.
 
Top