PIC16F628 - XC8 Compiler - BUILD FAILED - Page 1
Forum section: electronics / general

author: 2X
author_rank: Frequent Contributor
timestamp: June 14, 2025, 02:21:12 pm
content: Hi,I am trying to compile an old MPLABX project where I have made back in 2013 and always give a BUILD FAILED. Unfortunately I can't remember the version of the XC8 compiler and MPLABX where I used back then. Now I tried the versions 1.21, 1.45 & 3.00 of the XC8 compiler but with no one I can make it to build.Also, I create the project from the begging but nothing changed.What I am doing wrong?Code:make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-confmake -f nbproject/Makefile-default.mk dist/default/debug/Car_Temp_Sensor.X.debug.elf(908) exit status = 1make: *** [nbproject/Makefile-default.mk:95: build/default/debug/Car_Temp_Sensor.p1] Error 1make: *** [nbproject/Makefile-default.mk:85: .build-conf] Error 2make: *** [nbproject/Makefile-impl.mk:39: .build-impl] Error 2make: Entering directory 'C:/Users/PC1/Desktop/Car_Temp_Sensor.X'"C:\Program Files (x86)\Microchip\xc8\v1.21\bin\xc8.exe" --pass1 --chip=16F628A -Q -G -D__DEBUG=1 --debugger=none --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,-config,+clib --output=-mcof,+elf "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -obuild/default/debug/Car_Temp_Sensor.p1 Car_Temp_Sensor.cCar_Temp_Sensor.c:8: error: (141) can't open include file "16F628A.h": No such file or directorymake: Leaving directory 'C:/Users/PC1/Desktop/Car_Temp_Sensor.X'BUILD FAILED (exit value 2, total time: 2s)Microchip MPLAB® X IDE v6.25 Will Discontinue Support for Legacy MPLAB PICKit™ 3 In-Circuit Debugger, ICD 3 In-Circuit Debugger and REAL ICE™ In-Circuit Emulator Products—Now What?https://www.microchip.com/en-us/about/media-center/blog/2024/discontinued-ide-support-for-gen3-tools

author: fchk
author_rank: Frequent Contributor
timestamp: June 14, 2025, 02:45:49 pm
content: You are not supposed to include the processer header 16F628A. directly. You only include xc.h which then includes the correct headers.

author: 2X
author_rank: Frequent Contributor
timestamp: June 14, 2025, 04:27:58 pm
content: Thanks foy your reply.I have include the: #include <16F628A.h> (or you mean something else?)

author: voltsandjolts
author_rank: Unknown
timestamp: June 14, 2025, 04:31:28 pm
content: No, @fchk means remove that include, so all you have is:#include <xc.h>Then make sure your project settings are set to 16F628A, so the appropriate include file is included automatically.

