I am trying to run the most simple example of PWM using a PIC18F4550, XC8 compiler and the libraries plib/timers.h and plib/pwm.h
My code is the next:
#include <xc.h>
#include <plib/timers.h>
#include <plib/pwm.h>
//CONFIGURATION BITS...
#pragma config PLLDIV = 5, CPUDIV = OSC1_PLL2, USBDIV = 2
#pragma config FOSC = HSPLL_HS, FCMEN = OFF, IESO = OFF
#pragma config PWRT = OFF, BOR = OFF, VREGEN = OFF
#pragma config WDT = OFF, WDTPS = 32768
#pragma config MCLRE = ON, LPT1OSC = OFF, PBADEN = OFF
#pragma config STVREN = ON, LVP = OFF, ICPRT = OFF, XINST = OFF
#define _XTAL_FREQ 48000000
void main(){
TRISCbits.TRISC2 = 0;
unsigned char prescaler = T2_PS_1_16;
OpenTimer2(prescaler);
OpenPWM1(0x95);
while(1){
SetDCPWM1(300);
}
}
And the diagram of my PIC is:
But I get an error message when trying to compile:
C:\Program Files (x86)\Microchip\xc8\v1.40\include\pic18f4550.h:4426: error: (1098) conflicting declarations for variable "_TRISCbits" (C:\Program Files (x86)\Microchip\xc8\v1.40\include\pic18f4550.h:3829)
(908) exit status = 1
nbproject/Makefile-default.mk:125: recipe for target 'dist/default/production/PWM_code.X.production.hex' failed
make[2]: Leaving directory 'C:/Users/Delfin/Pictures/PIC18F4550 Basics/PWM_code.X'
nbproject/Makefile-default.mk:84: recipe for target '.build-conf' failed
make[1]: Leaving directory 'C:/Users/Delfin/Pictures/PIC18F4550 Basics/PWM_code.X'
make[2]: *** [dist/default/production/PWM_code.X.production.hex] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
BUILD FAILED (exit value 2, total time: 1s)
I have already downloaded and installed the periperial libraries from here: http://www.microchip.com/mymicrochip/filehandler.aspx?ddocname=en574973 and also linked them in my code as I show in the following picture:
So, why is not compiling? When I comment the line:
OpenPWM1(0x95);
works fine. I would appreciate any suggestions. Thanks
1 Answer 1
I have solved my question.
The problem is that I was using the 1.40 version of XC8 compiler. The periperial libraries are not longer supported and were compiled with version 1.34 of MPLAB XC8. Any changes made to header files since those libraries were created could potentially create a declaration mismatch.
What I did was download the former 1.34 version of XC8 ( http://ww1.microchip.com/downloads/en/DeviceDoc/xc8-v1.34-full-install-windows-installer.exe ) and installed it. After that I chose to work with that version of the compiler and my code now works fine
-
\$\begingroup\$ +1 but this is a huge abandonment to users by Microchip \$\endgroup\$Hernan Eche– Hernan Eche2018年07月04日 12:11:05 +00:00Commented Jul 4, 2018 at 12:11
-
\$\begingroup\$ Agreed, I have a number of projects that use 18F4550's , perfectly good MCU, and NOT supported my the new Harmony and MCC stuff, plib just makes things so much easier than having to prat about with direct register manipulation. All MCP are interested in is getting folks on to the next new hotness so they can continue to milk profit from them. \$\endgroup\$shawty– shawty2018年09月10日 21:09:56 +00:00Commented Sep 10, 2018 at 21:09