I am trying to combine two 8-bit number to an unsigned int but no matter what type casting I use, the result is still signed number. The code is complied using CodeWarrior 10.1 for freescale micro processor MC9S08LH64.
Things I tried that did not work - shift and add the two 8bits number then type cast them to be unsigned int at every step. - union/struct to combine the two 8-bit type cast them and the result number to unsigned int. - use unsigned int pointer (code below)
unsigned int acquire_sensor_voltage_internal_adc()
{ //this is internal ADC
unsigned int result;
unsigned int* data_ptr;
char print_buffer [50];
int_convert cvt;
//internal adc collecting counts of input voltage
//______________________________________________
//writing to ADCSC1A initiate the conversion sequence
ADCSC1A= 0x09;
while(!ADCSC1A_COCOA){}
cvt.parts.p0 = ADCRHA;
cvt.parts.p1 = ADCRLA;
data_ptr = &cvt.int_number;
result = (unsigned int)*data_ptr;
sprintf(print_buffer,"here!!!>>>>>>>%d\r\n",result);
serial_sendString(print_buffer,strlen(print_buffer));
//_______________________________________________
return (unsigned int) result;
}
//definition of int_convert from.h file
typedef union{
unsigned int int_number;
struct{
unsigned char p0;
unsigned char p1;
}parts;
}int_convert;