有关指针问题
struct rcv_rtu_msg{
unsigned short rtuId;
unsigned short deviceId;
unsigned short deviceType;
//unsigned long time;
unsigned short lenth;
unsigned short Data;
unsigned short checkSum;
};
rtu_msg.rtuId = RTU_ID;//宏定义
rtu_msg.lenth = RTU_DATA_LENTH;//宏定义
rtu_msg.checkSum = RTU_CHECKSUM;//宏定义
unsigned short *p_deviceType = (unsigned short *)Uart0RecvDat;
rtu_msg.deviceType = *p_deviceType;
p_deviceType++;
unsigned short *p_deviceId = (unsigned short *)p_deviceType;
rtu_msg.deviceId = *p_deviceId;
p_deviceId++;
unsigned short *p_data = (unsigned short *)p_deviceId;
rtu_msg.Data = *p_data;
由于不能发图片,我把Uart0RecvDat数组里面的内容说一下:[0] = 0x01即1 [1]= 0x00即0 [2] = 0x01 [3] = 0x00 [4] = 0xc7 [5] = 0x01 这些都是我中断捕获的数据,并且是正确的,所需要的。
背景:想将char Uart0RecvDat[]数组的内容赋值给结构体
上面是我定义的结构体我利用仿真查看了p_deviceType所指向数组的值是1,为什么赋值后的rtu_msg.deviceType的值是262 。下面的两个赋值也出现同样问题,求解决各位高手~~
[ 本帖最后由 bob24432972 于 2013-7-15 20:28 编辑 ]