• AVR Freaks
Reply to post

Hot!16 bit newbe!

Author
F6EEQ
Starting Member
  • Total Posts : 55
  • Reward points : 0
  • Joined: 2010/01/02 02:11:50
  • Location: F-26300 CHATUZANGE
  • Status: offline
2019/12/05 06:55:23 (permalink)
0

16 bit newbe!

Hi all,
I have a fairly good knowledge of 8 bits PIC µ and I wanted to have a try at 16 bits, just for fun.
So I bought a curiosity card DM240016.
 
I have one question: with 8 bits I did a lot of assembly programs.
For 16 bits it seems that C is more universally used, and I must say that the instruction set is... wider, so assembly could be difficult (?)
Do I have to really go to C, which is not a big problem, but another way to do things.
 
Also lots of µchip example use MCC, but I find (at least for 8 bits) that the generated code is "big" and somewhat unclear.
Is it more or less mandatory, regarding the amount of chip capability, or is it relatively easy to do it "by hand"?
 
Thanks for advice, and I may come back for further questions.
Regards, Gerard.

73 de Gerard F6EEQ
8 bit: with Curiosity card, Gooligum card + PICKit3
16 bit: with Curiosity card

12 Replies Related Threads

    NKurzman
    A Guy on the Net
    • Total Posts : 18145
    • Reward points : 0
    • Joined: 2008/01/16 19:33:48
    • Location: 0
    • Status: online
    Re: 16 bit newbe! 2019/12/05 07:19:59 (permalink)
    0
    You can program 16 or even 32 bit PICs in ASM if you choose.
    C is more common in all small CPUs these days than ASM.
    Note for the PIC24 the assembler is part of the C compiler.
    Yes MCC generates big code. It is what happens when you try to be all things to all people.
    No, it is not required to use MCC
    Except maybe for things like USB and TCP/IP.
    F6EEQ
    Starting Member
    • Total Posts : 55
    • Reward points : 0
    • Joined: 2010/01/02 02:11:50
    • Location: F-26300 CHATUZANGE
    • Status: offline
    Re: 16 bit newbe! 2019/12/05 08:13:27 (permalink)
    0
    OK Thanks for info.
     
    Will see what comes out!
     
    cheers.

    73 de Gerard F6EEQ
    8 bit: with Curiosity card, Gooligum card + PICKit3
    16 bit: with Curiosity card
    nigelwright7557
    Super Member
    • Total Posts : 322
    • Reward points : 0
    • Joined: 2006/11/06 08:15:51
    • Location: 0
    • Status: offline
    Re: 16 bit newbe! 2019/12/05 08:25:47 (permalink)
    0
    On 8 bit u's with a few instructions Assembler is fine.
    Once you get into u's with big complex instruction sets they arent really designed to be used with Assembler.
    So I keep assembler for 8 bit PIC's and C for the rest.
    C often comes with a massive repository of functions and these can be really useful.
    Try doing floating point in assembler and you will soon come running to C.
    Its horses for courses.
    I write for PIC12F508 and also for Windows 10 pc's and wouldnt use C on the PIC or assembler on the PC.
     
     
     
    NorthGuy
    Super Member
    • Total Posts : 5869
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: 16 bit newbe! 2019/12/05 08:53:58 (permalink)
    0
    The bigger and richer instruction set in PIC24 makes programming in assembler easier. However, in Microchip assembler, macros are less powerful than in MPASM and quite buggy as well.
     
    XC16 is based on GCC and since the instruction set in PIC24 is different from what GCC usually deals with, the resulting code is not very efficient compared to what you would write in assembler.
     
    It's up to you if you want C or assembler. I'd say it depends on the task. Some things are easier done in C, others can only be done in assembler.
     
    F6EEQ
    Starting Member
    • Total Posts : 55
    • Reward points : 0
    • Joined: 2010/01/02 02:11:50
    • Location: F-26300 CHATUZANGE
    • Status: offline
    Re: 16 bit newbe! 2019/12/06 09:25:29 (permalink)
    0
    Thanks to all for info.
     
    I found sone interesting documents with the help of the forum.
    I have a very basic question about assembly.
     
    With 8 bits, you invoke MPASM when you set-up your project.
    With 16bits, you have only XC16 to choose for. I understood that ASM is embedded in XC16, but I did not find how to begin an ASM program.
    With MPASM you just begin with config, define, eventually interrupt code, and then directly the code.
     
    How do you begin ASM file with XC16?
    In "introduction to microcontrollers lab manual" (DS51963A) there are a lot of interesting things, but nowhere a practical full example.
     
    For C programs I found what I needed in "developer help" wiki, but not for assembly.
    Thanks to all for help.

    73 de Gerard F6EEQ
    8 bit: with Curiosity card, Gooligum card + PICKit3
    16 bit: with Curiosity card
    KTrenholm
    Super Member
    • Total Posts : 753
    • Reward points : 0
    • Joined: 2012/08/08 14:04:23
    • Location: Connecticut, USA
    • Status: offline
    Re: 16 bit newbe! 2019/12/06 09:32:55 (permalink)
    0
    Well for simple inline assembly you can just do:
     

     
    asm("ASSEMBLY LINE GOES HERE");
     

     
    You should also be able to have assembly files (*.s) (*.S - Capital "S" - as MBedder pointed out below) in your project.
    See: http://forembed.com/xc16-...mbly-for-use-in-c.html
     
    post edited by KTrenholm - 2019/12/06 09:44:21
    MBedder
    Circuit breaker
    • Total Posts : 6817
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: 16 bit newbe! 2019/12/06 09:40:22 (permalink)
    0
    Make sure your assembly file has an .S (capital!) extension and just compile your assembly only project witn XC16 compiler.
    F6EEQ
    Starting Member
    • Total Posts : 55
    • Reward points : 0
    • Joined: 2010/01/02 02:11:50
    • Location: F-26300 CHATUZANGE
    • Status: offline
    Re: 16 bit newbe! 2019/12/06 09:51:23 (permalink)
    0
    OK Will give it a try as soon as I receive my Curiosity card.
    Thanks

    73 de Gerard F6EEQ
    8 bit: with Curiosity card, Gooligum card + PICKit3
    16 bit: with Curiosity card
    1and0
    Access is Denied
    • Total Posts : 10195
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: 16 bit newbe! 2019/12/06 09:59:10 (permalink)
    0
    The asm() is for embedding inline assembly code inside a C program. I think OP wants to program pure 16-bit assembly code, so here are some assembly template files from MBedder: https://www.microchip.com/forums/FindPost/1102359
     
    By the way, the reason for using capital "S" extension is so that the C preprocessor can be used.
    rodims
    Super Member
    • Total Posts : 1533
    • Reward points : 0
    • Joined: 2009/02/10 11:08:59
    • Location: 51.9627, 7.6262
    • Status: offline
    Re: 16 bit newbe! 2019/12/06 10:37:01 (permalink)
    0
    Do I have to really go to C, which is not a big problem, but another way to do things.

     
    As explained, you don't have to.
    A question is, why you would consider to use Assembler on a 16 bit (e.g. PIC24) CPU. 
    In my opinion there is no need to program your PIC24FJ256GA705 (256k Flash 16k RAM) in assembler unless you have some reason to do so.
    This may be
    - lack of C knowledge
    - desire to learn the PIC24 assembly
    - speed/performance requirements
    Apart from that it is not necessary to finally decide for C "OR" assembler in a project.
    You can use C for the major parts (e.g. 90 %) of your application and choose to add source files (.s extension) with manually optimized assembly functions (not inline assembly), if you cannot reach a desired performance with the C compilers output.   It's possible to review the compilers generated assembly output by generating a mixed C source / assembler listing.
    For the free xc16 compiler you are limited to the Optimization level 1, which should be good enough for many applications and especially for learning.
     
    post edited by rodims - 2019/12/06 10:39:16
    F6EEQ
    Starting Member
    • Total Posts : 55
    • Reward points : 0
    • Joined: 2010/01/02 02:11:50
    • Location: F-26300 CHATUZANGE
    • Status: offline
    Re: 16 bit newbe! 2019/12/07 02:10:32 (permalink)
    0
    OK Rodims
     
    I understood from what I read, that C is widely used for 16bits chips.
     
    I'm not a guru of C, but I know enough to do relatively good programming, at least for a hobbyist willing to learn, and make some small projects. I have some C experience with 8 bit Pics from Gooligum tutorials.
    In the future, I would also have a try at the DsPic, so C is mandatory as soon as you try to make some mathematics.
     
    Thanks for advice.
    Will come back with some more precise questions, as soon as I have understood the tutorials in Developper Help Wiki.
     
    Have a nice WE.

    73 de Gerard F6EEQ
    8 bit: with Curiosity card, Gooligum card + PICKit3
    16 bit: with Curiosity card
    MBedder
    Circuit breaker
    • Total Posts : 6817
    • Reward points : 0
    • Joined: 2008/05/30 11:24:01
    • Location: Zelenograd, Russia
    • Status: offline
    Re: 16 bit newbe! 2019/12/07 04:08:53 (permalink)
    0
    You may find some at least interesting, at most useful 16-bit assembly related stuff here - https://www.microchip.com..ums/m812420.aspx#815633
    Guest
    Quick Reply: (Open Full Version)
      Enter the random characters shown
    Submit Post
    Some restrictions apply to prevent link (URL) Spam.
    URLs in messages, signatures, and PM's are removed unless you have ...
    • been a member for at least 0 day(s);
    • made a total of 0 post(s);
    • earned at least 0 point(s) for post scores (based on the ratings on your posts);
    • earned at least 0 reward point(s);
    Jump to:
    © 2020 APG vNext Commercial Version 4.5