author: 2X
author_rank: Frequent Contributor
timestamp: June 14, 2025, 04:45:02 pm
content: Quote from: voltsandjolts on June 14, 2025, 04:31:28 pmI have already use only with the "#include <xc.h>" and still I can't make a succesful build.Code:make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-confmake -f nbproject/Makefile-default.mk dist/default/debug/Car_Temp_Sensor.X.debug.elfmake: Entering directory 'C:/Users/PC1/Desktop/Car_Temp_Sensor.X'"C:\Program Files (x86)\Microchip\xc8\v1.21\bin\xc8.exe" --pass1 --chip=16F628A -Q -G -D__DEBUG=1 --debugger=none --double=24 --float=24 --opt=+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-osccal,-resetbits,-download,-stackcall,-config,+clib --output=-mcof,+elf "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -obuild/default/debug/Car_Temp_Sensor.p1 Car_Temp_Sensor.cCar_Temp_Sensor.c:30: warning: (107) illegal # directive "use"Car_Temp_Sensor.c:30: warning: (163) unexpected text in control line ignoredCar_Temp_Sensor.c:31: warning: (107) illegal # directive "byte"Car_Temp_Sensor.c:31: warning: (163) unexpected text in control line ignoredCar_Temp_Sensor.c:32: warning: (107) illegal # directive "byte"Car_Temp_Sensor.c:32: warning: (163) unexpected text in control line ignoredCar_Temp_Sensor.c:34: warning: (107) illegal # directive "bit"Car_Temp_Sensor.c:34: warning: (163) unexpected text in control line ignoredCar_Temp_Sensor.c:35: warning: (107) illegal # directive "bit"Car_Temp_Sensor.c:35: warning: (163) unexpected text in control line ignoredCar_Temp_Sensor.c:36: warning: (107) illegal # directive "bit"Car_Temp_Sensor.c:36: warning: (163) unexpected text in control line ignoredCar_Temp_Sensor.c:37: warning: (107) illegal # directive "bit"Car_Temp_Sensor.c:37: warning: (163) unexpected text in control line ignoredCar_Temp_Sensor.c:38: warning: (107) illegal # directive "bit"Car_Temp_Sensor.c:38: warning: (163) unexpected text in control line ignoredCar_Temp_Sensor.c:221: warning: (107) illegal # directive "bit"Car_Temp_Sensor.c:221: warning: (163) unexpected text in control line ignoredCar_Temp_Sensor.c:222: warning: (107) illegal # directive "bit"Car_Temp_Sensor.c:222: warning: (163) unexpected text in control line ignoredCar_Temp_Sensor.c:11: error: (1363) unknown configuration setting/register (OSC = HS) usedCar_Temp_Sensor.c:13: error: (1363) unknown configuration setting/register (PWRT = ON) usedCar_Temp_Sensor.c:59: warning: (374) missing basic type; int assumedCar_Temp_Sensor.c:59: error: (314) ";" expectedCar_Temp_Sensor.c:70: error: (372) "," expectedCar_Temp_Sensor.c:71: warning: (349) non-prototyped function declaration for "lcd_send_nibble"Car_Temp_Sensor.c:74: warning: (361) function declared implicit intCar_Temp_Sensor.c:74: error: (192) undefined identifier "PIN_B4"Car_Temp_Sensor.c:75: error: (192) undefined identifier "PIN_B5"Car_Temp_Sensor.c:76: error: (192) undefined identifier "PIN_B6"Car_Temp_Sensor.c:77: error: (192) undefined identifier "PIN_B7"Car_Temp_Sensor.c:79: warning: (361) function declared implicit intCar_Temp_Sensor.c:80: warning: (361) function declared implicit intCar_Temp_Sensor.c:80: error: (192) undefined identifier "PIN_B2"Car_Temp_Sensor.c:81: warning: (361) function declared implicit intCar_Temp_Sensor.c:82: warning: (361) function declared implicit intCar_Temp_Sensor.c:89: error: (372) "," expectedCar_Temp_Sensor.c:89: error: (278) argument "int8" redeclaredCar_Temp_Sensor.c:89: error: (372) "," expectedCar_Temp_Sensor.c:90: warning: (349) non-prototyped function declaration for "lcd_send_byte"Car_Temp_Sensor.c:91: error: (192) undefined identifier "PIN_B3"Car_Temp_Sensor.c:111: error: (192) undefined identifier "PIN_B2"Car_Temp_Sensor.c:115: error: (254) undefined variable: "n"Car_Temp_Sensor.c:115: error: (254) undefined variable: "address"Car_Temp_Sensor.c:122: error: (195) expression syntaxCar_Temp_Sensor.c:124: error: (192) undefined identifier "PIN_B3"Car_Temp_Sensor.c:130: error: (192) undefined identifier "PIN_B2"Car_Temp_Sensor.c:134: error: (192) undefined identifier "i"Car_Temp_Sensor.c:142: error: (192) undefined identifier "LCD_INIT_STRING"Car_Temp_Sensor.c:142: advisory: (1) too many errors (21)make: Leaving directory 'C:/User/PC1/Desktop/Car_Temp_Sensor.X'(908) exit status = 1make: *** [nbproject/Makefile-default.mk:95: build/default/debug/Car_Temp_Sensor.p1] Error 1make: *** [nbproject/Makefile-default.mk:85: .build-conf] Error 2make: *** [nbproject/Makefile-impl.mk:39: .build-impl] Error 2BUILD FAILED (exit value 2, total time: 2s)Also, I have too many red and yellow underline markings.

