|
bma180.pdf
(1.16 MB, 下载次数: 78)
bma180加速度传感器的参数说明书
请高手帮写一下nxc程序
参照自制数字三轴罗盘传感器(猪头猪脑)程序
发现数据不停的变化,而且幅度比较大,程序如下:
#define SensorPort IN_1
#define ADDR 0x80
struct TriAxisData
{
int gX,gY,gZ;
};
byte ACC_ReadData(byte port, byte i2cAddr,TriAxisData &triData)
{
byte message[];
byte buf[];
int count;
byte nByteReady = 0;
byte b;
SetSensorLowspeed(port);
ArrayBuild(message, i2cAddr, 0x02);
while (I2CStatus(port, nByteReady) == STAT_COMM_PENDING);
count = 6;
if(I2CBytes(port, message, count, buf)) {
triData.gX=buf[1]<<8;
triData.gX |= buf[0];
triData.gY=buf[3]<<8;
triData.gY |= buf[2];
triData.gZ=buf[5]<<8;
triData.gZ |= buf[4];
}
return b;
}
task main()
{
string msg;
TriAxisData gData;
string ax, ay, az;
while (true ) {
// read the values from the sensor.
ACC_ReadData(SensorPort, ADDR, gData);
msg = "X: ";
ax = NumToStr(gData.gX);
msg = StrReplace(msg, 2, ax);
TextOut(0, LCD_LINE2, msg, false);
msg = "Y: ";
ay = NumToStr(gData.gY);
msg = StrReplace(msg, 2, ay);
TextOut(0, LCD_LINE3, msg, false);
msg = "Z: ";
az = NumToStr(gData.gZ);
msg = StrReplace(msg, 2, az);
TextOut(0, LCD_LINE4, msg, false);
Wait(200);
}
}
请帮助指点,谢谢!
|
|