Editing BoostC tiny Wiki

Jump to navigation Jump to search

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

Latest revision Your text
Line 2: Line 2:
  
 
This is the very beginning of a Wiki for BoostC.  Its organization will probably change a lot in the near future ( if we can get the free labor required ).  It may move to the SourceBoost site if they want to host it.  Since BoostC is proprietary it may be inappropriate for it to grow too big here unless we can find some explicit support for it.  For now here it is.  Much of this material applies to compilers other than BoostC and to environments other than PICs embedded systems.  Major sections will probably be split into seperate pages.  [http://www.sourceboost.com/ SourceBoost Homepage]
 
This is the very beginning of a Wiki for BoostC.  Its organization will probably change a lot in the near future ( if we can get the free labor required ).  It may move to the SourceBoost site if they want to host it.  Since BoostC is proprietary it may be inappropriate for it to grow too big here unless we can find some explicit support for it.  For now here it is.  Much of this material applies to compilers other than BoostC and to environments other than PICs embedded systems.  Major sections will probably be split into seperate pages.  [http://www.sourceboost.com/ SourceBoost Homepage]
 
== BoostC Wiki Contents ==
 
 
In addition to this page see:
 
 
===[[BoostC from the Forum]]=== 
 
Quickly review a year's worth ( or more ) of the forum for the most useful posts.
 
 
===[[A Really Basic Guide to the PIC Microprocessor and BoostC]]===
 
 
This is about as simple as it gets, does not assume much hardware knowledge either.
 
 
===Go to [[PIC Links]]===
 
Go to and search ( page search not google ) on "BoostC". There are projects, tips, tutorials.....
 
=== [[BoostC Inline Functions]] ===
 
=== [[How the BoostC Compiler Works]] ===
 
 
 
=== [[BoostC Explaining Dot H Files]] ===
 
=== [[BoostC Wiki Help Needed]] ===
 
 
 
=== and even more comming soon.....===
 
  
 
== Tips/Tricks/Gotchas ==
 
== Tips/Tricks/Gotchas ==
Line 42: Line 19:
 
=== Flakey Stack ===  
 
=== Flakey Stack ===  
  
If a program is flakey, particularly after working in earlier versions you may have run out of stack space for the call return stack.   
+
If a program is flakey, partarcularly after working in earlier versions you may have run out of stack space for the call return stack.   
  
To help you tell, look at all the linker messages.  Also open the code window and look at the call tree ( View -> Code Bar -> Call Tree ), see anything in red?
+
To help you tell look at all the linker messages.  Also open the code window and look at the call tree ( View -> Code Bar -> Call Tree ), see anything in red?
  
 
The fix:
 
The fix:
Line 54: Line 31:
 
=== Bad Options ===
 
=== Bad Options ===
  
Check you options, target should be right.  Recently I had a problem with the Compiler location option.  It seems to be a option of the project ( which makes sense if you want different projects to behave differently ) not the ide installation, so especially if you got the project from someone else check it.  For me a bad compiler location made the build take forever and do nothing; the compiler gave a useful error message.
+
Check you options, target should be right.  Recently I had a problem with the Compiler location option.  It seems to be a option of the project ( which makes sense if you want different projects to behave differently ) not the ide installation, so especially if you got the project from someone else check it.  For me a bad compiler location made the build take forever and do nothing, the compile gave a useful error message.
 
 
=== Types and Booleans ===
 
 
 
This may be standard C or just BoostC, but type checking is not as strict as languages like Java.  Especially be careful of the idea that booleans and numbers are interchangable.  Especially do not think that 0 is false and 1 is true.  You can count on 0 being false ( I think )  I have seen test_bit evaluate to 64.
 
 
 
=== Read Before Write Problems ===
 
 
 
[[Read before write]]
 
 
 
=== BootLoader Madness ===
 
 
 
Had a program, programmed with a programmer, worked fine.  Added a bootloader, bootloaded the program, NG.  Why why why!
 
 
 
Some hints, the fuses are inherited from the bootloader, your program cannot change, but that is not what got me.  I did not use, set, or enable interrupts.  This defult worked fine, but the bootloader apparently did not leave the settings in the default condition.  My fix, added an interrupt handler which did nothing, but even more important turned the global interrupts off at the very beginning of my program.  Not all bootloaders may behave in this way, but if you have a problem, consider the above.  See also:  [[PIC Programmers, In Circuit Programming and BootLoaders]]
 
 
 
=== Include the Library ===
 
 
 
Normally the compiler will find the library file needed, but if you get messages that functions are not found include the library that contains them, see the .h file with the same name for the library function.  This has been know to work with the EEProm Library.  Choose the right one, for the 18F or 16F if there is a choice.
 
 
 
=== How to use PIC registers as C variables ===
 
 
 
BoostC compiler can map C variables on specific addresses. This becomes handly when one wants to use PIC registers as C variables. For example PIC CCPR1L and CCPR1H are a consecutively addressed register pair.
 
 
 
  volatile unsigned short ccpr1 @ 0xFBE; //declare a 16 bit variable that is located at address 0xFBE, just where CCPR1 registers start
 
  //Now this variable can be used in C cone
 
  ccpr1 = 0x2400; //for example assign 0x2400 to it what writes 0x00 into CCPR1L and 0x24 into CCPR1H
 
  
 
== Standard C Issues ==
 
== Standard C Issues ==
Line 90: Line 41:
 
[http://en.wikipedia.org/wiki/C_Traps_and_Pitfalls C Traps and Pitfalls From Wikipedia, the free encyclopedia]  Note that there is a free download or a longer ( for purchase ) book.
 
[http://en.wikipedia.org/wiki/C_Traps_and_Pitfalls C Traps and Pitfalls From Wikipedia, the free encyclopedia]  Note that there is a free download or a longer ( for purchase ) book.
  
=== Good Practices ===
+
=== Good Pratices ===
  
 
Opinions may differ!
 
Opinions may differ!
Line 114: Line 65:
 
   char ix;
 
   char ix;
  
The reader, and perhaps even the programmer may not remember the default or remember it correctly
+
The reader, and perhaps even the programmer may not remember the default or remeber it correctly
  
  
Use parenthesis not operation conventions:
+
Use parenthsis not operation conventions:
  
 
   c    = a + ( b * c )  
 
   c    = a + ( b * c )  
Line 124: Line 75:
 
   
 
   
 
   c    = a + b * c
 
   c    = a + b * c
 
In the good "old days" of the PDP-11 where large memory was measured in killobytes it was necessary to conserve memory -- even at the source code level.  In the 21st century environment of gigabyte memories it's no longer necessary to conserve bytes at the expense of readability and clarity.  Many programmers (particularly the old grumpy ones) take pride in saving a few bytes -- but mostly its a tradition thing except where the shortcuts save a bit of program run time.  ....but then there might be a reason why they call it 'code'.
 
 
Keep in mind that the following two sections are not equal. While the first looks neater at the source code level, it generates many times(!) more (redundant) machine instructions than the second form.
 
 
 
    bit LED1_TRIS        @ TRISB.5;
 
    bit LED2_TRIS        @ TRISB.6;
 
    bit LED3_TRIS        @ TRISB.4;
 
   
 
    LED1_TRIS = LED2_TRIS = LED3_TRIS = 0; // make output
 
 
 
Writing it this way, generates smaller and faster code:
 
 
    bit LED1_TRIS        @ TRISB.5;
 
    bit LED2_TRIS        @ TRISB.6;
 
    bit LED3_TRIS        @ TRISB.4;
 
   
 
    // make output
 
    LED1_TRIS = 0;
 
    LED2_TRIS = 0;
 
    LED3_TRIS = 0;
 
  
 
==== Read This ====
 
==== Read This ====
  
 
[http://www.csd.uoc.gr/~hy255/reading/cstyle.pdf  Recommended C Style and Coding Standards] from Bell Labs
 
[http://www.csd.uoc.gr/~hy255/reading/cstyle.pdf  Recommended C Style and Coding Standards] from Bell Labs
 
== How to pages ==
 
 
[[Index of sample code pages]] showing sample code, showing the various ways tricky, or not so tricky issues have been tackled
 
  
 
== Optimization ==
 
== Optimization ==
Line 166: Line 90:
 
*Is shifting better than multiplying/dividing by poweres of 2?
 
*Is shifting better than multiplying/dividing by poweres of 2?
  
*does if( intcon & (1<<T0IF) ) work better than test_bit( intcon, T0IF )? --- answered see below.
+
*does if( intcon & (1<<T0IF) ) work better than test_bit( intcon, T0IF )?
  
 
*Is there a time penality to using local variables.
 
*Is there a time penality to using local variables.
Line 176: Line 100:
 
=== Optimizations that Seem Not to Work ===
 
=== Optimizations that Seem Not to Work ===
  
Some of these may not truely attempts at optimization, just different ways of writing code, in andy case we compare them to other presumabably clearer ways of writing the code.
 
  
Generally these test were done by writing the code and then examining the casm file.
 
  
==== Shift, vs Test ====
 
  
In interrupts we often see a bit test as
+
== Code Snips that may Be Helpful ==
  
    if( intcon & (1<<T0IF) )
+
You are counting down and want to know when an unsigned number goes negative ( never ).  You could declare it signed, slowing everything down.  Instead check against FF.  This assumes you do not use FF on the positive side.
  
by which it is meant:
+
  if ( ix == 0xFF ) ..
  
    if( test_bit(  intcon, T0IF) )
 
 
Looking at the generated code: it is identical, so why not use the clearer formulation?  { Also looking at boostc.h it seems this is the definition of the expression }
 
 
=== "x" vs 'x' ===
 
 
Sometimes there is "no difference"  between "x" vs 'x'.  For example serial_printf( '\r' ); and serial_printf( "\r" ); both print a carriage return.  But the character formulation, '\r', will take less memory and run faster.  Often a function will take either a character or a string, if the string is one character long use the character formulation.
 
 
==== More ====
 
 
More in process... and soon to be the new home for all [[BoostC Optimizations]]
 
 
== Code Snips that may Be Helpful ==
 
 
 
moved to and merged with [[Index of sample code pages]]
 
  
 
== Example Programs and Projects ==
 
== Example Programs and Projects ==
  
 
Go to [[PIC Links]] and search ( page search not google ) on "BoostC".
 
Go to [[PIC Links]] and search ( page search not google ) on "BoostC".
 
== Getting help ==
 
 
Struggling with a new PIC feature? Check out the PIC tutorials at: http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1959 for some useful help on the various PIC peripherals
 
  
 
== Further reading ==
 
== Further reading ==
Line 217: Line 118:
 
* [[Microcontrollers]] This Wiki's main page on microcontrollers including the PIC.
 
* [[Microcontrollers]] This Wiki's main page on microcontrollers including the PIC.
  
* [[Playing With PIC Pack]] A user developed package in BoostC for the PIC.
+
* [[Playing With PIC Pack]] A user develope package in BoostC for the PIC.
  
* [[BoostC from the Forum]] Information extracted and summarized from the BoostC Forum.  
+
* [[BoostC from the Fourm]] Information extracted and summarized from the BoostC Forum.
  
 
* [http://en.wikibooks.org/wiki/C_programming Wikibooks: C programming] is about C programming in general (alas, focuses on programs running on desktop computers, rather than small microcontrollers).
 
* [http://en.wikibooks.org/wiki/C_programming Wikibooks: C programming] is about C programming in general (alas, focuses on programs running on desktop computers, rather than small microcontrollers).
 
* Gooligum C Tutorials [http://www.gooligum.com.au/tut_midrange_C.html ] C language Tutorials for mid range PICs with extensive examples and detailed explanations.  Written for HITEC and PICC but easily convertable to SourceBoost C.
 
[[Category:BoostC]][[Category:PIC]]
 

Please note that all contributions to OpenCircuits may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see OpenCircuits:Copyrights for details). Do not submit copyrighted work without permission!

Cancel Editing help (opens in new window)