这是我琢磨的BMP180的程序,串口输出测量值。检测出的温度始终不对,气压没问题。海拔高度的计算随便从网上扒了一个。大家一起交流,集思广益。
#include
#include
#include
#define uchar unsigned char
#define uint unsigned int
sbit SDA=P1^0;
sbit SCL=P1^1;
uchar code Comd0[]="temp:";
uint tempre[6];
#define OSS 1 // 过采样设置,(OSS可取0,1,2,3)
long temperature=0; //温度值
long pressure=0; //压力值
float height=0; //相对海拔高度值
short ac1;
short ac2;
short ac3;
short ac4;
short ac5;
short ac6;
short b1;
short b2;
short mb;
short mc;
short md;
void Some_Nop()
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
void Delay_ms(uchar i)
{
uint j;
for(;i>0;i--)
for(j=0;j<124;j++);
}
void Delay_s() //延时1s
{
uchar i;
for(i=0;i<20;i++)
{
TH0=0x4c;
TL0=0x00;
TR0=1;
while(TF0==0);TF0=0;
TR0=0;
}
}
/*************** I2C *******************/
/*****************************************************/
void I2C_init() //I2C初始化
{
SDA=1;
SCL=1;
}
void I2C_Start() //I2C开始
{
SDA=1;
Some_Nop();
SCL=1;
Some_Nop();
SDA=0;
Some_Nop();
SCL=0;
_nop_();
}
void I2C_Stop() //I2C结束
{
SD