高级会员

- 积分
- 597
- 金钱
- 597
- 注册时间
- 2014-10-15
- 在线时间
- 138 小时
|
1金钱
我用STM32F103VCT6写程序。
有一下一段代码: 这段代码会跑飞。 其中: - case 5:
- if(Encoder.Uint<SP_Read.Encoder_Sample[0].Uint)
- ShiftValue0=0.0f;
- else if(Encoder.Uint<SP_Read.Encoder_Sample[1].Uint)
- ShiftValue0=((float)(Encoder.Uint-SP_Read.Encoder_Sample[0].Uint)) * \
- SP_Read.Encoder_Xsh1[0].Float;
- else if(Encoder.Uint<SP_Read.Encoder_Sample[2].Uint)
- ShiftValue0=((float)(Encoder.Uint-SP_Read.Encoder_Sample[1].Uint)) * \
- SP_Read.Encoder_Xsh1[1].Float+((float)SP_Read.WyBzz[0].Uint);
- else if(Encoder.Uint<SP_Read.Encoder_Sample[3].Uint)
- ShiftValue0=((float)(Encoder.Uint-SP_Read.Encoder_Sample[2].Uint)) * \
- SP_Read.Encoder_Xsh1[2].Float+((float)SP_Read.WyBzz[1].Uint);
-
- else if(Encoder.Uint<SP_Read.Encoder_Sample[4].Uint)
- ShiftValue0=((float)(Encoder.Uint-SP_Read.Encoder_Sample[3].Uint)) * \
- SP_Read.Encoder_Xsh1[3].Float+((float)SP_Read.WyBzz[2].Uint);
- // else if(Encoder.Uint<SP_Read.Encoder_Sample[5].Uint)
- // ShiftValue0=((float)(Encoder.Uint-SP_Read.Encoder_Sample[4].Uint)) * \
- // SP_Read.Encoder_Xsh1[4].Float+((float)SP_Read.WyBzz[3].Uint);
- // else
- // ShiftValue0=((float)(Encoder.Uint-SP_Read.Encoder_Sample[5].Uint)) * \
- // SP_Read.Encoder_Xsh1[4].Float+((float)SP_Read.WyBzz[4].Uint);
- break;
-
复制代码把这段注释掉,就不跑飞了,加上就不行。 大神看看,哪里有问题。谢谢
|
最佳答案
查看完整内容[请看2#楼]
你不觉得 char s[8]
然后%-10.2f到s这个数据里面本身就数据越界了嘛,其他的case可能算出来的浮点数小,你那个case如果整数位大于一定程度肯定越界
|