智能车制作

 找回密码
 注册

扫一扫,访问微社区

查看: 14521|回复: 13
打印 上一主题 下一主题

悬赏!!!!谁有K60的MPU6050加速度计的例程?

[复制链接]

8

主题

111

帖子

0

精华

金牌会员

Rank: 6Rank: 6

积分
1153
威望
579
贡献
358
兑换币
381
注册时间
2014-11-22
在线时间
108 小时
毕业学校
河南理工大学万方科技学院
1#
发表于 2015-8-9 06:46:50 | 显示全部楼层
void mpu6050_init()
{
  i2c_init(I2C0,200000);
  lptmr_delay_ms(10);
  i2c_write_reg(I2C0,0x68,0x6b,0x00);
  i2c_write_reg(I2C0,0x68,0x19,0x00);
  i2c_write_reg(I2C0,0x68,0x1a,0x00);
  i2c_write_reg(I2C0,0x68,0x1b,0x08);
  i2c_write_reg(I2C0,0x68,0x1c,0x00);
}
/************************************
读取mpu6050的值
*************************************/
void mpu6050_read()
{
    uint16 msb,lsb;
    msb=i2c_read_reg(I2C0,0x68,0x3b);
    lsb=i2c_read_reg(I2C0,0x68,0x3c);
    accel_x=msb<<8|lsb;
/*    msb=i2c_read_reg(I2C0,0x68,0x3d);
    lsb=i2c_read_reg(I2C0,0x68,0x3e);
    accel_y=msb<<8|lsb;
    msb=i2c_read_reg(I2C0,0x68,0x3f);
    lsb=i2c_read_reg(I2C0,0x68,0x40);
    accel_z=msb<<8|lsb;
    msb=i2c_read_reg(I2C0,0x68,0x43);
    lsb=i2c_read_reg(I2C0,0x68,0x44);
    gyro_x=msb<<8|lsb;  */
    msb=i2c_read_reg(I2C0,0x68,0x45);
    lsb=i2c_read_reg(I2C0,0x68,0x46);
    gyro_y=msb<<8|lsb;
/*   msb=i2c_read_reg(I2C0,0x68,0x47);
    lsb=i2c_read_reg(I2C0,0x68,0x48);
    gyro_z=msb<<8|lsb;    */
}
I2C野火底层
回复

使用道具 举报

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

本版积分规则

关于我们|联系我们|小黑屋|亿加合和智能车制作 ( 黑ICP备2022002344号

GMT+8, 2024-5-5 03:20 , Processed in 0.052922 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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