Electrical – MPLAB XC16 not generating .HEX file after successful build

hex filemplabxpic

I am new to MPLAB XC16 IDE. I am generating a simple blinking LED code to understand the basics of the microcontroller PIC24FJ32GA002.

The main file is as follows:

#include <xc.h>
#include <libpic30.h>

#define sysclock 96000000UL
#define FCY sysclock/4

// CONFIG2
#pragma config POSCMOD = XT             // Primary Oscillator Select (XT Oscillator mode selected)
#pragma config I2C1SEL = PRI            // I2C1 Pin Location Select (Use default SCL1/SDA1 pins)
#pragma config IOL1WAY = ON             // IOLOCK Protection (Once IOLOCK is set, cannot be changed)
#pragma config OSCIOFNC = OFF           // Primary Oscillator Output Function (OSC2/CLKO/RC15 functions as CLKO (FOSC/2))
#pragma config FCKSM = CSDCMD           // Clock Switching and Monitor (Clock switching and Fail-Safe Clock Monitor are disabled)
#pragma config FNOSC = FRCDIV           // Oscillator Select (Fast RC Oscillator with Postscaler (FRCDIV))
#pragma config SOSCSEL = SOSC           // Sec Oscillator Select (Default Secondary Oscillator (SOSC))
#pragma config WUTSEL = LEG             // Wake-up timer Select (Legacy Wake-up Timer)
#pragma config IESO = ON                // Internal External Switch Over Mode (IESO mode (Two-Speed Start-up) enabled)

// CONFIG1
#pragma config WDTPS = PS32768          // Watchdog Timer Postscaler (1:32,768)
#pragma config FWPSA = PR128            // WDT Prescaler (Prescaler ratio of 1:128)
#pragma config WINDIS = ON              // Watchdog Timer Window (Standard Watchdog Timer enabled,(Windowed-mode is disabled))
#pragma config FWDTEN = OFF             // Watchdog Timer Enable (Watchdog Timer is disabled)
#pragma config ICS = PGx1               // Comm Channel Select (Emulator EMUC1/EMUD1 pins are shared with PGC1/PGD1)
#pragma config GWRP = OFF               // General Code Segment Write Protect (Writes to program memory are allowed)
#pragma config GCP = OFF                // General Code Segment Code Protect (Code protection is disabled)
#pragma config JTAGEN = OFF             // JTAG Port Enable (JTAG port is disabled)


int main(void) {
    TRISB = 0xFFFF;

    while(1) {
        PORTB = 0xFFFF;
        __delay_ms(1000);
        PORTB = 0x0000;
        __delay_ms(1000);
    }

    return 0;
}

The project builds successfully with this build output:

make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Users/mohsi/MPLABXProjects/PIC24FJ32GA002.X'
make  -f nbproject/Makefile-default.mk dist/default/production/PIC24FJ32GA002.X.a
make[2]: Entering directory 'C:/Users/mohsi/MPLABXProjects/PIC24FJ32GA002.X'
"C:\Program Files (x86)\Microchip\xc16\v1.33\bin\xc16-gcc.exe"   main.c  -o build/default/production/main.o  -c -mcpu=24FJ32GA002  -MMD -MF "build/default/production/main.o.d"        -g -omf=coff -DXPRJ_default=default  -legacy-libc    -O0 -msmart-io=1 -Wall -msfr-warn=off  
"C:\Program Files (x86)\Microchip\xc16\v1.33\bin\xc16-gcc.exe"   system.c  -o build/default/production/system.o  -c -mcpu=24FJ32GA002  -MMD -MF "build/default/production/system.o.d"        -g -omf=coff -DXPRJ_default=default  -legacy-libc    -O0 -msmart-io=1 -Wall -msfr-warn=off  
"C:\Program Files (x86)\Microchip\xc16\v1.33\bin\xc16-ar.exe"   -omf=coff -r dist/default/production/PIC24FJ32GA002.X.a  build/default/production/main.o build/default/production/system.o      
make[2]: Leaving directory 'C:/Users/mohsi/MPLABXProjects/PIC24FJ32GA002.X'
make[1]: Leaving directory 'C:/Users/mohsi/MPLABXProjects/PIC24FJ32GA002.X'

BUILD SUCCESSFUL (total time: 6s)

Yet still the project only compiles .a file in the project folder/dis/default/production folder:

enter image description here

Here are the project properties to show that I am using the correct micro controller using Simulator in MPLAB X IDE using XC16 compiler:

enter image description here

Any help would be appreciated. For context, I need to simulate this microcontroller in Proteus simulator. So need the .HEX file from the project.

Best Answer

It's only creating the .a because your project type is a static library, change the project type to be an Application and it will generate the hex file.