我试图将两个8位数组合为无符号整数,但无论使用何种类型转换,结果仍然是有符号数字。该代码是使用CodeWarrior 10.1编译的,用于freescale微处理器MC9S08LH64。
我尝试过但不起作用的方法有: - 移位并添加两个8位数字,然后在每个步骤中将它们强制转换为无符号int。 - 使用union / struct组合两个8位数并将它们及结果数字类型转换为无符号int。 - 使用无符号int指针(以下是代码)。
我尝试过但不起作用的方法有: - 移位并添加两个8位数字,然后在每个步骤中将它们强制转换为无符号int。 - 使用union / struct组合两个8位数并将它们及结果数字类型转换为无符号int。 - 使用无符号int指针(以下是代码)。
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;