This is an old revision of the document!
char c; c = 12 >> 1; // c is 6 (division through 2) c = 12 >> 2; // c is 3 (division through 4) c = 12 << 1; // c is 24 (multiplication by 2) c = 12 << 2; // c is 48 (mulitplication by 4) c = 1023 >> 3; // c is 127 (10bit to 7bit ;)
if multiplications, divisions, pointer operations, etc. are used in the .c code, the linker may fail due to missing functions, which are part of the libsdcc.lib library. The common library for pic16 derivatives is not compatible to MIOS, therefore I've created a special one which can be downloaded from here. Read the README.txt file for further details. TK on the C-Page
MIOS_DOUT_SRSet(1, 00000001) Will set the 1st pin (aka Pin 0)…. or
MIOS_DOUT_SRSet(1, 01000000) Will set the 7th pin (aka Pin 6)
Some of these bugs have first been described in a german thread in the forum.
Sometimes the transfer of an array between modules does not work properly, e.g. file 1:
unsigned char MIDIValues[8];
file 2:
MIOS_MIDI_TxBufferPut(MIDIValues[1]);
Instead, you need to do something like
unsigend char value = MIDIValues[1]; //explicite temp variable MIOS_MIDI_TxBufferPut(value);
Arrays with more than 256 elements will produce compile (in fact linker) errors:
unsigned char myArray[256]; // will work unsigned char myArray[257]; // will not be linked! unsigned char myArray[64][4]; // will work unsigned char myArray[64][5]; // will not be linked!
Thanks to Thomas for testing some workarounds with multiple single-dimensional arrays.
Always use parenthesis around expressions like
myarray[a+b];
instead use
myarray[(a+b)];
Avoid #ifdef and #if preprocessor-statements wrapped around declarations and function prototypes. Even if the preprocessor's #if statement is true (eg defined as '1'), any access to it's vars and functions from outside these wrapped statements produce a compile-warning:
#define TEST 1 #if TEST unsigned char testvar; #endif /* TEST */ void testfunction(void) { unsigned char c = testvar + 1; // access to testvar produces compiler error! }
Avoid comparisons of unsigned char
with 0
, e.g.
unsigned char i; for (i = 0; i < 0; i+ü) { //body }
0
could be a constant that was defined using #define
, e.g. the number of motorized faders. But you have no motorized faders… The main problem consists in the fact that your code depends on what else is done around the comparison or in the body. This provokes completely erratic behaviour.
There is potential trouble with bit copy operations. Instead of
app_flags.SRAM_CARD_STATUS = PORTEbits.RE2;
you should use
if( PORTEbits.RE2 ){ app_flags.SRAM_CARD_STATUS = 1; }else{ app_flags.SRAM_CARD_STATUS = 0; }
It is less elegant, but it works safely.