Hallo µC Fans,
die Temperatur einzulesen vom LM75 klappt bereits- die Steht bei mir in
einem unsigned char als 8-Bit. Bei 25,5°C have ich im Byte den Wert 51 -
den die Auflösung ist 0,5°C. Um die Temperatur in einer unganzen Zahl
darzustellen (z.B. 25,5) wollte ich den wert in eine float Variable
kopieren und dann durch 2 teilen. Aber es klappt nicht.
Zwei Fehlermöglichlkeiten:
1.Die Typumwandlung funktioniert nicht (value_0 ist unsigned char und
soll in float f_temperat geschrieben werden)
2.Der sprintf(s, "Temperatur= %f",f_temperat); Befehl funktioniert
nicht richtig. Den auf dem Display wird ein String ausgegeben "Integer
only ... -lfp"
Copmiler ist ICC
Mein Code
f_temperat=(float)value_0;
sprintf(s, "Temperatur= %f",f_temperat);
lcd_WR_string(LCD_L4,&s[0]);
für printf Befehl Steht im Handbuch (ich komme damit nicht klar):
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:
%[flags]*[width][.precision][l]<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