奇怪,太奇怪了!
void SpidermanSendCmdFeedback()
{
NWK_PACKET_V3 feedback_sp;
int i=0;
int crc;
feedback_sp.addrInfo_v3 = 0x00;//保留
feedback_sp.frameHead_f_v3 = 0x55;
feedback_sp.frameHead_s_v3 = 0xaa;
feedback_sp.frameType_v3 = 0x0a;// cmd feedback_sp type
feedback_sp.DeviceType_v3 = 0x07;
feedback_sp.PVersion_v3 = 0x03;
//feedback_sp.length = 0x07;
feedback_sp.hop_v3 = 0x00;
feedback_sp.payload_v3[i++] = 0xff;
feedback_sp.payload_v3[i++] = 0xff;//feedback_sp addr
//feedback_sp.payload[i++] =
switch(usart.pBuffer[0])
{
case 17:
feedback_sp.payload_v3[i++] = usart.pBuffer[usart.pBuffer[0] - 4];
break;
case 25:
feedback_sp.payload_v3[i++] = usart.pBuffer[usart.pBuffer[0] - 10];
break;
default:
feedback_sp.payload_v3[i++] = 0xff;
break;
}
feedback_sp.payload_v3[i++] = 0x04;
switch(usart.pBuffer[0])
{
case 17:
feedback_sp.payload_v3[i++] = usart.pBuffer[usart.pBuffer[0] - 5];//包序列号
feedback_sp.payload_v3[i++] = usart.pBuffer[usart.pBuffer[0] - 1];//crc1
feedback_sp.payload_v3[i++] = usart.pBuffer[usart.pBuffer[0]]; //crc2
break;
case 25:
feedback_sp.payload_v3[i++] = usart.pBuffer[usart.pBuffer[0] - 11];//包序列号
feedback_sp.payload_v3[i++] = usart.pBuffer[usart.pBuffer[0] - 1];//crc1
feedback_sp.payload_v3[i++] = usart.pBuffer[usart.pBuffer[0]]; //crc2
break;
default:
feedback_sp.payload_v3[i++] = 0xff;
feedback_sp.payload_v3[i++] = 0xff;
feedback_sp.payload_v3[i++] = 0xff;
break;
}
feedback_sp.payload_v3[i++] = 0x02;//指令送达蜘蛛侠成功
feedback_sp.length_v3 = i+ 1+ 2;
crc = addCrc(&feedback_sp);
feedback_sp.payload_v3[i++] = crc;
feedback_sp.payload_v3[i++] = crc >> 8;
printRawTy( (char*)&feedback_sp.frameHead_f_v3,feedback_sp.length_v3 + PACKET_HEADER_SIZE - 1 );
}
访问此函数时如果机构体变量feedback_sp定义为局部变量的话,函数执行完毕后,结构体变量的值均没发生变化,时局部变量的默认值;但是将此变量定义为全局变量的话,函数执行完毕后,结构体变量的值是期望的值,我用的是IAR for AVR编译器。请问则是为什么呀?是不是编译器设置不对还是另有原因?
[解决办法]