Getting started with xc16 in MPLAB v3.20

Thread Starter

Robin66

Joined Jan 5, 2016
275
Hi

I'm using PIC24F for the first time and so I've installed xc16 (v1.31) and am trying to get going with my old code that was writen for xc8 (PIC18F). I've now spent hours on this and am getting nowhere fast. I'd really appreciate some pointers. I'm sure I'm treading old ground.

This is the first warning I'm getting which I believe shows that the xc16 libs haven't been read correctly. On the previous line I have the below, which is actually highlighted before I build saying it "Cannot find include file", but it doesn't error or warn in the build log

Code:
#include <xc.h>
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Users/Robin/MPLABXProjects/motorcontroller v3.X'
make -f nbproject/Makefile-default.mk dist/default/production/motorcontroller_v3.X.production.hex
make[2]: Entering directory 'C:/Users/Robin/MPLABXProjects/motorcontroller v3.X'
"C:\Program Files (x86)\Microchip\xc16\v1.31\bin\xc16-gcc.exe" main.c -o build/default/production/main.o -c -mcpu=24FV32KA302 -MMD -MF "build/default/production/main.o.d" -g -omf=elf -legacy-libc -O0 -msmart-io=1 -Wall -msfr-warn=off
lcd.h: In function 'Lcd_Cmd':
In file included from main.c:69:0:
lcd.h:30:6: warning: implicit declaration of function '__delay_ms'


However I've found __delay_ms is declared in ...xc16\v1.31\support\generic\h\libpic30.h, with the comment: "They depend on a user-supplied definition of FCY."

So I've started main.c with
Code:
#define FCY 16000000UL
But the problem persists. What should I check next?

Robin
 
Last edited:

Thread Starter

Robin66

Joined Jan 5, 2016
275
Make sure your include directory is set under your compiler settings.
Thanks spinnaker. I added this location as below C:\Program Files (x86)\Microchip\xc16\v1.31\include. The include folder doesn't seem to contain or point to any delay routines tho and it doesn't affect my build error.

upload_2017-3-5_21-45-16.png
 

Thread Starter

Robin66

Joined Jan 5, 2016
275
Ok, I've found that I can get rid of this error by explicitly including libpic30.h as below. I'm not sure I have config'ed xc16 correctly because it doesn't say to do this in the xc16 user manual.

Code:
#include <xc.h>
#include <libpic30.h>
#include "lcd.h"
 

spinnaker

Joined Oct 29, 2009
7,830
You should not need to do that. Not needed in XC8 for sure. Also what is odd in XC8 is you define _XTAL_FREQ not FCY for the delay functions.
 

Thread Starter

Robin66

Joined Jan 5, 2016
275
You should not need to do that. Not needed in XC8 for sure. Also what is odd in XC8 is you define _XTAL_FREQ not FCY for the delay functions.
Yes I used _XTAL_FREQ in my old XC8 project but switched to FCY after reading the XC16 manual.

I've just commented out the FCY declaration but upon building it does not then complain about the __delay_ms() usage, even tho this function is only declared if FCY exists, according to libpic30.h. Something's not right.
 

spinnaker

Joined Oct 29, 2009
7,830
Yes I used _XTAL_FREQ in my old XC8 project but switched to FCY after reading the XC16 manual.

I've just commented out the FCY declaration but upon building it does not then complain about the __delay_ms() usage, even tho this function is only declared if FCY exists, according to libpic30.h. Something's not right.
Yeah I would hope they would be the same. Then again this is microchip. ;)
 
Top