3
\$\begingroup\$

I'm trying to program a microprocessor for the first time, and having lots and lots of doubts.

I have installed both the C18 and the XC8 compilers, plus a few others. When I create a new project and select my microprocessor, PIC18F26K22, I get to choose between these two compilers, in addition to the two mpasm assemblers. When they are both available to choose, does that mean that they both work?

How do I decide which one to use? I have tried googling but cant seem to find the answer; perhaps because I don't know what to google for and don't know how to read the results. Or perhaps it makes no real difference which one I pick?

\$\endgroup\$
1

2 Answers 2

4
\$\begingroup\$

As Roger says, use XC8. It's the newer compiler.

The C18 compiler is obsolete and it won't support any newer devices.

Another disadvantage of C18 is that it only supports the PIC18 family of microcontrollers as opposed to the XC8, which supports all the 8-bit PIC microcontrollers: PIC10, PIC12, PIC16, PIC18.


I'd also argue that XC8 (which is based on the HI-TECH C Compiler) is a tad easier to use than C18. Just take a look at how you would declare an ISR in both compilers:

C18:

void isr(void)
{
   /* ... */
}

#pragma code high_vector=0x08

void interrupt_at_high_vector(void)
{
    _asm GOTO isr _endasm
}

#pragma code

#pragma interrupt isr

vs XC8:

void interrupt isr(void)
{
   /* ... */
}
\$\endgroup\$
3
\$\begingroup\$

C18 is the old Microchip compiler, and XC8 is the new Microchip compiler that they bought from HiTech (or some name like that, anyway, the Aussie compiler).

XC8 has the current support and is what Microchip is going forwards with. If you are starting from scratch with PICs, then this is probably what you want.

However, there are some issues to be aware of either way. XC8 doesn't implement a software stack. It also does its own linking using a incompatible binary format to that of C18 and MPASM. If you plan to mix C and assembler, and particularly if you have existing MPASM modules, or expect to get any from others, then stay away from XC8.

On the flip side, C18 has its issues too. While the code generator seems to be robust, some of its strategies of how to use the PIC 18 hardware are "less than brilliant". It implements a software stack, but chose a layout that requires the one pre/post inc/dec addressing mode that the PIC 18 doesn't have. Duh! It also reserves two of the three FSR registers for its own use. It also uses a caller-clean stack model for subroutine calls. That means subroutines can't remove data from the stack they're done with before calling other subroutines. The result is that the stack needs considerably more space than it should.

Personally, I stick to MPASM on the 8 bit PICs. I have used C18 in the past for some mixed C/ASM projects, but that was only because I received code that way. It was always more trouble when the compiler was involved, compared to a pure MPASM project. I've also got many subsystems written in MPASM already on the disk, so mostly I just have to add the logic specific to the project. Things like UART handlers, USB device, TCP/IP stack, and many other facilities are already there.

\$\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.