1. 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.
    Dismiss Notice

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

Discussion in 'Microcontrollers' started by Rich D., Oct 17, 2017.

  1. Rich D.

    Rich D. Member

    Joined:
    Feb 3, 2014
    Messages:
    243
    Likes:
    20
    Location:
    West Chester, PA
    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.
     
  2. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,294
    Likes:
    647
    Location:
    Derbyshire, UK
    ONLINE
    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.
     
  3. Rich D.

    Rich D. Member

    Joined:
    Feb 3, 2014
    Messages:
    243
    Likes:
    20
    Location:
    West Chester, PA
    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.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,294
    Likes:
    647
    Location:
    Derbyshire, UK
    ONLINE

    Why don't you just write the program entirely in assembler?, why use C at all? - I've never had occasion to try and call assembler from within XC16.
     
  6. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,294
    Likes:
    647
    Location:
    Derbyshire, UK
    ONLINE
    • Informative Informative x 1
  7. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,251
    Likes:
    911
    Location:
    Rochdale UK
    In the MPLABX folder "mpasmx" is available for standalone programs... But as everyone else has stated.. you can still use asm only builds in MPLABX..
     
  8. Rich D.

    Rich D. Member

    Joined:
    Feb 3, 2014
    Messages:
    243
    Likes:
    20
    Location:
    West Chester, PA
    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.
     
  9. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,294
    Likes:
    647
    Location:
    Derbyshire, UK
    ONLINE
    Neither do I - I much prefer Pascal to C

    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.
     
  10. Rich D.

    Rich D. Member

    Joined:
    Feb 3, 2014
    Messages:
    243
    Likes:
    20
    Location:
    West Chester, PA
    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.
     
  11. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,251
    Likes:
    911
    Location:
    Rochdale UK
    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..
     
  12. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,829
    Likes:
    138
    Location:
    morristown,tn
    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.
     
  13. Rich D.

    Rich D. Member

    Joined:
    Feb 3, 2014
    Messages:
    243
    Likes:
    20
    Location:
    West Chester, PA
    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.)
     
  14. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,829
    Likes:
    138
    Location:
    morristown,tn
    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
     
  15. jpanhalt

    jpanhalt Well-Known Member Most Helpful Member

    Joined:
    Jun 21, 2006
    Messages:
    5,985
    Likes:
    511
    Location:
    Cleveland, OH, USA
  16. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,251
    Likes:
    911
    Location:
    Rochdale UK
    Can you send / post the asm file so I might try... At least I can point you in the correct direction..
     
  17. Rich D.

    Rich D. Member

    Joined:
    Feb 3, 2014
    Messages:
    243
    Likes:
    20
    Location:
    West Chester, PA
    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 http://forembed.com/xc16-writing-assembly-for-use-in-c.html ?

    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.
     

    Attached Files:

  18. be80be

    be80be Well-Known Member

    Joined:
    Aug 23, 2008
    Messages:
    4,829
    Likes:
    138
    Location:
    morristown,tn
    I just tried to use Mplab X with the 24FJ128GA204 there is no option in mplab x 4.01 for just asm.
     

    Attached Files:

  19. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,084
    Likes:
    326
    Location:
    Brisbane Australia
    ONLINE
    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 (text):

    // 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: Oct 19, 2017
  20. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,251
    Likes:
    911
    Location:
    Rochdale UK
    Same here!! I didn't post last night as it was too late...

    Burt!! I have two options when selecting pic24 / 33 a) MPASM and 2) XC16.. I'm on MPLABX V4.00
     
  21. Nigel Goodwin

    Nigel Goodwin Super Moderator Most Helpful Member

    Joined:
    Nov 17, 2003
    Messages:
    39,294
    Likes:
    647
    Location:
    Derbyshire, UK
    ONLINE
    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.
     

Share This Page