Hi guys, I fell on a problem on which I just spent a day and a half, plus a whole night, with no clue :-(
At this step, as every poor programmer would, I think "this is probably a
compiler issue, otherwise my brain is dead", so it's quite ashamed that I
submit this here...
I have a function called SubReadInputs() that does something complex yet
simple ;-) :
1/ It first "statically" fills an array/structure of 12 entries by copying
ports
inputs into it.
2/ It then processes the array using a for (i=0; i<=11; i++) { ...blah... }
loop to perform some "logical debounce magic" on said entries.
However the loop doesn't work as expected at all, and when used the whole
thing goes crazy and all inputs shift permanently in a completely random way
that I'm completely unable to understand.
I've come to incriminate the loop logic itself when I noticed that :
- If I set the loop values to process a single value, it still behaves crazy
for the corresponding input.
- If I remove the loop logic and set "i" manually to any given constant value,
then the corresponding input is processed appropriately ?!?
i.e.:
for (i=0; i<=0; i++) {
blah-blah-blah... ;
}
...and the system is mad, where :
i=0;
// for (i=0; i<=0; i++) {
blah-blah-blah... ;
// } End of loop commented out
...and input[0] is processed properly (and it works for any arbitray value of
"i").
I've lost so much sleep on this one that I really give up crying mother :-/
In case there would be some sdcc weirdness in there, and some nice folk would
like to take a look into my code or check the asm the compiler produces from
it, I attach the whole project below.
As a bonus, you'll get (working !) routines to play tunes from a PIC16F886 or
flash LEDs in nice ways, calculate and update program and EEPROM checksums, but
for processing a table if inputs with a stupid for(), no way... :-(
You'll find the incriminated loop in the "pompes_IO.c" file by looking for the
"DAMNED LOOP FROM HELL" comment :-\
My deppest gratitude will go to the helping hand :-}
--
Michel Bouissou (OpenPGP ID 0xEB04D09C)
pompes_LOOP_FROM_HELL.tar.bz2
Description: application/bzip-compressed-tar
------------------------------------------------------------------------------ Come build with us! The BlackBerry(R) Developer Conference in SF, CA is the only developer event you need to attend this year. Jumpstart your developing skills, take BlackBerry mobile applications to market and stay ahead of the curve. Join us from November 9 - 12, 2009. Register now! http://p.sf.net/sfu/devconference
_______________________________________________ Sdcc-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/sdcc-user
