找回密码
 马上注册

QQ登录

只需一步,快速开始

查看: 5307|回复: 1

请教bma180加速度传感器如何编程?

[复制链接]
发表于 2011-12-22 22:06:07 | 显示全部楼层 |阅读模式
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);
  }
}

请帮助指点,谢谢!

如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
发表于 2011-12-22 23:06:23 | 显示全部楼层
提倡自己动手,丰衣足食
如果您觉得我的帖子对您有用,请不吝给我一个“赞”!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|中文乐高 ( 桂ICP备13001575号-7 )

GMT+8, 2024-5-7 04:40 , Processed in 0.084671 second(s), 25 queries .

Powered by Discuz! X3.5

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表