Continue to Site

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.

  • 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.

Hi-Tech C

Status
Not open for further replies.

usif

New Member
I just recently got into C programming for the PIC's, and I am completely lost as to what compiler I have to pick. I have the PIC 16F877A.

I have ran C programs on the PIC, but I am having trouble decoding what the program instruction do - I havnt found any useful tutorial for Hi-Tech C (Im using the PIC lite intergration with MPLAB)

Are there any useful tutorials, etc. Or are there better compilers, with a larger support base.
 
I just recently got into C programming for the PIC's, and I am completely lost as to what compiler I have to pick. I have the PIC 16F877A.

I have ran C programs on the PIC, but I am having trouble decoding what the program instruction do - I havnt found any useful tutorial for Hi-Tech C (Im using the PIC lite intergration with MPLAB)

Are there any useful tutorials, etc. Or are there better compilers, with a larger support base.
Grab the BoostC demo from SourceBoost. It's an excellent PIC compiler. The demo works on all supported PICs. It's only memory and code size limited. When your programs get too big for the demo you can buy a full license for about $75. That gets you both 16F and 18F compilers, as well as support for some 12F's. A ton of bang for the buck!

You can't beat that deal anywhere. Microchip's C18 is about $500 and is for 18F's only. You get to pay again to get another compiler for 16F's. PICC is around $1000 for a full license, I think for only one family (16F or 18F). I could be mistaken about that, but still it's a lot of bucks if you're a hobbiest.
 
Grab the BoostC demo from SourceBoost. It's an excellent PIC compiler. The demo works on all supported PICs. It's only memory and code size limited. When your programs get too big for the demo you can buy a full license for about $75. That gets you both 16F and 18F compilers, as well as support for some 12F's. A ton of bang for the buck!

You can't beat that deal anywhere. Microchip's C18 is about $500 and is for 18F's only. You get to pay again to get another compiler for 16F's. PICC is around $1000 for a full license, I think for only one family (16F or 18F). I could be mistaken about that, but still it's a lot of bucks if you're a hobbiest.

In terms of support and noob-friendliness - i.e tutorials, etc, does BoostC stand out from the rest?

And im assuming that all C compilers syntax's are very similar to each other?
 
In terms of support and noob-friendliness - i.e tutorials, etc, does BoostC stand out from the rest?
There's lots of BoostC users here at Electro Tech. I don't know of any tutorials targetted exactly at BoostC, but aside from compiler specific stuff it's an ANSI C compiler. It works as you would expect one to work. Tutorials for other compilers, except for minor syntax differences (not in C, but in register/bit access), should work fine.

And I'm assuming that all C compilers syntax's are very similar to each other?
Well, C is C, and has been "forever". The equates in the include files and the libraries supplied are mostly what makes compilers different from each other. And libs are pretty standardized too.

The way you access bits and registers is defined in the include files (can be changed if you can't live with it). This is where some of the biggest differences in PIC compiler syntax comes in. BoostC is one of the easiest to live with, IMHO. It is a little different from the others, but not weird or anything - they're all a bit different from each other. It's easy to port code from other compilers. The changes aren't hard to make.

If you've never programmed in C before you might be wise to learn it on a PC first, at least till you're a bit comfortable with it. There's bazillions of tutorials and on a PC you have easy pre-configured stdin and stdout (the keyboard and monitor) to learn with, whereas on a PIC you have to write code to do your own input and output. It can be quite a hump to get over when you're brand new to the language. If you don't yet know how to program in C, how do you write I/O code to learn the basics? On the other hand, blinking a LED in C is trivially easy.
 
Last edited:
Well, C is C, and has been "forever". The equates in the include files and the libraries supplied are mostly what makes compilers different from each other. And libs are pretty standardized too.

People always claim that, yet it's not simple to transfer code from one compiler to another - not even on a PC. And on PIC's compilers are wildly different - C seems no better than BASIC or Pascal for moving between compilers.
 
Hi I also like to join to this thread regarding compilers.I have the same issue like OP.

I have CCS C full,BoostC trial,C18 Student versions.

I still wondering what to start with.Futz gave me some nice info about compilers.

I already completed studying a CCS book by (Nigel Gardener) & got the basics of C.
After finding on the net very few working with this compiler (CCS C) & heard there are some bugs on that.

My mind is always focusing to change the current compiler.More focusing on 18F series for future designs.

Any ideas on what compiler to use?
 
Last edited:
Gayan,

What target hardware do you have available.

Mike.

Hi Mike I have

Programmers

*Junebug
*ICD2
*Modified JDM (for 18F)

Target boards

Target boards I have made by myself with the ICSP connector & header pins on all I/O pins on PIC 18F1320,18F452 etc..........

At anytime I can quickly build any target board to check the code is working in real life :)
 
As you have a Junebug then I'd start with C18. There's lots of example code on here. Why not start by controlling a servo clicky.

Mike.
 
My vote also goes to my favorite - Sourceboost. In fact it comes with Basic, C and C++ support. It has very nice and simple to use IDE and simulation capabilites. Free version is 2kB and 2 ram banks limited but it takes a while to fill that. (Full license cost is very reasonable as mentioned above).

Btw, Sourceboost developers have recently announced working on compiler for dsPIC/PIC24/PIC32 series :)
 
I gave BoostC a try last night, and my LED's have been flashing :)

What I didnt understand, is why I had to turn my porta into digital mode so I can get them on?
 
I gave BoostC a try last night, and my LED's have been flashing :)

What I didnt understand, is why I had to turn my porta into digital mode so I can get them on?

You don't, you can light LEDs with the pins set to analogue. What you can't do is bit operations on the port as analogue pins always read as zero.

So,
Code:
	bsf	PORTA,1
	bsf	PORTA,2
will result in bit one being zero because the next bsf will read a zero from bit 1 and write it back.

It's also very confusing.:D

Mike.
 
I'm having trouble starting. Can anyone confirm that I should get a good C book, learn the basics and then apply it to the PIC's?
 
Why don't you try writing some code and see if it works. If it doesn't work then post it on here and people will help. We like people that try to write stuff and get stuck. We don't like people that say "gimme xxx".

Mike.
 
Usif,
The hard part about starting with C on a microprocessor isn't so much the C language, it only has 32 keywords (ref: K&R) of which 11 are data types. Plus if you've done any programming before then the basic constructs: if, for, etc. are already familiar.

The tricky bit is all the stuff that's processor dependent, such as initialising the PIC's hardware registers, CONFIG words, include files and the like. This all tends to change with each different C compiler, however - not the core code in the application itself. What I'd suggest is choose a development environment and just go with the C compiler that comes with that. My choice is the free MPLAB IDE and the PICC Lite compiler that comes with it. Not because it's any better than any of the others, just because it's there already and so is less hassle when you're at the bottom of the learning curve.

The next thing to do is to get some sample code off the internet. It doesn't have to be exactly the functions you want, but the key is to get all the peripheral stuff (configs etc.) and then to adapt the C code to do what you want it to.
 
I'm having trouble starting. Can anyone confirm that I should get a good C book, learn the basics and then apply it to the PIC's?

You should first learn C before trying to play with microcontrollers. No need for a book, everything (yes everything) you need can be found on the Internet.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top