</pre><p>BMP180气压传感器具有体积小,功耗低等优点,因为广泛的被应用于手机,手表等小型编写式设计,在淘宝上看到有现成的模块,就买了一个玩玩,目的是想将它和CC2540组合,做一个电子气压计,并通过蓝牙传送到手机。下面为BMP180在CC2540上的测试程序。</p><p></p><p></p><pre name="code" class="cpp"><span style="font-family: Arial, Helvetica, sans-serif;">#include<ioCC2540.h></span>
#include "bmp180.h"
//#include "bmpi2c.h"
#include <math.h> //Keil library
#include <stdlib.h> //Keil library
#include <stdio.h> //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<msDelay;i++)
for(j=0;j<5;j++);
return;
}
/**************************************
延时5毫秒(STC90C52RC@12M)
不同的工作环境,需要调整此函数
当改用1T的MCU时,请调整此延时函数
**************************************/
void Delay5ms()
{
WORD n = 25;
while (n--);
}
/**************************************
起始信号
**************************************/
void BMP085_Start()
{
P1DIR |= 0X01;
SDA=1; //拉高数据线
SCL=1; //拉高时钟线
Delay5us(); //延时
SDA=0; //产生下降沿
Delay5us(); //延时
SCL = 0;