Merge pull request #3 from armku/master
增加NPA数字压力传感器驱动,IIC 型号:NPA_700B_015A
This commit is contained in:
commit
8cc592e542
|
@ -0,0 +1,42 @@
|
|||
#include "NPA_700B_015A.h"
|
||||
|
||||
NPA_700B_015A::NPA_700B_015A()
|
||||
{
|
||||
this->IIC = nullptr;
|
||||
this->Address = 0X51;
|
||||
}
|
||||
|
||||
void NPA_700B_015A::Init()
|
||||
{
|
||||
debug_printf("\r\nAT24CXX::Init Address=0x%02X \r\n", Address);
|
||||
|
||||
this->IIC->SubWidth = 1;
|
||||
this->IIC->Address = this->Address;
|
||||
this->IIC->Open();
|
||||
}
|
||||
|
||||
int NPA_700B_015A::Read()
|
||||
{
|
||||
byte buf1, buf2;
|
||||
int buf;
|
||||
buf1 = 0;
|
||||
buf2 = 0;
|
||||
this->IIC->Start();
|
||||
this->IIC->WriteByte(Address);
|
||||
if (!this->IIC->WaitAck(true))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
buf1 = this->IIC->ReadByte();
|
||||
this->IIC->Ack(true);
|
||||
buf2 = this->IIC->ReadByte();
|
||||
this->IIC->Ack(false);
|
||||
this->IIC->Stop();
|
||||
buf = (buf1 << 8) | buf2;
|
||||
return buf;
|
||||
}
|
||||
//¶ÁÈ¡´óÆøÑ¹Öµ
|
||||
float NPA_700B_015A::ReadP()
|
||||
{
|
||||
return this->Read() * 0.007278646;
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef _NPA_H
|
||||
#define _NPA_H
|
||||
|
||||
#include "I2C.h"
|
||||
//压力传感器 NPA-700B-015A
|
||||
class NPA_700B_015A
|
||||
{
|
||||
public:
|
||||
SoftI2C* IIC;
|
||||
|
||||
NPA_700B_015A();
|
||||
int Read();
|
||||
float ReadP();//读取大气压值
|
||||
void Init();
|
||||
private:
|
||||
byte Address; //设备地址
|
||||
};
|
||||
#endif
|
Loading…
Reference in New Issue