1
\$\begingroup\$

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.

\$\endgroup\$

3 Answers 3

2
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ How can I do this? I have tried going through Project properties, can't find option. \$\endgroup\$
    – Mohsin
    Commented Mar 8, 2018 at 11:45
  • \$\begingroup\$ Project Properties -> Building -> Configuration type (it's a drop down box at the top) \$\endgroup\$
    – Colin
    Commented Mar 8, 2018 at 11:47
0
\$\begingroup\$

I have been trying to compile an already once successfully compiled and one who has generated. What i have noticed is that MPLAB X tries to reset compilation make files and uses object files to link to a hex file. I can switch from a main.c blink file to mine and that is when MPLAB loses its mind. Microchip is still using compiling technology that is randomly losing its mind. As I see here, support is less than accomodating. I am very close to using another MCU..

\$\endgroup\$
0
\$\begingroup\$

I had the same problem. The .hex file is not generated when clicking 'Build'. Instead, you need to click 'Make and Program' to generate the .hex file in the directory (dist/default/production).

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.