C compiler for the PIC16 series microcontroller

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
DavidH
Posts: 80
Joined: Mon Aug 03, 2009 3:53 am UTC

C compiler for the PIC16 series microcontroller

Postby DavidH » Sun Jan 09, 2011 1:22 am UTC

Hello,

I've recently found myself having to do some rather complex real time machine control using a PIC16 microcontroller. These are usually coded in assembly (while more advanced microprocessors can be coded in multiple languages).

I was wondering if anyone had any good experience with a C or C++ cross compiler for the PIC16? Ideally one that includes some rudimentary optimizations. My google-fu doesn't seem to be enough.

Cheers, David.

ST47
Posts: 125
Joined: Tue Oct 16, 2007 6:42 pm UTC

Re: C compiler for the PIC16 series microcontroller

Postby ST47 » Sun Jan 09, 2011 5:01 am UTC

You mean like this:
http://www.microchip.com/stellent/idcpl ... e=en542849

The free version works fine, the paid version has better optimization. I TA a class where we throw a PIC chip and this compiler at a bunch of freshmen and tell them to do something neat for a semester, and while there are a few quirks, mostly UI stuff with the IDE, they always seem to manage it. Compilers are available for Windows, Linux, and OS X. If you're interested, we also use a piece of software called Tiny Bootloader to actually program the chip; no complaints there either. Of course there are other options.

Compiler is C, not C++, does all the nice things like inline assembly, and appears to support everything you could want, and the lite version is more than adequate.

User avatar
thoughtfully
Posts: 2253
Joined: Thu Nov 01, 2007 12:25 am UTC
Location: Minneapolis, MN
Contact:

Re: C compiler for the PIC16 series microcontroller

Postby thoughtfully » Sun Jan 09, 2011 6:29 am UTC

If you end up doing a lot of PIC development, you can get a fully featured C (not C++) command line compiler from CCS for $99. It even comes in a Linux version! Oh, rats. They jacked it up to $150. Sorry. They have some educational discounts; you might be able to get a better deal if you're a student or work in a university lab or such.

If you are doing a lot of microcontroller development though, go with AVR chips (arduinos are a great way to get started!) and use the GNU toolchain. You even get C++ (with some limitations)!

I have used all these products. The CCS compiler since version 4 has been quite nice, although before that there were a lot of bugs you had to work around, but they were mostly well-known and not so hard to deal with. There's a really great user forum on their site that's a big help. I believe CCS is still the cheapest by a long ways if you want a reasonably decent PIC compiler, although I haven't been paying attention for awhile. The free ones tend to only support the low end chips, have limitations on the code size, or be rough around the edges/poorly maintained/supported. But I'm going with AVR and GNU for all my new projects.
Image
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

User avatar
sparkyb
Posts: 1091
Joined: Thu Sep 06, 2007 7:30 pm UTC
Location: Camberville proper!
Contact:

Re: C compiler for the PIC16 series microcontroller

Postby sparkyb » Wed Jan 26, 2011 1:07 pm UTC

I've done a bunch of projects with PICs (PIC16F87X series) and I bought myself a license of the SourceBoost BoostC compiler (or at least what became BoostC after they changed names). I think it is cheaper than CCS, how much cheaper depends on the level of license you need. I've been pretty happy with it. They also have a BoostC++ if you really want C++.

However, as much as I love PICs, like thoughtfully says it seems arduinos are the way to go these days. I haven't had to do any microcontroller work lately, but I imagine if I did I'd have to bite the bullet and learn to use an AVR because they seem to be way more available in nice pre-built packages. And of course, if you're just looking for a higher level language than assembly, you can also use the even higher level Wiring language on Arduino.

User avatar
Emu*
Posts: 689
Joined: Mon Apr 28, 2008 9:47 am UTC
Location: Cardiff, UK
Contact:

Re: C compiler for the PIC16 series microcontroller

Postby Emu* » Wed Jan 26, 2011 3:25 pm UTC

