I'm trying to fill an array with a rotating counts then add the all up each time the sub is called. When I simulate this code I never see the i++ index. I guess keil supports i++ by itself.
i++; if(i == 10){i == 0;} array[i] = data; data = 0; for (a = 0; a < 10 ; a++) {data = data + array[i];}
i++; // What's this doing here? // You're incrementing i, but haven't initialised it if(i == 10){i == 0;} // Should be i=0 ? array[i] = data; // you're putting an uninitialised value from data into one element of array // i was uninitialised, so it could be anything now // (because of the preceding error, i could even be 10!) data = 0; // having just used data, you now initialise it! for (a = 0; a < 10 ; a++) {data = data + array[i];} // you repeat this assignment 10 times // still using the undefined value of 'i' each time
I did post an error when I posted the
{i == 0;}
{i=0;}
It's hard to figure things out since you didn't specify any variable types.
i++;
if(i == 10){i == 0;}
array[i] = data; data = 0; for (a = 0; a < 10 ; a++) {data = data + array[i];}
unsigned int func (unsigned char data) { #define ARRAY_SIZE 10 static unsigned char ndx = 0; static unsigned char array [ARRAY_SIZE] = { 0, }; static unsigned int array_ttl; if (++i >= ARRAY_SIZE) i = 0; array_ttl -= array[ndx]; // remove oldest data array_ttl += data; // add newest data array[ndx] = data; // add newest data to array return (array_ttl); // return total or return (array_ttl/ARRAY_SIZE); // return average }
for (a = 0; a < 10 ; a++) {data = data + array[i];}
data = data + array[i];
"The simulator was only updating the results when I minimized the maximized my window." Have you checked 'Periodic Window Update' on the 'View' menu?
Why would you use
unsigned char array [ARRAY_SIZE]