printf支持MSP430微控制器 [英] printf support for MSP430 micro-controller

查看:691
本文介绍了printf支持MSP430微控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用不同的C编译器为Texas Instruments(TI)MSP430微控制器升级全面测试的C程序,从Quadravox,AQ430开发工具更改为VisualGDB C编译器。



该程序使用VisualGDB编译零错误和零警告。中断服务程序,定时器,UART控制等等都似乎正在运行。然而,sprintf的某些用途不起作用。例如:

  unsigned int duration; 
float msec;

msec =(float)duration;

msec = msec / 125.0;

sprintf(glb_response,break:%3.1f msec,msec);

返回: break:%3.1f msec



这是预期的: break:12.5 msec


$ b $我已经了解了以下内容(维基百科):


编译器选项--printf_support = [full |最小| nofloat]允许
使用一个较小的,功能有限的,printf / sprintf的变体,
在构建时做出选择。



有效值为:



full:支持所有格式说明符。这是默认值。



nofloat:不包括支持打印浮点值。支持
除%f,%g,%G,%e和%E之外的所有格式说明符。



minimal:支持打印整数,或字符串值
,不带宽度或精度标志。具体来说,仅支持%%,%d,%o,
%c,%s和%x格式说明符




我需要完全支持printf。我知道我的产品上的MSP430将支持这一点,因为这个C程序已经服务了好几年了。



我的问题是我无法弄清楚1)如果VisualGDB有办法将printf支持设置为full,2)如果是,在哪里设置它。



任何和所有评论和答案将不胜感激。

解决方案

我建议对浮点数的充分支持是不必要的和不明智的。解决一个琐碎的问题是一个大量的代码;在没有浮点硬件的情况下,浮点运算通常在性能,代码空间和内存使用原因的情况下都是最好的避免。



所以看来,$ code>持续时间以1/125000秒为单位,您希望输出的值为0.1毫秒的精度。所以:

  unsigned msec_x10 = duration * 10u / 125u; 

sprintf(glb_response,
break:%u。%u msec,
msec_x10 / 10,
msec_x10%10);

如果要舍入到最接近的十分之一(而不是舍入),则:

  unsigned msec_x10 =((duration * 20u)+ 125)/ 250u; 


I am upgrading a fully tested C program for the Texas Instruments (TI) MSP430 micro-controller using a different C compiler, changing from the Quadravox, AQ430 Development Tool to the VisualGDB C compiler.

The program compiles with zero errors and zero warnings with VisualGDB. The interrupt service routines, timers, UART control, and more all seem to be working. Certain uses of sprintf, however, are not working. For example:

unsigned int duration;
float msec;

msec = (float)duration;

msec = msec / 125.0;

sprintf(glb_response,"break: %3.1f msec",msec);

This returns: break: %3.1f msec

This is what is expected: break: 12.5 msec

I have learned about the following (from Wikipedia):

The compiler option --printf_support=[full | minimal | nofloat] allows you to use a smaller, feature limited, variant of printf/sprintf, and make that choice at build time.

The valid values are:

full: Supports all format specifiers. This is the default.

nofloat: Excludes support for printing floating point values. Supports all format specifiers except %f, %g, %G, %e, and %E.

minimal: Supports the printing of integer, char, or string values without width or precision flags. Specifically, only the %%, %d, %o, %c, %s, and %x format specifiers are supported

I need full support for printf. I know the MSP430 on my product will support this, as this C program has been in service for years.

My problem is that I can't figure out 1) if VisualGDB has the means to set printf support to full and 2) if so, where and to set it.

Any and all comments and answers will be appreciated.

解决方案

I would suggest that full support for floating point is both unnecessary and ill-advised. It is a large amount of code to solve a trivial problem; and without floating-point hardware, floating point operations are usually best avoided in any case for performance, code space and memory usage reasons.

So it appears that duration is in units of 1/125000 seconds and that you wish to output a value to a precision of 0.1 milliseconds. So:

unsigned msec_x10 = duration * 10u / 125u ;

sprintf( glb_response, 
         "break: %u.%u msec", 
         msec_x10 / 10,  
         msec_x10 % 10 ) ;

If you want rounding to the nearest tenth (as opposed to rounding down), then:

unsigned msec_x10 = ((duration * 20u) + 125 ) / 250u ;

这篇关于printf支持MSP430微控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