?? temprature.c
字號(hào):
#include <stdio.h>
#include <math.h>
double calculate_exponent();
int calculate_sign();
double calculate_mantissa();
double ieee_to_decimal();
double temprature();
double calculate_exponent(int eb)/*計(jì)算e的值*/
{
double exponent = 0;
exponent = eb - 127;
return (exponent);
}
int calculate_sign(int high_byte)/*計(jì)算符號(hào)位*/
{
if(128 & high_byte)
return (1);
else
return (0);
}
double calculate_mantissa(int high_byte, int mid_byte, int low_byte)/*計(jì)算mantissa的值*/
{
int power = 0;
int multiplier = 0;
float mantissa = 0;
long int mantissa_bits;
long int index = 8388608; /* 0b 100000000000000000000000 */
high_byte &= 127; /* strip off sign bit. */
mantissa_bits = (low_byte + (mid_byte * 256) + (high_byte * 65536) + 8388608);/*組合成標(biāo)準(zhǔn)的long int*/
for (power = 0; power >= -23; power--)/**/
{
if ((mantissa_bits & index)!=0)
multiplier = 1;
else
multiplier = 0;
mantissa = mantissa + (pow(2,power) * multiplier);
index = index/2; /* index向右移一位 */
}
return (mantissa);
}
double ieee_to_decimal(int eb, int high_byte, int mid_byte, int low_byte)
{
double decimal_result = 0;
double mantissa = 0;
double exponent = 0;
int sign = 0; /* 0 = positive, 1 = negative */
mantissa = calculate_mantissa(high_byte,mid_byte,low_byte);
exponent = calculate_exponent(eb);
sign = calculate_sign (high_byte);
decimal_result = ((pow(-1,sign))*(mantissa)*pow(2,exponent));
return (decimal_result);
}
/*double pow(x,y)是math.h里面的標(biāo)準(zhǔn)函數(shù):是計(jì)算 x exp(y)的值 就是計(jì)算x的y次冪*/
double temprature(int temp,int ad2,int ad3,int ad1,int cal1_H,int cal1_L,int cal2_H,int cal2_L,int temp1_H,int temp1_L,int temp2_H,int temp2_L)
{
double cal1,cal2,temp1,temp2; /*要定義成全局變量*/
double N1,Vin,tempbuf;
int lowbyte,midbyte,highbyte,exp;
lowbyte=(cal1_H>>8);
midbyte=(cal1_H&0x0f);
highbyte=(cal1_L>>8);
exp=(cal1_L&0x0f);
cal1=ieee_to_decimal(exp, highbyte,midbyte, lowbyte);
lowbyte=(cal2_H>>8);
midbyte=(cal2_H&0x0f);
highbyte=(cal2_L>>8);
exp=(cal2_L&0x0f);
cal2=ieee_to_decimal(exp, highbyte,midbyte, lowbyte);
lowbyte=(temp1_H>>8);
midbyte=(temp1_H&0x0f);
highbyte=(temp1_L>>8);
exp=(temp1_L&0x0f);
temp1=ieee_to_decimal(exp, highbyte,midbyte, lowbyte);
lowbyte=(temp2_H>>8);
midbyte=(temp2_H&0x0f);
highbyte=(temp2_L>>8);
exp=(temp2_L&0x0f);
temp2=ieee_to_decimal(exp, highbyte,midbyte, lowbyte);
N1=ad3-(ad2-ad3)*cal1;
Vin=(temp-N1)/(ad1-N1)*cal2;
tempbuf=25+(Vin-temp1)/temp2;
return(tempbuf);
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -