金牌会员
 
- 积分
- 1065
- 金钱
- 1065
- 注册时间
- 2012-6-18
- 在线时间
- 157 小时
|
发表于 2015-12-18 15:51:58
|
显示全部楼层
/**************************实现函数********************************************
*函数原型: void BMP180_init(void)
*功 能: 供外部调用的初始化程序
*******************************************************************************/
void BMP180_init(void) {
_cm_Offset = 0;
_Pa_Offset = 0; // 1hPa = 100Pa = 1mbar
//初始化气压传感器,
//MODE_ULTRA_HIGHRES 高精度测量模式
BMP_init(MODE_ULTRA_HIGHRES, 0, 1);
}
/**************************实现函数********************************************
*函数原型: void BMP180_getTemperature(int32_t *_Temperature,u8 rw)
*功 能: 读取温度值。
输入 :
int32_t *_Temperature 温度结果存放的指针
u8 rw 是否需要等待 0 则不需要等待。
*******************************************************************************/
void BMP180_getTemperature(int32_t *_Temperature,u8 rw) {
BMP180_calcTrueTemperature(rw); // force b5 update
*_Temperature = ((b5 + (int32_t)8) >> 4);
}
void BMP180_getAltitude(int32_t *_centimeters,u8 rw){
int32_t TruePressure;
BMP180_calcTruePressure(&TruePressure,rw);
BMP180_newPressure(TruePressure);
TruePressure = last_Pressure;
*_centimeters = 4433000 * (1 - pow((TruePressure / (float)_param_datum), 0.1903)) + _cm_Offset;
// converting from float to int32_t truncates toward zero, 100.999985 becomes 100 resulting in 1 cm error (max).
}
void BMP180_calcTrueTemperature(u8 rw){
int32_t ut,x1,x2,mctemp,mdtemp;
if(rw){
BMP180_writemem(CONTROL, READ_TEMPERATURE);
delay_ms(10); // min. 4.5ms read Temp delay
}
BMP180_readmem(CONTROL_OUTPUT, 2, _buff);
ut = ((int32_t)_buff[0] << 8 | ((int32_t)_buff[1])); // uncompensated temperature value
// calculate temperature
x1 = (((int32_t)ut - (int32_t)ac6) * (int32_t)ac5) >> 15;
mctemp= mc;
mdtemp= md;
x2 = (mctemp <<11) / (x1 + mdtemp);
b5 = x1 + x2;
} |
|