1
\$\begingroup\$

I have learnt that the MPLAB IDE has different compilers like C18, XC8 and HI-Tech.

I want to know the following things:

  1. Why are there different compilers when one can do the job?
  2. Are certain compilers only used for specific microcontrollers?
  3. Are there more compilers than these 3 that I need to be aware of?
  4. If any compiler can be used for say compiling PIC18F code, then what decides which one I choose? I really want to know how to decide which one to go with.
\$\endgroup\$
1
  • \$\begingroup\$ Market forces .................... \$\endgroup\$
    – Russell McMahon
    Commented Mar 25, 2015 at 1:28

2 Answers 2

6
\$\begingroup\$

Why are there different compilers when one can do the job?

Because people improve them over time.

C18 has been superseded by XC8. C18 is old and rubbish, so they made XC8 which is much better. They also took the opportunity to name it something more logical.

HI-Tech is a third party compiler written by someone else that Microchip bought the rights to. It's also deprecated in favour of XC8.

Are certain compilers only used for specific microcontrollers?

Yes. As new chips are released the compiler has to support them. Old compilers that don't get updated won't support the new chips.

Are there more compilers than these 3 that I need to be aware of?

There is also the open source SDCC compiler, but it's very basic and only has partial PIC support, and doesn't (as far as I know) work with MPLAB.

Another one, which uses its own IDE, is called CCS, though I have never used it.

If you don't like C, then there are a number of BASIC compilers for 8-bit PIC chips, including Swordfish.

If any compiler can be used for say compiling PIC18F code, then what decides which one I choose? I really want to know how to decide which one to go with.

That's simple - you choose XC8 since it's the currently supported one. All the others are old and deprecated.

\$\endgroup\$
7
  • \$\begingroup\$ This answer is spot on. Thank you. A final point remains. When would one choose to use the MPASM option in MPLAB. As far as I know, this is merely assembler. Why leave the convenience of C Code and write whole program in assembly? \$\endgroup\$
    – quantum231
    Commented Mar 24, 2015 at 22:50
  • \$\begingroup\$ Because with assembly you have complete control over absolutely everything. You can (if you are good) write some very very small footprint code. \$\endgroup\$
    – Majenko
    Commented Mar 24, 2015 at 22:51
  • \$\begingroup\$ Don't forget about CCS <www.ccsinfo.com/content.php?page=compilers>. A lot of people whom I respect really like that compiler. \$\endgroup\$ Commented Mar 24, 2015 at 22:52
  • \$\begingroup\$ I have CCS C compiler on my machine but am unable to use my ICD3 with it. I have posted another question related to it. What I understand is that the older compilers exist for legacy code and must not be used for new code. \$\endgroup\$
    – quantum231
    Commented Mar 24, 2015 at 22:55
  • \$\begingroup\$ Regarding writing in Assembler: that's all that both myself and my coworker write in. Although my coworker is competent with C, I'm an oldster and my brain just doesn't grok C. As a result, it takes me much longer to write any given program compared to someone who writes in a high-level language. This is mostly offset in that most of the stuff that I write gets used for a very long time (decades). \$\endgroup\$ Commented Mar 24, 2015 at 22:56
6
\$\begingroup\$

So far the answer given limits itself to 8-bit PIC microelectronics, but the OP asked (in part):

  1. Why are there different compilers when one can do the job?

  2. Are certain compilers only used for specific microcontrollers?

I will answer both of these questions together. Microchip makes not only 8-bit microcontrollers (PIC10, PIC12, PIC16, PIC18) but also 16-bit (PIC24/dsPIC33) and 32-bit (PIC32).

Each of the 8-bit PIC's (except the PIC18) have similar instruction sets, using a single accumulator (W0), a small amount of RAM (25-256 bytes), and a hardware call stack. The instruction set originally had 35 instructions, but was expanded to 49 instructions on newer devices to better accommodate C compilers (Up to that point, most 8-PIC programs were written in assembler code -- many still are on the chips with very little flash.)

The PIC18 devices added support for a software stack, and a much large RAM. They have 75 instructions (83 for newer devices).

In spite of all these differences (particularly the differences between the low-end 8-bit PIC instruction set and the higher end PIC18), the XC8 compiler supports all of these 8-bit PIC families. It does so by actually making using of two compilers internally -- PICC and PICC18, and choosing which one to use based on the processor selected.

There are both free and paid versions of the XC8 compiler -- the only difference being the amount of optimization performed.

The next step up from the 8-bit PIC microcontrollers are the 16-bit PIC24 and the dsPIC33. These are very similar -- the dsPIC includes the PIC24 instruction set, but also adds additional instructions for doing DSP (Digital Signal Processing), hence its name. These 16-bit PIC processors are supported by the XC16 compiler. Although they can be programmed in assembly language, it is seldom done except for very tight loops or time critical interrupt service routines (ISR).

Like XC8, there are both free and paid versions of the XC16 compiler -- again the difference being the amount of optimization performed.

And finally, there is the 32-bit PIC32 family, with an instruction set derived from the RISC-style MIPS. The newer devices can address up to 2MB of flash memory and 512K of data. The 32-bit processors are supported by the XC32 compiler. Like the PIC24, they are seldom programmed in assembly language. And also like Like XC16 compiler, there are both free and paid versions of the XC32 compiler -- again the difference being the amount of optimization performed -- some as much as 50%.

\$\endgroup\$
1
  • \$\begingroup\$ Your answer is just pure awesomeness. By the way, I bought the ICD3 that you recommended to me last time. \$\endgroup\$
    – quantum231
    Commented Mar 25, 2015 at 18:59

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.