#include "REG52.h"
#include "INTRINS.H" //Keil library
#include "UART.h"
unsigned int xx, yy;
//typedef unsigned char u8;
//typedef unsigned int uint16;
u8 num =0;
sbit SCL=P1^1; //IIC时钟引脚定义
sbit SDA=P1^0; //IIC数据引脚定义
bit zdxh=0;
#define OSS 0 // Oversampling Setting (note: code is not set up to use other OSS values)
#define BMP085_SlaveAddress 0xee //定义器件在IIC总线中的从地址
u8 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();
void Delay5ms();
void BMP085_Start();
void BMP085_Stop();
void BMP085_SendACK(bit ack);
bit BMP085_RecvACK();
void BMP085_SendByte(u8 dat);
u8 BMP085_RecvByte();
void BMP085_ReadPage();
void BMP085_WritePage();
//*********************************************************
void conversion(long temp_data)
{
shiwan=temp_data/100000 ;
temp_data=temp_data%100000; //取余运算
wan=temp_data/10000 ;
temp_data=temp_data%10000; //取余运算
qian=temp_data/1000 ;
temp_data=temp_data%1000; //取余运算
bai=temp_data/100 ;
temp_data=temp_data%100; //取余运算
shi=temp_data/10 ;
temp_data=temp_data%10; //取余运算
ge=temp_data;
}
/************************延时程序************************************/
void delay(unsigned int z)
{
unsigned int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
//void delay1(u16 aa)
//{
// u8 bb;
// while(aa--)
// {
// for(bb=0;bb<115;bb++) //1ms基准延时程序
// {
// ;
// }
// }
//}
/**************************************
延时5微秒(STC90C52RC@12M)
不同的工作环境,需要调整此函数,注意时钟过快时需要修改
当改用1T的MCU时,请调整此延时函数
**************************************/
void Delay5us()
{
unsigned char i;
_nop_();
i = 11;
while (--i);
}
/**************************************
延时5毫秒(STC90C52RC@12M)
不同的工作环境,需要调整此函数
当改用1T的MCU时,请调整此延时函数
**************************************/
void Delay5ms()
{
unsigned char i, j;
i = 54;
j = 199;
do
{
while (--j);
} while (--i);
}
/**************************************
起始信号
**************************************/
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(u8 dat)
{
u8 i;
for (i=0; i<8; i++) //8位计数器
{
dat <<= 1; //移出数据的最高位
SDA = CY; //送数据口
SCL = 1; //拉高时钟线
Delay5us(); //延时
SCL = 0; //拉低时钟线
Delay5us(); //延时
}
BMP085_RecvACK();
}
/**************************************
从IIC总线接收一个字节数据
**************************************/
u8 BMP085_RecvByte()
{
u8 i;
u8 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(u8 ST_Address)
{
u8 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(2); // 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(2); // max time is 4.5ms
pressure = Multiple_read(0xF6);
pressure &= 0x0000FFFF;
return pressure;
//return (long) bmp085ReadShort(0xF6);
}
//初始化BMP085,根据需要请参考pdf进行修改**************
void Init_BMP085()
{
ac1
没有合适的资源?快使用搜索试试~ 我知道了~
stc单片机0.96OLED+气压模块程序
共31个文件
bak:9个
lst:3个
h:3个
需积分: 0 1 下载量 48 浏览量
2023-07-12
15:54:17
上传
评论
收藏 127KB ZIP 举报
温馨提示
stc单片机0.96OLED+气压模块程序
资源推荐
资源详情
资源评论
收起资源包目录
stc单片机0.96OLED+气压模块程序.zip (31个子文件)
stc单片机0.96OLED+气压模块程序
OLED
OLED_uvopt.bak 57KB
OLED_uvproj.bak 13KB
OLED.uvgui.Aaron_Lee 138KB
OLED 94KB
OLED.uvgui_Administrator.bak 71KB
OLED.build_log.htm 1KB
codetab.h 13KB
OLED.uvopt 57KB
蓝牙遥控车.c 10KB
UART.LST 6KB
OLED.M51 26KB
OLED_Opt.Bak 2KB
OLED.Uv2.bak 2KB
OLED.plg 180B
UART.OBJ 42KB
蓝牙遥控车_uvopt.bak 55KB
UART.h 200B
蓝牙遥控车.uvproj 14KB
蓝牙遥控车.uvopt 5KB
蓝牙遥控车.OBJ 56KB
UART.c 3KB
蓝牙遥控车.uvgui.Administrator 90KB
蓝牙遥控车_uvproj.bak 13KB
OLED.lnp 59B
OLED.hex 8KB
OLED_Uv2.Bak 2KB
OLED12864.LST 446B
OLED.uvgui.Administrator 71KB
OLED.opt.bak 2KB
LQ12864.h 6KB
蓝牙遥控车.LST 17KB
共 31 条
- 1
资源评论
qq_30851873
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功