/*
* BMP085模块 *
* 用途:BMP085模块IIC测试程序 *
* 作者 日期 备注 * Huafeng Lin 2010/12/10 新增 * Huafeng Lin 2010/12/11 修改 * */
#include
#include
#define DataPort P2 //LCD1602数据端口 sbit SCL=P1^0; //IIC时钟引脚定义 sbit SDA=P1^1; //IIC数据引脚定义
sbit LCM_RS=P0^2; //LCD1602命令端口 sbit LCM_RW=P0^1; //LCD1602命令端口 sbit LCM_EN=P0^0; //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_data0000; //取余运算 wan=temp_data/10000+0x30 ;
temp_data=temp_data000; //取余运算 qian=temp_data/1000+0x30 ;
temp_data=temp_data00; //取余运算 bai=temp_data/100+0x30 ;
temp_data=temp_data0; //取余运算 shi=temp_data/10+0x30 ;
temp_data=temp_data; //取余运算
//单个写入数 //单个读 //连续的 ge=temp_data+0x30; }
/*******************************/ void delay(unsigned int k) { unsigned int i,j; for(i=0;i /*******************************/ 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;