Hi Filipe,
About the ansel error. It seems to be in your program, not in a library so I think you should remove those lines.
About the 40 MHz. Do you need 40 MHz using a crystal or is 32 MHz using the internal oscillator sufficient? Below the code I think that should work for 32 MHz but you need to test it. I always use a blink sample program as starting point.
-- This program uses the internal oscillator at 32 MHz.
pragma target clock 32_000_000 -- oscillator frequency
--
pragma target OSC INTOSC_NOCLKOUT -- internal oscillator
pragma target WDT CONTROL -- watchdog
pragma target XINST DISABLED -- do not use extended instructionset
pragma target DEBUG DISABLED -- no debugging
pragma target BROWNOUT DISABLED -- no brownout reset
pragma target FCMEN DISABLED -- no clock monitoring
pragma target IESO DISABLED -- no int/ext osc switching
pragma target LVP ENABLED -- low voltage programming
pragma target MCLR EXTERNAL -- external reset
--
-- The configuration bit settings above are only a selection, sufficient
-- for this program. Other programs may need more or different settings.
--
WDTCON_SWDTEN = OFF -- disable WDT
OSCCON_SCS = 0 -- select primary oscillator
OSCCON_IRCF = 0b111 -- 8 MHz
OSCTUNE_PLLEN = TRUE -- 4xPLL
For 40 MHz it may be something like this. You need a 10 MHz crystal for this configuration:
-- This program assumes that a 10 MHz resonator or crystal
-- is connected to pins OSC1 and OSC2.
pragma target clock 40_000_000 -- oscillator frequency
--
pragma target OSC HS_PLL -- crystal with 4xPLL
pragma target WDT CONTROL -- watchdog
pragma target XINST DISABLED -- do not use extended instructionset
pragma target DEBUG DISABLED -- no debugging
pragma target BROWNOUT DISABLED -- no brownout reset
pragma target FCMEN DISABLED -- no clock monitoring
pragma target IESO DISABLED -- no int/ext osc switching
pragma target LVP ENABLED -- low voltage programming
pragma target MCLR EXTERNAL -- external reset
--
-- The configuration bit settings above are only a selection, sufficient
-- for this program. Other programs may need more or different settings.
--
WDTCON_SWDTEN = OFF -- disable WDT
OSCCON_SCS = 0 -- select primary oscillator
OSCTUNE_PLLEN = TRUE -- 4xPLL
--
Kind regards,
Rob