|
- /*
- * This file contains some mpu6050 operation.
- * By IC爬虫 (1394024051@qq.com)
- * 2014-12-19 v1.0
- */
- #include "MPL3115.h"
- #include "I2C.h"
- /**********************************************************/
- //函数名称:void MPL3115Init
- //入口参数:无
- //出口参数:无
- //函数功能:MPL3115初始化
- /**********************************************************/
- void MPL3115_Init()
- {
- I2C_Init(MPL3115A2_ADDRESS);
- I2C_Write(CTRL_REG1,0xB8);
- I2C_Write(PT_DATA_CFG,0x07);
- I2C_Write(CTRL_REG1,0xB9);
- }
- /**********************************************************/
- //函数名称:readAltitude
- //入口参数:无
- //出口参数:返回海拔
- //函数功能:读取MPL3115海拔
- /**********************************************************/
- float readAltitude()
- {
- uchar statu;
- unsigned char MSB=0,CSB=0,LSB=0;
- I2C_Read(STATUS,&statu);
- if(statu & 0x02)
- {
- I2C_Read(0x01,&MSB);
- I2C_Read(0x02,&CSB);
- I2C_Read(0x03,&LSB);
-
- float tempcsb = (LSB>>4)/16.0;
- float altitude = (float)( (MSB << 8) | CSB) + tempcsb;
- return(altitude);
- }
- return 0 ;
- }
- /**********************************************************/
- //函数名称:readTemp
- //入口参数:无
- //出口参数:返回温度
- //函数功能:读取MPL3115温度值
- /**********************************************************/
- float readTemp()
- {
- uchar statu;
- uchar T_MSB=0,T_LSB=0;
- I2C_Read(STATUS,&statu);
- if( statu & 0x02)
- {
- I2C_Read(0x04,&T_MSB);
- I2C_Read(0x05,&T_LSB);
- float temperature = (float)(T_MSB + (float)(T_LSB>>4)/16);
- return(temperature);
- }
- return 0;
- }
复制代码
|
|