Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Assembly on the MPLAB-X IDE, how???

Status
Not open for further replies.

Rich D.

Active Member
Please excuse me if this was mentioned and addressed already, I looked and looked and didn't find anything...
I want to program a PIC24FJGA204 chip using MPLAB-X IDE (v4.00). I have a sample code that downloads and runs correctly on the unit (a PIC24F Curiosity Development board). Of course that is written in C (might as well be Greek). I can't seem to figure out how to get a Microchip Demo C program to call and execute assembly code. Microchip of course brags all over the place it can be done but doesn't seem to show me how! Seems they are really trying to screw the assembly coders out there. I would switch brands but I already have board designs committed to PIC24s.

I added a small sample .s file to the project with some assembly code. It compiles but shows no errors, and runs but doesn't execute any assembly code (which would take over and flash an LED and never return.) I didn't expect it to though, as I have never seen how to "declare" or tell the software to run this assembly. I figure it should be in a header or build file or something but what do I need to add and where? All my dreams would come true if somebody has a project example that does something simple in assembly such as flip an LED on a PIC24 that will compile and run with MPLAB-X. That really is all I need to get started. Once I have control over the chip I am confident I can get it to do all kinds of tricks for me.

For those who would just recommend I use C, Insult me if you must, but I am not good in C, I don't really get it, I used it for work but I don't like it, never did, never will. I have successfully developed many applications in Microchip Assembly for various dsPICs and I am comfortable with it, I will be able to kik-ass with it, so I want to use it. In fact I *need* to use it, as I have promised two companies that I will develop code with these PIC24FJ chips, and now that my old MPLAB IDE v7.xx won't support these newer, better chips, I am screwed unless I figure out how to get this d$%& MPLAB-X software to do what the old 7.xx software did so well...assembly.
 
I'm not quite sure what you're asking?.

Is it how to call assembler routines from within C?, or how to use assembler (on it's own) on the 24F series?.

Personally, as a VERY long time assembler programmer, I'm now tending to use C instead - and have never used assembler on the 24F series. I've always hated C, tried to learn it a number of times over the decades, and don't claim to be any good with it even now, but I can write working code.
 
Is it how to call assembler routines from within C

Yes. I have the demo C code. I don't know how to get it to execute my assembly code in a .s file. How can I get the C code to execute assembly. The microchip commands #asm and #endasm or asm() simply insert in-line code as I understand it. I want to go into my code and never come back. It appears it never goes and executes my code.
 
That link could be exactly what I have been looking for in many hours of internet searches! Thanks, I will have to check it out.

P.S. I wouldn't go near C if I can avoid it. I don't like all those shift-*{)%& characters everywhere!
I never needed to use it in the past.
Since I can't seem to get MPLAB-X to do an assembly project, I thought that at least I could "trick" the compiler into doing my assembly code as part of a C project.
Just between you and me though, I wouldn't write a single line of C.
 
P.S. I wouldn't go near C if I can avoid it. I don't like all those shift-*{)%& characters everywhere!

Neither do I - I much prefer Pascal to C

Since I can't seem to get MPLAB-X to do an assembly project,

Don't you simply select MPASM when you are asked which compiler you want to use?, or change it afterwards from Project Properties?. I think it's going to be more difficult trying to do both.
 
But as everyone else has stated.. you can still use asm only builds in MPLABX.

Yes, Microchip and everyone else has stated that. My question is HOW? I suspect I need a header file in C, but I don't know how to write one of them because I don't know what 'C' wants.
 
Why are you going on about C.... Just do ASM... Start a new project and select ASM as your tool!!

If you want to write functions in asm, then call them in C just put an underscore before the function..

Truth is... We're not sure what you are after.. A) a skeletal C program using asm, or B) asm only as you did in MPLAB IDE v8..
 
Asm works fine in Mplab X don't have to use xc16 only problem I've found is for some reason some older chips don't have pin's name as they was before X
But the new 4.01 had even that fixed
I don't C myself but some of these chips setting them up is a big job. So if MMC works with this I use it to find the names and most stuff not that bad then
uart i2c spi adc timers all get easy.
 
Let me re-state the question:

1) I wish to write an assembly program for PIC24F.
2) I am using MPLAB-X 4.00
3) I have a file with assembly code written. It works on older 16 bit processors.
4) When I create an MPLAB-X project and add this assembly file it will not compile. It does not have the proper headers or declares or whatever-it-needs.
5) When I attempt to embed this file into a simple C project, it compiles but does not execute on the target chip.
6) I need to create a header, or a call, or a graduated-fiddlesig*.
7) * A graduated-fiddlesig is this undefined entity that causes an assembly file to be compiled and executed. I don't know what it is - that is the root question.

Fundamentally I could care less whether it is 100% assembly or called from C or Fortran or via an old Howdy-Doody TV show rerun or anything.

I only want to get that assembly code to execute on the PIC24F and I don't care how.


If there is even one example out there of a simple project that can compile and execute assembly code, I can use it. Does anybody know of or have an example or sample to share?
(I am starting to believe it does not exist.)
 
You can use your file but you'll still have to make sure the names are right
Mplab works different on Windows Linux it's very picky about name case
But if you want I'll post u a project that uses asm and is call from a header file in the main loop of c program
 
That would be awesome if you could help me with this!
Can I offer you a reward to further motivate you?

I don't have the file with me now, but how about the assembly code that Nigel pointed me to with **broken link removed** ?