author: MarkF
author_rank: Super Contributor
timestamp: June 14, 2025, 06:08:51 pm
content: For the configuration errors, use the 'Configuration Bits' tool. Open the Config Tools window, make your selections, and cut-and-paste from the 'Output' window into the top of your code before the #include <xc.h>.If you want to use the delay_ms() and delay_us() functions, I defined the following code:Example for 32MHz master clock. For the built-in 'delays' to work, you NEED to define _XTAL_FREQ.Code:#define _XTAL_FREQ 32000000L#define delay_us(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000000.0)))#define delay_ms(x) _delay((unsigned long)((x)*(_XTAL_FREQ/4000.0)))For reading and writing pins, you can setup some #defines and then just do an assignment:Code:#define IORDpin LATBbits.LATB0#define IORDtris TRISBbits.TRISB0#define IOWRpin LATBbits.LATB5#define IOWRtris TRISBbits.TRISB5#define IOACKpin PORTAbits.RA4#define IOACKtris TRISAbits.TRISA4#define IOACK2pin PORTCbits.RC2#define IOACK2tris TRISCbits.TRISC2#define SPI_CSpin LATAbits.LATA5#define SPI_CStris TRISAbits.TRISA5ThenCode:SPI_CSpin = 1; // set CS- pin highSPI_CStris = 0; // CS- pin as outputTRISCbits.TRISC3 = 0; // SCK pin as outputTRISCbits.TRISC4 = 1; // SDI pin as inputTRISCbits.TRISC5 = 0; // SDO pin as outputYOU ARE AWARE WHEN YOU NEED TO USE THE 'PORT' REGISTER OR 'LAT' REGISTER DEPENDING ON WHICH PIC YOU'RE USING!!!

author: up8051
author_rank: Frequent Contributor
timestamp: June 14, 2025, 06:26:29 pm
content: #use, #byte, #bit etc. were used by CCS compiler, not XC8 compiler.You need to migrate from CCS to XC8

author: mariush
author_rank: Super Contributor
timestamp: June 14, 2025, 07:05:15 pm
content: You can define byte data type, instead of doing search and replace in your files ... I used unsigned char, unsigned short etc etc ... you can look in theIn my projects, I didn't use the built in _delay function, instead wrote my own ... downside is that you have to tweak the function for specific frequency you're gonna use. You shouldn't waste cpu cycles with delays longer than a few ms, if you need more than that use timers and/or interrupts and use the cpu to do something else in the meantime.You have the instruction set of PIC16F628 here, at page 118https://ww1.microchip.com/downloads/en/DeviceDoc/40044G.pdf- most instructions use 1 cycle, some use 2 cycles - each cycle is 4 ticks or 4 Hz...So you can do something like this (code below was for a pic18f chip, but the nop and goto should use the same amount of cycles) :delay.h :Code:#ifndef __DELAYH_INIT#define __DELAYH_INIT#define delay_1tcy() asm("nop")#define delay_2tcy() asm("goto $+1")#define delay_4tcy() asm("goto $+1");asm("goto $+1");#define delay_10tcy() delay_2tcy();delay_4tcy();delay_4tcy();// These are valid for 16 Mhz - for example at 16 Mhz the micro does 4 cycles in 1uS , hence the delay_1us = delay_4tcy();// At 32 Mhz, you'd define delay_8tcy() delay_4tcy();delay_4tcy(); and then delay_1us() = delay_8tcy()#define delay_500ns() delay_2tcy();#define delay_1us() delay_4tcy();#define delay_4us() delay_1us();delay_1us();delay_1us();delay_1us();#define delay_5us() delay_4us();delay_1us();#define delay_10us() delay_5us();delay_5us();extern void delay_1ms();// for up to 255 msextern void delay_ms(unsigned char ms);and delay.cCode:void delay_1ms(){unsigned char n = 248;do {asm("goto $+1"); asm("goto $+1"); asm("goto $+1");asm("goto $+1"); asm("goto $+1"); asm("goto $+1");asm("nop");// decrease if not zero - decfsz (1 cycle if !=0, 2 cycles otherwise)// goto loop start = 2 cycles} while(--n);// = 16 cycles x [n+1] + 1 (from last decfsz) - 2 (last goto is skipped)// 249x16+1-2 = 3983 cycles (1 = decfsz ), -2 for last goto// + 1 = 3984 cycles (assignment of 248 to n)// + 4 = 3988 cycles (function call and return)delay_2tcy(); // = 3990 cyclesdelay_10tcy(); // = 4000 cycles = 1 ms at 16 Mhz}

author: mikeselectricstuff
author_rank: Super Contributor
timestamp: June 14, 2025, 07:10:22 pm
content: if migrating old C code, check you have C90 set as the C standard in XC8 global options - C99 is default and IME causes some errors with old code

author: 2X
author_rank: Frequent Contributor
timestamp: June 14, 2025, 11:42:16 pm
content: Finally I make a succeded build with CCS compiler (CCS PCWHD v5.008). I have attached the new code if anyone will need help in the future.Thanks all of you for the help.