BMP180气压传感器调试

BMP180气压传感器具有体积小,功耗低等优点,因为广泛的被应用于手机,手表等小型编写式设计,在淘宝上看到有现成的模块,就买了一个玩玩,目的是想将它和CC2540组合,做一个电子气压计,并通过蓝牙传送到手机。下面为BMP180在CC2540上的测试程序。

#include
#include "bmp180.h"
//#include "bmpi2c.h"
 
#include      //Keil library 
#include    //Keil library 
#include     //Keil library
 
#define   uchar unsigned char
#define   uint unsigned int
 
 
#define BMP085_SlaveAddress   0xee  //定义器件在IIC总线中的从地址                              
#define OSS 0// Oversampling Setting (note: code is not set up to use other OSS values)
 
 
typedef unsigned char  BYTE;
typedef unsigned short WORD;
 
long  temperature = 8;//温度值
long  pressure = 8;//压力值
long  height = 8;//相对海拔高度值
 
//uchar ge,shi,bai,qian,wan,shiwan;           //显示变量
int  dis_data;                              //变量
 
short ac1;
short ac2;
short ac3;
unsigned short ac4;
unsigned short ac5;
unsigned short ac6;
short b1;
short b2;
short mb;
short mc;
short md;

void Delay5us()
{
  unsigned int i,j;
  for(i=0;i<5;i++)
    for(j=0;j<50;j++);
  return;
}

void Delay_1ms(unsigned char msDelay)
{
  unsigned int i,j;
  for(i=0;i> 15;
x2 = ((long) mc << 11) / (x1 + md);
b5 = x1 + x2;
 temperature = ((b5 + 8) >> 4);
// conversion(temperature);
// DisplayOneChar(4,0,'T');       //温度显示
//     DisplayOneChar(5,0,':');
//     DisplayOneChar(7,0,bai);      
//     DisplayOneChar(8,0,shi);
//     DisplayOneChar(9,0,'.');
// DisplayOneChar(10,0,ge);
// DisplayOneChar(11,0,0XDF);     //温度单位
// DisplayOneChar(12,0,'C');
 
  b6 = b5 - 4000;
  // Calculate B3
  x1 = (b2 * (b6 * b6)>>12)>>11;
  x2 = (ac2 * b6)>>11;
  x3 = x1 + x2;
  b3 = (((((long)ac1)*4 + x3)<>2;
   
  // Calculate B4
  x1 = (ac3 * b6)>>13;
  x2 = (b1 * ((b6 * b6)>>12))>>16;
  x3 = ((x1 + x2) + 2)>>2;
  b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;
   
  b7 = ((unsigned long)(up - b3) * (50000>>OSS));
  if (b7 < 0x80000000)
    p = (b7<<1)/b4;
  else
    p = (b7/b4)<<1;
     
  x1 = (p>>8) * (p>>8);
  x1 = (x1 * 3038)>>16;
  x2 = (-7357 * p)>>16;
 pressure = p+((x1 + x2 + 3791)>>4);
 
//height=(101325-pressure)*9;
 height = 44330-4961*pow(pressure, 0.19);
 
 
 
// conversion(pressure);
//     DisplayOneChar(4,1,'P');    //显示压强
//     DisplayOneChar(5,1,':');
// DisplayOneChar(6,1,shiwan);
// DisplayOneChar(7,1,wan);   
//     DisplayOneChar(8,1,qian);
//     DisplayOneChar(9,1,'.');
//     DisplayOneChar(10,1,bai);
//     DisplayOneChar(11,1,shi);
// DisplayOneChar(12,1,'K');   //气压单位
// DisplayOneChar(13,1,'p');
// DisplayOneChar(14,1,'a');
 
}
 /*
void OLED_BMP180()
{
 
Init_BMP085(); 
bmp085Convert();
LCD_P8x16Str(20,3,"H:");
OLCD_P8x16(36,3,height/10000);
OLCD_P8x16(44,3,height%10000/1000);
OLCD_P8x16(52,3,height%1000/100);
//OLCD_P8x16(60,3,height%100/10);
LCD_P8x16Str(60,3,"M");
 
LCD_P8x16Str(20,5,"P:");
OLCD_P8x16(36,5,pressure/100000);
OLCD_P8x16(44,5,pressure%100000/10000);
OLCD_P8x16(52,5,pressure%10000/1000);
LCD_P8x16Str(60,5,".");
OLCD_P8x16(68,5,pressure%1000/100);
LCD_P8x16Str(76,5,"Kpa");
 
LCD_P8x16Str(20,1,"T:");
OLCD_P8x16(36,1,temperature/100);
OLCD_P8x16(44,1,temperature%100/10);
LCD_P8x16Str(52,1,".");
OLCD_P8x16(60,1,temperature%10);
LCD_P8x16Str(68,1,"'C");
 
}*/

BMP180气压传感器调试_第1张图片



你可能感兴趣的:(蓝牙,硬件)