yl101310 发表于 2008-8-21 10:49:55

请问在AVR怎么使用printf这样的函数

请问在AVR怎么使用printf这样的函数啊?

zxq6 发表于 2008-8-22 12:57:20

来自iccavr的帮助
int printf(char *fmt, ..)

prints out formatted text according to the format specifiers in the fmt string. The format specifiers are a subset of the standard formats. The full conversion specification is:

%*[.precision]<conversion character>

The flags are:

#                 - alternate form. For the 'x' or 'X' conversion, a 0x or 0X is generated. For the floating point conversions, a decimal point is generated even if the floating point value is exactly an integer.

- (minus)        - left align the output

+ (plus)        - add a '+' sign character for positive integer output

' ' (space)        - use space as the sign character for positive integer

0                - pad with zero instead of spaces

The width is either a decimal integer or '*', denoting that the value is taken from the next argument. The width specifies the minimal number of characters that will be printed, left or right aligned if needed and padded with either spaces or zeros, depending on the flag characters.

The precision is preceded by a '.' and is either a decimal integer or '*', denoting that the value is taken from the next argument. The precision specifies the minimal number of digits for an integer conversion, the maximum number of characters for the 's' string conversion, and the number of digits after the decimal point for the floating point conversions.

The conversion characters are as follows. If an 'l' (letter el) appears before an integer conversion character, then the argument is taken as a long integer.

%d - prints the next argument as a decimal integer

%o - prints the next argument as an unsigned octal integer

%x - prints the next argument as an unsigned hexadecimal integer

%X - the same as %x except that upper case is used for 'A'-'F'

%u - prints the next argument as an unsigned decimal integer

%s - prints the next argument as a C null terminated string

%c - prints the next argument as an ASCII character

%f - prints the next argument as a floating point number in decimal <aaa>.<bbbb> format

%e, %E - prints the next argument as a floating point number in scientific notation <a>.<bbb>e<exp> format. %e uses small 'e' and %E uses capital 'E'

%g, %G - printfs the next argument as a floating point number in either decimal or scientific notation.

printf is supplied in three versions, depending on your code size and feature requirements (the more features, the higher the code size):

Basic: only %c, %d, %x, %u, and %s format specifiers without modifiers are accepted.
        Long: the long modifiers %ld, %lu, %lx are supported, in addition to the width and precision fields.
        Floating point: all formats including %f for floating point are supported.

The code size is significantly larger as you progress down the list. You select the version to use in the Compiler Options dialog box.

printf returns the number of characters printed.

talentandy008 发表于 2011-9-9 11:23:21

呵呵,论坛里有很多例子
页: [1]
查看完整版本: 请问在AVR怎么使用printf这样的函数