It wouldn't let me post AssemblyFileExample.s file so I added the .txt extension.
If that doesn't help, then perhaps AssemblyFileBlinkLED.s.txt could help. It is a simple blink for the development board that I typed in but I can't confirm it compiles ok, but at least it has the LED output pins I'm attempting to use. (Port A, pins 9,10).

What I hope to learn/find/get/understand is some other file(s), headers, instructions or whatever to get this thing to compile and execute. I'm using a PIC24FJ128GA204 on an unmodified Microchip Curiosity Development board.
 

Attachments

  • AssemblyFileExample.s.txt
    795 bytes · Views: 314
  • AssemblyFileBlinkLED.s.txt
    1.3 KB · Views: 304
I just tried to use Mplab X with the 24FJ128GA204 there is no option in mplab x 4.01 for just asm.
 

Attachments

  • MPLAB_XC16_Asm_Link_Users_Guide.pdf
    1.8 MB · Views: 416
I just installed XC16 and did the following,

Added a new project with PIC24FJ128GA204 selected.
Added a newmain.c file.
Opened the config window.
Generated the config source code and added it to the top of newmain.
Added a newAsmTemplate.s and copied the above example to it.

It compiled without complaint.

Mike.
Edit, with the Simulator selected I was able to single step through the asm code.
I think the thing you were missing is the prototype of _add and the call to it.
The complete newmain.c is,
Code:
// PIC24FJ128GA204 Configuration Bit Settings

// 'C' source line config statements

// CONFIG4
#pragma config DSWDTPS = DSWDTPS1F      // Deep Sleep Watchdog Timer Postscale Select bits (1:68719476736 (25.7 Days))
#pragma config DSWDTOSC = LPRC          // DSWDT Reference Clock Select (DSWDT uses LPRC as reference clock)
#pragma config DSBOREN = ON             // Deep Sleep BOR Enable bit (DSBOR Enabled)
#pragma config DSWDTEN = ON             // Deep Sleep Watchdog Timer Enable (DSWDT Enabled)
#pragma config DSSWEN = ON              // DSEN Bit Enable (Deep Sleep is controlled by the register bit DSEN)
#pragma config PLLDIV = DISABLED        // USB 96 MHz PLL Prescaler Select bits (PLL Disabled)
#pragma config I2C1SEL = DISABLE        // Alternate I2C1 enable bit (I2C1 uses SCL1 and SDA1 pins)
#pragma config IOL1WAY = ON             // PPS IOLOCK Set Only Once Enable bit (Once set, the IOLOCK bit cannot be cleared)

// CONFIG3
#pragma config WPFP = WPFP127           // Write Protection Flash Page Segment Boundary (Page 127 (0x1FC00))
#pragma config SOSCSEL = ON             // SOSC Selection bits (SOSC circuit selected)
#pragma config WDTWIN = PS25_0          // Window Mode Watchdog Timer Window Width Select (Watch Dog Timer Window Width is 25 percent)
#pragma config PLLSS = PLL_PRI          // PLL Secondary Selection Configuration bit (PLL is fed by the Primary oscillator)
#pragma config BOREN = ON               // Brown-out Reset Enable (Brown-out Reset Enable)
#pragma config WPDIS = WPDIS            // Segment Write Protection Disable (Disabled)
#pragma config WPCFG = WPCFGDIS         // Write Protect Configuration Page Select (Disabled)
#pragma config WPEND = WPENDMEM         // Segment Write Protection End Page Select (Write Protect from WPFP to the last page of memory)

// CONFIG2
#pragma config POSCMD = NONE            // Primary Oscillator Select (Primary Oscillator Disabled)
#pragma config WDTCLK = LPRC            // WDT Clock Source Select bits (WDT uses LPRC)
#pragma config OSCIOFCN = OFF           // OSCO Pin Configuration (OSCO/CLKO/RA3 functions as CLKO (FOSC/2))
#pragma config FCKSM = CSDCMD           // Clock Switching and Fail-Safe Clock Monitor Configuration bits (Clock switching and Fail-Safe Clock Monitor are disabled)
#pragma config FNOSC = FRCDIV           // Initial Oscillator Select (Fast RC Oscillator with Postscaler (FRCDIV))
#pragma config ALTCMPI = CxINC_RB       // Alternate Comparator Input bit (C1INC is on RB13, C2INC is on RB9 and C3INC is on RA0)
#pragma config WDTCMX = WDTCLK          // WDT Clock Source Select bits (WDT clock source is determined by the WDTCLK Configuration bits)
#pragma config IESO = ON                // Internal External Switchover (Enabled)

// CONFIG1
#pragma config WDTPS = PS32768          // Watchdog Timer Postscaler Select (1:32,768)
#pragma config FWPSA = PR128            // WDT Prescaler Ratio Select (1:128)
#pragma config WINDIS = OFF             // Windowed WDT Disable (Standard Watchdog Timer)
#pragma config FWDTEN = ON              // Watchdog Timer Enable (WDT enabled in hardware)
#pragma config ICS = PGx1               // Emulator Pin Placement Select bits (Emulator functions are shared with PGEC1/PGED1)
#pragma config LPCFG = OFF              // Low power regulator control (Disabled - regardless of RETEN)
#pragma config GWRP = OFF               // General Segment Write Protect (Write to program memory allowed)
#pragma config GCP = OFF                // General Segment Code Protect (Code protection is disabled)
#pragma config JTAGEN = ON              // JTAG Port Enable (Enabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>

void add(void);

void main(void) {
    add();
}
 
Last edited:
I've just tried it as well, I only get the options for XC16 (the three different versions on my computer), no MPASM for 24F - but you do get MPASM offered for 16F and 18F.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top