This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

problem comparing signed char

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.

0