久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费
標題:
BMP180氣壓傳感器arduino與51單片機源碼及數據手冊下載
[打印本頁]
作者:
yezhongmang
時間:
2018-5-21 17:55
標題:
BMP180氣壓傳感器arduino與51單片機源碼及數據手冊下載
網上找來的,需要的可以看一看
0.png
(123.73 KB, 下載次數: 44)
下載附件
2018-5-22 01:09 上傳
arduino源程序如下:
//Arduino 1.0+ Only
//Arduino 1.0+ Only
/*Based largely on code by Jim Lindblom
Get pressure, altitude, and temperature from the BMP085.
Serial.print it out at 9600 baud to serial monitor.
*/
#include <Wire.h>
#define BMP085_ADDRESS 0x77 // I2C address of BMP085
const unsigned char OSS = 0; // Oversampling Setting
// Calibration values
int ac1;
int ac2;
int ac3;
unsigned int ac4;
unsigned int ac5;
unsigned int ac6;
int b1;
int b2;
int mb;
int mc;
int md;
// b5 is calculated in bmp085GetTemperature(...), this variable is also used in bmp085GetPressure(...)
// so ...Temperature(...) must be called before ...Pressure(...).
long b5;
void setup(){
Serial.begin(9600);
Wire.begin();
bmp085Calibration();
}
void loop()
{
float temperature = bmp085GetTemperature(bmp085ReadUT()); //MUST be called first
float pressure = bmp085GetPressure(bmp085ReadUP());
float atm = pressure / 101325; // "standard atmosphere"
float altitude = calcAltitude(pressure); //Uncompensated caculation - in Meters
Serial.print("Temperature: ");
Serial.print(temperature, 2); //display 2 decimal places
Serial.println("deg C");
Serial.print("Pressure: ");
Serial.print(pressure, 0); //whole number only.
Serial.println(" Pa");
Serial.print("Standard Atmosphere: ");
Serial.println(atm, 4); //display 4 decimal places
Serial.print("Altitude: ");
Serial.print(altitude, 2); //display 2 decimal places
Serial.println(" M");
Serial.println();//line break
delay(1000); //wait a second and get values again.
}
// Stores all of the bmp085's calibration values into global variables
// Calibration values are required to calculate temp and pressure
// This function should be called at the beginning of the program
void bmp085Calibration()
{
ac1 = bmp085ReadInt(0xAA);
ac2 = bmp085ReadInt(0xAC);
ac3 = bmp085ReadInt(0xAE);
ac4 = bmp085ReadInt(0xB0);
ac5 = bmp085ReadInt(0xB2);
ac6 = bmp085ReadInt(0xB4);
b1 = bmp085ReadInt(0xB6);
b2 = bmp085ReadInt(0xB8);
mb = bmp085ReadInt(0xBA);
mc = bmp085ReadInt(0xBC);
md = bmp085ReadInt(0xBE);
}
// Calculate temperature in deg C
float bmp085GetTemperature(unsigned int ut){
long x1, x2;
x1 = (((long)ut - (long)ac6)*(long)ac5) >> 15;
x2 = ((long)mc << 11)/(x1 + md);
b5 = x1 + x2;
float temp = ((b5 + 8)>>4);
temp = temp /10;
return temp;
}
// Calculate pressure given up
// calibration values must be known
// b5 is also required so bmp085GetTemperature(...) must be called first.
// Value returned will be pressure in units of Pa.
long bmp085GetPressure(unsigned long up){
long x1, x2, x3, b3, b6, p;
unsigned long b4, b7;
b6 = b5 - 4000;
// Calculate B3
x1 = (b2 * (b6 * b6)>>12)>>11;
x2 = (ac2 * b6)>>11;
x3 = x1 + x2;
b3 = (((((long)ac1)*4 + x3)<<OSS) + 2)>>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;
p += (x1 + x2 + 3791)>>4;
long temp = p;
return temp;
}
// Read 1 byte from the BMP085 at 'address'
char bmp085Read(unsigned char address)
{
unsigned char data;
Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(address);
Wire.endTransmission();
Wire.requestFrom(BMP085_ADDRESS, 1);
while(!Wire.available())
;
return Wire.read();
}
// Read 2 bytes from the BMP085
// First byte will be from 'address'
// Second byte will be from 'address'+1
int bmp085ReadInt(unsigned char address)
{
unsigned char msb, lsb;
Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(address);
Wire.endTransmission();
Wire.requestFrom(BMP085_ADDRESS, 2);
while(Wire.available()<2)
;
msb = Wire.read();
lsb = Wire.read();
return (int) msb<<8 | lsb;
}
// Read the uncompensated temperature value
unsigned int bmp085ReadUT(){
unsigned int ut;
// Write 0x2E into Register 0xF4
// This requests a temperature reading
Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(0xF4);
Wire.write(0x2E);
Wire.endTransmission();
// Wait at least 4.5ms
delay(5);
// Read two bytes from registers 0xF6 and 0xF7
ut = bmp085ReadInt(0xF6);
return ut;
}
// Read the uncompensated pressure value
unsigned long bmp085ReadUP(){
unsigned char msb, lsb, xlsb;
unsigned long up = 0;
// Write 0x34+(OSS<<6) into register 0xF4
// Request a pressure reading w/ oversampling setting
Wire.beginTransmission(BMP085_ADDRESS);
Wire.write(0xF4);
Wire.write(0x34 + (OSS<<6));
Wire.endTransmission();
// Wait for conversion, delay time dependent on OSS
delay(2 + (3<<OSS));
// Read register 0xF6 (MSB), 0xF7 (LSB), and 0xF8 (XLSB)
msb = bmp085Read(0xF6);
lsb = bmp085Read(0xF7);
xlsb = bmp085Read(0xF8);
up = (((unsigned long) msb << 16) | ((unsigned long) lsb << 8) | (unsigned long) xlsb) >> (8-OSS);
return up;
}
void writeRegister(int deviceAddress, byte address, byte val) {
Wire.beginTransmission(deviceAddress); // start transmission to device
Wire.write(address); // send register address
Wire.write(val); // send value to write
Wire.endTransmission(); // end transmission
}
int readRegister(int deviceAddress, byte address){
int v;
Wire.beginTransmission(deviceAddress);
Wire.write(address); // register to read
Wire.endTransmission();
Wire.requestFrom(deviceAddress, 1); // read a byte
while(!Wire.available()) {
// waiting
}
v = Wire.read();
return v;
}
float calcAltitude(float pressure){
float A = pressure/101325;
float B = 1/5.25588;
float C = pow(A,B);
C = 1 - C;
C = C /0.0000225577;
return C;
}
復制代碼
51單片機源碼
//***************************************
// BMP085 IIC測試程序
// 使用單片機STC89C51
// 晶振:11.0592M
// 顯示:LCD1602
// 編譯環境 Keil uVision2
// 參考宏晶網站24c04通信程序
//****************************************
#include <REG51.H>
#include <math.h> //Keil library
#include <stdlib.h> //Keil library
#include <stdio.h> //Keil library
#include <INTRINS.H> //Keil library
#define uchar unsigned char
#define uint unsigned int
#define DataPort P0 //LCD1602數據端口
sbit SCL=P1^0; //IIC時鐘引腳定義
sbit SDA=P1^1; //IIC數據引腳定義
sbit LCM_RS=P2^0; //LCD1602命令端口
sbit LCM_RW=P2^1; //LCD1602命令端口
sbit LCM_EN=P2^2; //LCD1602命令端口
#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;
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 delay(unsigned int k);
void InitLcd(); //初始化lcd1602
void WriteDataLCM(uchar dataW);
void WriteCommandLCM(uchar CMD,uchar Attribc);
void DisplayOneChar(uchar X,uchar Y,uchar DData);
void conversion(long temp_data);
void Single_Write(uchar SlaveAddress,uchar REG_Address,uchar REG_data); //單個寫入數據
uchar Single_Read(uchar REG_Address); //單個讀取內部寄存器數據
void Multiple_Read(uchar,uchar); //連續的讀取內部寄存器數據
//------------------------------------
void Delay5us();
void Delay5ms();
void BMP085_Start();
void BMP085_Stop();
void BMP085_SendACK(bit ack);
bit BMP085_RecvACK();
void BMP085_SendByte(BYTE dat);
BYTE BMP085_RecvByte();
void BMP085_ReadPage();
void BMP085_WritePage();
//-----------------------------------
//*********************************************************
void conversion(long temp_data)
{
shiwan=temp_data/100000+0x30 ;
temp_data=temp_data%100000; //取余運算
wan=temp_data/10000+0x30 ;
temp_data=temp_data%10000; //取余運算
qian=temp_data/1000+0x30 ;
temp_data=temp_data%1000; //取余運算
bai=temp_data/100+0x30 ;
temp_data=temp_data%100; //取余運算
shi=temp_data/10+0x30 ;
temp_data=temp_data%10; //取余運算
ge=temp_data+0x30;
}
/*******************************/
void delay(unsigned int k)
{
unsigned int i,j;
for(i=0;i<k;i++)
{
for(j=0;j<121;j++)
{;}}
}
/*******************************/
void WaitForEnable(void)
{
DataPort=0xff;
LCM_RS=0;LCM_RW=1;_nop_();
LCM_EN=1;_nop_();_nop_();
while(DataPort&0x80);
LCM_EN=0;
}
/*******************************/
void WriteCommandLCM(uchar CMD,uchar Attribc)
{
if(Attribc)WaitForEnable();
LCM_RS=0;LCM_RW=0;_nop_();
DataPort=CMD;_nop_();
LCM_EN=1;_nop_();_nop_();LCM_EN=0;
}
/*******************************/
void WriteDataLCM(uchar dataW)
{
WaitForEnable();
LCM_RS=1;LCM_RW=0;_nop_();
DataPort=dataW;_nop_();
LCM_EN=1;_nop_();_nop_();LCM_EN=0;
}
/***********************************/
void InitLcd()
{
WriteCommandLCM(0x38,1);
WriteCommandLCM(0x08,1);
WriteCommandLCM(0x01,1);
WriteCommandLCM(0x06,1);
WriteCommandLCM(0x0c,1);
}
/***********************************/
void DisplayOneChar(uchar X,uchar Y,uchar DData)
{
Y&=1;
X&=15;
if(Y)X|=0x40;
X|=0x80;
WriteCommandLCM(X,0);
WriteDataLCM(DData);
}
/**************************************
延時5微秒(STC90C52RC@12M)
不同的工作環境,需要調整此函數,注意時鐘過快時需要修改
當改用1T的MCU時,請調整此延時函數
**************************************/
void Delay5us()
{
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
_nop_();_nop_();_nop_();_nop_();
}
/**************************************
延時5毫秒(STC90C52RC@12M)
不同的工作環境,需要調整此函數
當改用1T的MCU時,請調整此延時函數
**************************************/
void Delay5ms()
{
WORD n = 560;
while (n--);
}
/**************************************
起始信號
**************************************/
void BMP085_Start()
{
SDA = 1; //拉高數據線
SCL = 1; //拉高時鐘線
Delay5us(); //延時
SDA = 0; //產生下降沿
Delay5us(); //延時
SCL = 0; //拉低時鐘線
}
/**************************************
停止信號
**************************************/
void BMP085_Stop()
{
SDA = 0; //拉低數據線
SCL = 1; //拉高時鐘線
Delay5us(); //延時
SDA = 1; //產生上升沿
Delay5us(); //延時
}
/**************************************
發送應答信號
入口參數:ack (0:ACK 1:NAK)
**************************************/
void BMP085_SendACK(bit ack)
{
SDA = ack; //寫應答信號
SCL = 1; //拉高時鐘線
Delay5us(); //延時
SCL = 0; //拉低時鐘線
Delay5us(); //延時
}
/**************************************
接收應答信號
**************************************/
bit BMP085_RecvACK()
{
SCL = 1; //拉高時鐘線
Delay5us(); //延時
CY = SDA; //讀應答信號
SCL = 0; //拉低時鐘線
Delay5us(); //延時
return CY;
}
/**************************************
向IIC總線發送一個字節數據
**************************************/
void BMP085_SendByte(BYTE dat)
{
BYTE i;
for (i=0; i<8; i++) //8位計數器
{
dat <<= 1; //移出數據的最高位
SDA = CY; //送數據口
SCL = 1; //拉高時鐘線
Delay5us(); //延時
SCL = 0; //拉低時鐘線
Delay5us(); //延時
}
BMP085_RecvACK();
}
/**************************************
從IIC總線接收一個字節數據
**************************************/
BYTE BMP085_RecvByte()
{
BYTE i;
BYTE dat = 0;
SDA = 1; //使能內部上拉,準備讀取數據,
for (i=0; i<8; i++) //8位計數器
{
dat <<= 1;
SCL = 1; //拉高時鐘線
Delay5us(); //延時
dat |= SDA; //讀數據
SCL = 0; //拉低時鐘線
Delay5us(); //延時
}
return dat;
}
/*
//單字節寫入BMP085內部數據*******************************
void Single_Write(uchar SlaveAddress,uchar REG_Address,uchar REG_data)
{
BMP085_Start(); //起始信號
BMP085_SendByte(SlaveAddress); //發送設備地址+寫信號
BMP085_SendByte(REG_Address); //內部寄存器地址
BMP085_SendByte(REG_data); //內部寄存器數據
BMP085_Stop(); //發送停止信號
}
*/
/*
//單字節讀取BMP085內部數據********************************
uchar Single_Read(uchar REG_Address)
{ uchar REG_data;
BMP085_Start(); //起始信號
BMP085_SendByte(BMP085_SlaveAddress); //發送設備地址+寫信號
BMP085_SendByte(REG_Address); //發送存儲單元地址
BMP085_Start(); //起始信號
BMP085_SendByte(BMP085_SlaveAddress+1); //發送設備地址+讀信號
REG_data=BMP085_RecvByte(); //讀出寄存器數據
BMP085_SendACK(1);
BMP085_Stop(); //停止信號
return REG_data;
}
*/
//*********************************************************
//讀出BMP085內部數據,連續兩個
//*********************************************************
short Multiple_read(uchar ST_Address)
{
uchar msb, lsb;
short _data;
BMP085_Start(); //起始信號
BMP085_SendByte(BMP085_SlaveAddress); //發送設備地址+寫信號
BMP085_SendByte(ST_Address); //發送存儲單元地址
BMP085_Start(); //起始信號
BMP085_SendByte(BMP085_SlaveAddress+1); //發送設備地址+讀信號
msb = BMP085_RecvByte(); //BUF[0]存儲
BMP085_SendACK(0); //回應ACK
lsb = BMP085_RecvByte();
BMP085_SendACK(1); //最后一個數據需要回NOACK
BMP085_Stop(); //停止信號
Delay5ms();
_data = msb << 8;
_data |= lsb;
return _data;
}
//********************************************************************
long bmp085ReadTemp(void)
{
BMP085_Start(); //起始信號
BMP085_SendByte(BMP085_SlaveAddress); //發送設備地址+寫信號
BMP085_SendByte(0xF4); // write register address
BMP085_SendByte(0x2E); // write register data for temp
BMP085_Stop(); //發送停止信號
delay(10); // max time is 4.5ms
return (long) Multiple_read(0xF6);
}
//*************************************************************
long bmp085ReadPressure(void)
{
long pressure = 0;
BMP085_Start(); //起始信號
BMP085_SendByte(BMP085_SlaveAddress); //發送設備地址+寫信號
BMP085_SendByte(0xF4); // write register address
BMP085_SendByte(0x34); // write register data for pressure
BMP085_Stop(); //發送停止信號
delay(10); // max time is 4.5ms
pressure = Multiple_read(0xF6);
pressure &= 0x0000FFFF;
return pressure;
//return (long) bmp085ReadShort(0xF6);
}
//**************************************************************
//初始化BMP085,根據需要請參考pdf進行修改**************
void Init_BMP085()
{
ac1 = Multiple_read(0xAA);
ac2 = Multiple_read(0xAC);
ac3 = Multiple_read(0xAE);
ac4 = Multiple_read(0xB0);
ac5 = Multiple_read(0xB2);
ac6 = Multiple_read(0xB4);
b1 = Multiple_read(0xB6);
b2 = Multiple_read(0xB8);
mb = Multiple_read(0xBA);
mc = Multiple_read(0xBC);
md = Multiple_read(0xBE);
}
//***********************************************************************
void bmp085Convert()
{
long ut;
long up;
long x1, x2, b5, b6, x3, b3, p;
unsigned long b4, b7;
long temperature;
long pressure;
ut = bmp085ReadTemp();
ut = bmp085ReadTemp(); // 讀取溫度
up = bmp085ReadPressure();
up = bmp085ReadPressure(); // 讀取壓強
x1 = ((long)ut - ac6) * ac5 >> 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;
……………………
…………限于本文篇幅 余下代碼請從51黑下載附件…………
復制代碼
所有資料51hei提供下載:
【批量下載】GY-68 BMP180 新款 BOSCH溫度 代替BMP085 氣壓傳感器模塊1等.zip
(2.21 MB, 下載次數: 58)
2018-5-21 17:55 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
作者:
avpexe
時間:
2018-7-31 09:56
牛批啊大兄弟
作者:
omer
時間:
2019-5-12 08:38
感謝分享。
歡迎光臨 (http://www.zg4o1577.cn/bbs/)
Powered by Discuz! X3.1
主站蜘蛛池模板:
国产精品一区二区三区四区
|
日韩免费一区二区
|
羞羞免费网站
|
狠狠色综合网站久久久久久久
|
三区在线观看
|
精品国产一区二区国模嫣然
|
女朋友的闺蜜3韩国三级
|
国产精品99久久久精品免费观看
|
日本a网站
|
爱爱爱av
|
婷婷综合
|
大陆一级毛片免费视频观看
|
亚洲国产精品一区二区第一页
|
在线精品一区二区三区
|
盗摄精品av一区二区三区
|
亚洲欧美日韩中文字幕一区二区三区
|
亚洲精品久久久久久一区二区
|
夜夜夜操
|
亚洲精品中文字幕中文字幕
|
亚洲久视频
|
九九热精品视频
|
欧美激情一区二区三区
|
国产福利在线
|
欧美久久一区二区三区
|
成人美女免费网站视频
|
青青草国产在线观看
|
亚洲视频在线看
|
国产黄色在线观看
|
亚洲日韩中文字幕一区
|
久久久久国产
|
男女污污动态图
|
日韩二区三区
|
久久成人18免费网站
|
99久久影院
|
在线看片国产
|
亚洲欧美日韩在线
|
免费观看成人性生生活片
|
91精品久久久久久久久久入口
|
日韩一区在线播放
|
国产欧美日韩在线观看
|
国产一区二区三区免费观看视频
|