binaris - decimalis szubrutin
HWSW Famulus
hwsw at famulus.hu
Thu Nov 3 12:14:41 CET 2005
> A kovetkezo kodolasra nem tud valaki egy binaris - decimalis
> atalakito szubrutint? PIC16fxxx-hez kellene,
> Ketto regiszter lenne a bemenet es X regiszter lenne a kimenet.
>
> Internally, this calculation is performed by the DS1624 to provide
> 0.03125 C resolution.
> The temperature reading is provided in a 13 bit,
> two s complement reading by issuing READ TEMPERATURE command.
> Table 2 describes the exact relationship of output data to measured
> temperature.
> The data is transmitted serially through the 2 wire serial interface,
> MSB first.
> The DS1624 can measure temperature over the range of -55 C to +125 C
> in 0.03125 C increments. For Fahrenheit usage a lookup table or
> conversion factor must be used.
>
> TEMPERATURE/DATA RELATIONSHIPS Table 2
> TEMP DIGITAL OUTPUT (Binary) DIGITAL OUTPUT (Hex)
> +125C 01111101 00000000 7D00h
> +25.0625C 00011001 00010000 1910h
> +0.5C 00000000 10000000 0080h
> +0C 00000000 00000000 0070h
> -0.5C 11111111 10000000 FF80h
> -25.0625C 11100110 11110000 E6F0h
> -55C 11001001 00000000 C900h
>
> --
> udv.:
> jozsi
Nekem a google azt adta ki pl....
KJ
--------------------------
Format of Temperature Data.
The temperature data is returned as two bytes. The first byte, T.BYTE1
contains the whole part in degrees C. The highest five bits of the second
byte, T.BYTE0 consists of the fractional part. This is the number of 0.03125
degrees C.
For example, consider;
0001 1001 0001 0000
whole part fract part in upper 5 bits
= 16 + 8 + 1 = 2 * 0.03125
Thus the temperature is 25.0625 or 25.06.
Thus the fractional portion may be calculated;
T_FRACT_100 = ((T.BYTE0 >> 3) * 312) / 10
Thus, the temperature could be then displayed as;
DEBUG DEC T.BYTE1, ".", DEC T_FRACT_100, CR
Note that the most significant bit of T.BYTE1, is a sign bit; 0 indicates
positive and 1 indicates negative. Thus, if negative, the two's compliment
of the result must be taken.
For example;
1110 0110 1100 1000
Ones Comp 0001 1001 0011 0111
Twos Comp 0001 1001 0011 1000
Thus the whole part is 16+8+1 or 25. The fractional part is 0.03125 *
(4+2+1) or 0.22 degrees C. Thus, the result is -25.22 degrees C.
This may be implemented;
IF (T.BIT15 <> 0) THEN MINUS
T_FRACT_100 = ((T.BYTE0 >> 3) * 312) / 10
DEBUG DEC T.BYTE1, ".", DEC T_FRACT_100, CR
GOTO CONTINUE
MINUS:
T = ~T + 1 ' perform two's complement
T_FRACT_100 = ((T.BYTE0 >> 3) * 312) / 10
DEBUG "-", DEC T.BYTE1, ".", DEC T_FRACT_100, CR
GOTO CONTINUE
CONTINUE:
More information about the Elektro
mailing list