hi i am trying to compare the value of two signed chars. one is a plain variable currentval while the other is a signed char inside an array of type signed char called spectrumarray.for some reason it doesnt work.
xdata signed char spectrumarray[256]; signed char currentval;//current value at this freq int xdata channel; for(channel=0;channel<256;channel++){ for(sample=0;sample<70;sample++){//sample 70 times at this freq currentval=halSpiReadStatus(CCxxx0_RSSI); //this just reads a register from some a source external to the microcontroller if((signed char)spectrumarray[channel] < (signed char)currentval) spectrumarray[channel]=currentval; //want to put currentval into the array if it is more than the value currently in the array } printf("%Bd\n\r",(signed char)currentval); //did this just to check to see what the currentval was }
Used this to initalize the array
void init_array(void){ int xdata arrayindex; for(arrayindex=0;arrayindex<256;arrayindex++){ spectrumarray[arrayindex]=-128;//initialize to the lowest value possible } }
I am sure the currentval values are more than what is inside the array when they are compared, yet when i print out the whole array it only holds -128 for every value except the last.I'm kind of stumped.oh yea forgot to mention im also new to the C51. microcontroller in use is the Silabs C8051F320.
if((signed char)spectrumarray[channel] < (signed char)currentval)
Those (signed char) casts are quite totally pointless.
I am sure the currentval values are more than what is inside the array when they are compared,
What makes you so sure?
oh yea the (signed char) cast, i was just frustrated and was just trying random stuff didnt make any diff tho.umm i printed it out right after each comparison to see what it was i.e right after the second for loop. the values were all more than -128. By doesn't work i mean the value at that postion in the array should be made equal to the value of currentval if it is less than currentval.however it doesn't change.im sorry if i wasnt too clear