View previous topic :: View next topic |
Author |
Message |
mikem
Joined: 09 Jul 2009 Posts: 11
|
writing portable C code while using CCS build in functions |
Posted: Thu Jul 09, 2009 9:11 am |
|
|
Hi All,
I have just purchased the CCS compiler to use with a PIC16f690. I am trying to figure out the best way going forward of using all the built in functions of the CCS compiler while still writing the code in such a way that if it could be ported to another compiler down the road if necessary.
Not sure if this just means putting the built in functions into a wrapper function. For example there are some great low level functions for i2c but if I ported these to another compiler they would not work.
If anyone has some suggestions it would be much appreciated!!
Thanks in advance.
Mike |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Thu Jul 09, 2009 9:26 am |
|
|
If you used CCS functions as they are in your code you would just need to write your own versions if you ever moved to another compiler.
Exceptions are, as far as I know:-
int default to unsigned int8, use your own type def!
standardio inserts tris statements, use fastio or add tris to your version of the function when porting.
functions which accept a single char can accept a string, the compiler will create code to call the function with each char in the const array!, write an equivilent to accept strings.
I am sure there are a lot of other considerations which people will comment on. These ones are what I would consider minor
Most functions you would be able to write your own when porting if one was not supplied. |
|
|
mikem
Joined: 09 Jul 2009 Posts: 11
|
|
Posted: Thu Jul 09, 2009 9:41 am |
|
|
Thanks for the reply Wayne_.
>> If you used CCS functions as they are in your code you would just need to write your own versions if you ever moved to another compiler.
You are probably right with this point. Just stick to good coding style and I should be fine.
Cheers
Mike |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Thu Jul 09, 2009 10:55 am |
|
|
Writing w/CCS is one of the reasons we (I) use CCS. Some of the functions you would HAVE to write for another compiler are done for you.
I did a project starting with C18... but then when looking at how nicely CCS handles streams w/fprintf and printf... it was more worthwhile to convert the project to CCS as it would have taken as much time to sort out the idiosyncrasies of using C18.
Remember, most other compilers were typically made for another target and ported to the Microchip line. This is good and bad.
When I did that conversion from C18 to CCS doing JUST ENOUGH to get it to compile, I went from 80% usage of PROM space to 49%. I didn't change any of the typedefs from C18 (that were set for 16bit INTs) to CCS. JUST ENOUGH to compile and I got back that much PROM space.
Someday I might have to jump back into C18 or another -- but CCS has some compelling arguments for its use. (and yes, I run into bugs too - but no compiler is without I hear. ;D -- could be worse, could be MS and a double API. Try calling up Bill Gates to complain! )
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
Guest
|
|
Posted: Fri Jul 10, 2009 2:07 am |
|
|
Hi Ben,
thanks for your thoughts!! Yet more useful information.
You porting experience from C18 to CCS is quite interesting.
Sounds like I picked a good compiler for the pic line of micros.
Cheers
Mike |
|
|
|