我正在尝试将两个 8 位数字组合成一个无符号整数,但无论我使用什么类型的转换,结果仍然是有符号数。该代码使用飞思卡尔微处理器 MC9S08LH64 的 CodeWarrior 10.1 编译。
我试过的东西不起作用 - 移动并添加两个 8 位数字,然后在每一步都将它们强制转换为无符号整数。- union/struct 将两个 8 位类型组合起来,并将结果编号转换为 unsigned 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;