//寄存器地址定义
#define BMP085_ADD 0xEE
#define AC1_ADD 0xAA
#define AC2_ADD 0xAC
#define AC3_ADD 0xAE
#define AC4_ADD 0xB0
#define AC5_ADD 0xB2
#define AC6_ADD 0xB4
#define B1_ADD 0xB6
#define B2_ADD 0xB8
#define MB_ADD 0xBA
#define MC_ADD 0xBC
#define MD_ADD 0xBE
#define oss 3
/***************************************/
//毫秒延迟
/**************************************/
void msdelay(uint num)
{
uint i;
for(i=0;i<num;i++)
{
while(bmp085_delay_1ms==FALSE);
bmp085_delay_1ms=FALSE;
}
}
//读UT
long UT_READ(void)
{
uchar cmd[1];
uchar reg[2];
long UT=0;
cmd[0]=0x2E;
IIC_Str_Write(BMP085_ADD, 0xF4, cmd, 1);
msdelay(10);
IIC_Str_Read(BMP085_ADD, 0xF6, reg, 2);
UT=((long)reg[0]<<8)+reg[1];
return UT;
}
//读UP
long UP_READ(void)
{
uchar cmd[1];
uchar reg[3];
long UP;
cmd[0]=0x34+(oss<<6);
IIC_Str_Write(BMP085_ADD, 0xF4, cmd, 1);
if(oss==0)
msdelay(10);
else if(oss==1)
msdelay(13);
else if(oss==2)
msdelay(19);
else if(oss==3)
msdelay(31);
IIC_Str_Read(BMP085_ADD, 0xF6, reg, 3);
UP=(((long)reg[0]<<16)+((int)reg[1]<<8)+reg[2])>>(8-oss);
return UP;
}
//定义参数结构体
typedef struct
{
ulong UT;
ulong UP;
long P;
uint T;
int AC1;
int AC2;
int AC3;
uint AC4;
uint AC5;
uint AC6;
int B1;
int B2;
int MB;
int MC;
int MD;
} BMP085_Def;
BMP085_Def BMP085_DAT;
//参数计算,和规格书校正过好几遍,没发现啥问题
void BMP085_Calcu()
{
long x1,x2,x3,B3,B5,B6,B7;
ulong B4;
x1 = (BMP085_DAT.UT - BMP085_DAT.AC6) * BMP085_DAT.AC5 / 32768;
x2 = (BMP085_DAT.MC * 2048)/(x1 + BMP085_DAT.MD);
B5 = x1 + x2;
BMP085_DAT.T = (B5 + 8)/16;
Current_temp=BMP085_DAT.T /10.0;
B6 = B5 - 4000;
x1 = (BMP085_DAT.B2*(B6 * B6/4096))/2048;
x2 = BMP085_DAT.AC2 * B6/2048;
x3 = x1 + x2;
B3 = ((BMP085_DAT.AC1 * 4 + x3) << oss + 2)/4;
x1 = BMP085_DAT.AC3 * B6/8192;
x2 = (BMP085_DAT.B1 * (B6 * B6/4096))/65536;
x3 = ((x1 + x2) + 2)/4;
B4 = BMP085_DAT.AC4 * ((ulong)(x3 + 32768))/32768;
B7 = ((ulong)BMP085_DAT.UP - B3) * (50000 >> oss);
if(B7 < 0x80000000)
BMP085_DAT.P = (B7 * 2)/B4;
else
BMP085_DAT.P = (B7/B4)*2;
x1 =( BMP085_DAT.P/256)*( BMP085_DAT.P/256);
x1 = (x1*3038)/65536;
x2 = (-7357* BMP085_DAT.P)/65536;
BMP085_DAT.P = BMP085_DAT.P + (x1 + x2 + 3791)/16;
Current_press=BMP085_DAT.P /1000.0;
}
//BMP085整个运行函数
void BMP085_process(void)
{
uchar reg[2];
if(!Read_BMP085)
return;
Read_BMP085=FALSE;
//bmp085读寄存器
IIC_Str_Read(BMP085_ADD, AC1_ADD, reg, 2);
BMP085_DAT.AC1=((int)reg[0]<<8)+reg[1];
IIC_Str_Read(BMP085_ADD, AC2_ADD, reg, 2);
BMP085_DAT.AC2=((int)reg[0]<<8)+reg[1];
IIC_Str_Read(BMP085_ADD, AC3_ADD, reg, 2);
BMP085_DAT.AC3=((int)reg[0]<<8)+reg[1];
IIC_Str_Read(BMP085_ADD, AC4_ADD, reg, 2);
BMP085_DAT.AC4=((uint)reg[0]<<8)+reg[1];
IIC_Str_Read(BMP085_ADD, AC5_ADD, reg, 2);
BMP085_DAT.AC5=((uint)reg[0]<<8)+reg[1];
IIC_Str_Read(BMP085_ADD, AC6_ADD, reg, 2);
BMP085_DAT.AC6=((uint)reg[0]<<8)+reg[1];
IIC_Str_Read(BMP085_ADD, B1_ADD, reg, 2);
BMP085_DAT.B1=((int)reg[0]<<8)+reg[1];
IIC_Str_Read(BMP085_ADD, B2_ADD, reg, 2);
BMP085_DAT.B2=((int)reg[0]<<8)+reg[1];
IIC_Str_Read(BMP085_ADD, MB_ADD, reg, 2);
BMP085_DAT.MB=((int)reg[0]<<8)+reg[1];
IIC_Str_Read(BMP085_ADD, MC_ADD, reg, 2);
BMP085_DAT.MC=((int)reg[0]<<8)+reg[1];
IIC_Str_Read(BMP085_ADD, MD_ADD, reg, 2);
BMP085_DAT.MD=((int)reg[0]<<8)+reg[1];
BMP085_DAT.UT=UT_READ();
BMP085_DAT.UP=UP_READ();
BMP085_Calcu();
}
计算出来 温度:40.5度 大气压:50.12KP 求指正!!!!
一周热门 更多>