The Arduino library is pretty nifty and the IDE-bootloader link over USB saves a lot of worry.

You can use it as a stanrardised AVR board without the bootloader if you like, but that depends how much performance you need to drag out of it.
Cosmologicon wrote:Emu* implemented a naive east-first strategy and ran it for an hour, producing results that rivaled many sophisticated strategies, visiting 614 cells. For this, Emu* is awarded Best Deterministic Algorithm!

User avatar
DavidH
Posts: 80
Joined: Mon Aug 03, 2009 3:53 am UTC

Re: C compiler for the PIC16 series microcontroller

Postby DavidH » Wed Jan 26, 2011 7:50 pm UTC

I have to use a PIC16, simply because that's what I'm supplied with. I decided to just go with assembly and I must say.. ouch. The language only has one conditional branch (skipping the next instruction if a byte is 0), and no multiplication or division.

Thanks for the advice, though! If I ever do a project using a microcontroller again, I'm definitely going with an Arduino.

The main problem I'm running into now is the 8 bit architecture, which I overflow just slightly under certain operating conditions. Is there any standard algorithm to detect an overflow and utilize 2 consecutive bytes instead of the normal word (which is one)? Note the extreme lack of branching.

User avatar
Emu*
Posts: 689
Joined: Mon Apr 28, 2008 9:47 am UTC
Location: Cardiff, UK
Contact:

Re: C compiler for the PIC16 series microcontroller

Postby Emu* » Thu Jan 27, 2011 8:13 am UTC

All the fancy control structures you're familiar with compile to machine code so must be representable in assembly.

Jump if equal to 0 and jump if not equal to 0 are just the test which all control structures must inevitably boil down to. You have to do your calculation and then the decision, rather than having them nicely rolled into one.
Cosmologicon wrote:Emu* implemented a naive east-first strategy and ran it for an hour, producing results that rivaled many sophisticated strategies, visiting 614 cells. For this, Emu* is awarded Best Deterministic Algorithm!

kmatzen
Posts: 214
Joined: Thu Nov 15, 2007 2:55 pm UTC
Location: Ithaca, NY

Re: C compiler for the PIC16 series microcontroller

Postby kmatzen » Thu Jan 27, 2011 2:32 pm UTC

DavidH wrote:The main problem I'm running into now is the 8 bit architecture, which I overflow just slightly under certain operating conditions. Is there any standard algorithm to detect an overflow and utilize 2 consecutive bytes instead of the normal word (which is one)? Note the extreme lack of branching.


Are we talking about AVR now? There is add with carry, ADC. That along with the regular add without carry, ADD, should be all that you need to do multiword arithmetic.

If you don't want to buy an Arduino kit, the AVR microcontrollers are very inexpensive and I think the only additional item you would need to buy for your first one is a programmer. After that, you can build your own programmers by using other AVR microcontrollers that you program. I use an AVR Dragon, but those were free on digikey awhile ago when you bought a dev kit. I ended up not using the dev kit very much though so that was $50 wasted. The microcontrollers themselves cost about $5 for a reasonably featured model or free if you are willing to deal with their free sample option. The GNU toolchain works well although I've had some issues with the AVR Dragon. Mainly lack of documentation issues. These issues are resolvable if you are familiar with other AVR programmers though.

At least in the last 4 or 5 years, I haven't heard a lot about PIC and hobby projects. It all seems to be AVR now. My microprocessor course when I was an undergrad used PowerPC, but now I think they even ditched that for ARM. Depending on what you do, especially if your project would benefit from an FPU, PowerPC or ARM might be helpful. If your multiplication and division is all by powers of 2 or can be approximated with powers of 2, then these won't help you too much.

What I like about the Arduino platform is that you can do a lot of reconfiguration without reprogramming. I make stupid mistakes and end up programming more microcontrollers just to fix my mistakes and salvage the initial microcontrollers.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 5 guests