c_tips_and_tricks_for_pic_programming
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
c_tips_and_tricks_for_pic_programming [2007/12/18 10:07] – added bitfields, cleaned up headline-levels audiocommander | c_tips_and_tricks_for_pic_programming [2008/04/05 21:03] – Added info for the gpasm toolchain stryd_one | ||
---|---|---|---|
Line 11: | Line 11: | ||
</ | </ | ||
* There' | * There' | ||
+ | * The [[http:// | ||
* If this is not enough, you could search for ASM optimized custom functions. You'll find some in code examples of TK, the [[ACSensorizer]] and a lot of PIC-Specialized Webpages – or of course the forum. | * If this is not enough, you could search for ASM optimized custom functions. You'll find some in code examples of TK, the [[ACSensorizer]] and a lot of PIC-Specialized Webpages – or of course the forum. | ||
- | * If that still is not enough or you have no time and a lot of processing power / space available on your PIC, you can include the **libsdcc library**: | + | \\ |
+ | \\ | ||
+ | ==== MIOS LIBSDCC Library ==== | ||
- | >> | + | If that still is not enough or you have no time and a lot of processing power / space available on your PIC, you can include the **libsdcc library**: |
+ | \\ | ||
+ | If multiplications, | ||
+ | You Should specify your custom linker script in the makefile if using the new gpasm based mios toolchain. | ||
+ | \\ | ||
+ | When using the library, sometimes the compiler will optimise multiplications to bitshifts (as demonstrated above) automatically. You can check the output files to see if this has occurred, but it is recommended to code the bitshifts manually, to be sure. | ||
\\ | \\ | ||
+ | |||
====== Bitfields, Unions & Structs ====== | ====== Bitfields, Unions & Structs ====== | ||
Line 46: | Line 55: | ||
mynum = something.ALL; | mynum = something.ALL; | ||
</ | </ | ||
- | >> // Due to an SDCC restriction, bitfields are limited to 8 bits max // | + | >> // It has been confirmed with recent versions of SDCC, that bitfields are not limited to 8bits as was previously expected. |
Line 71: | Line 80: | ||
* Adding the keyword ' | * Adding the keyword ' | ||
- | * Always use ' | + | * Always use ' |
Line 96: | Line 105: | ||
unsigned char value = MIDIValues[1]; | unsigned char value = MIDIValues[1]; | ||
MIOS_MIDI_TxBufferPut(value); | MIOS_MIDI_TxBufferPut(value); | ||
+ | </ | ||
+ | In most cases, adding parenthesis around your index variable has the same effect (see tip further down) | ||
+ | <code c> | ||
+ | MIOS_MIDI_TxBufferPut((MIDIValues[1])); | ||
</ | </ | ||
Line 101: | Line 114: | ||
==== Large Arrays ==== | ==== Large Arrays ==== | ||
- | Arrays with more than 256 elements will produce compile (in fact linker) errors: | + | Arrays with more than 256 bytes of elements will produce compile (in fact linker) errors: |
<code c> | <code c> | ||
unsigned char myArray[256]; | unsigned char myArray[256]; | ||
Line 108: | Line 121: | ||
unsigned char myArray[64][4]; | unsigned char myArray[64][4]; | ||
unsigned char myArray[64][5]; | unsigned char myArray[64][5]; | ||
+ | |||
+ | unsigned int myArray[128]; | ||
+ | unsigned int myArray[129]; | ||
</ | </ | ||
c_tips_and_tricks_for_pic_programming.txt · Last modified: 2011/09/15 07:14 by ichaljhe