这里的代码:
int main(){
uint64_t i = 0;
int16_t dx = 0,dy = 0,dz = 0;
字节数据= 0x00,b = 0x00,hx = 0x00,lx = 0x00,hy = 0x00,ly = 0x00,hz = 0x00,lz = 0x00;
double fx = 0.,fy = 0.,fz = 0。 single_write(LSM303AGR_ACC_CTRL_REG1,0x27); //在寄存器上写单个字节
single_write(LSM303AGR_ACC_CTRL_REG2,0x00);
single_write(LSM303AGR_ACC_CTRL_REG3,0x00);
single_write(LSM303AGR_ACC_CTRL_REG4,0x80);
等待(1);
而(1){
b = single_read(LSM303AGR_ACC_STATUS_REG2);
if(b& 0x01){
lx = single_read(LSM303AGR_ACC_OUT_X_L);
hx = single_read(LSM303AGR_ACC_OUT_X_H);
dx =(int16_t)((uint16_t)(((uint16_t)hx)<<< 8 +((uint16_t)lx)));
fx =(double)(2。/ 32768.)*(double)dx;
pc.printf(' tX READY:x =%d t t t tfx =%lf r n',dx,fx);
}
if(b& 0x02){
ly = single_read(LSM303AGR_ACC_OUT_Y_L);
hy = single_read(LSM303AGR_ACC_OUT_Y_H);
dy =(int16_t)((uint16_t)(((uint16_t)hy)<< 8 +((uint16_t)ly)));
fy =(double)(2。/ 32768.)*(double)dy;
pc.printf(' tY READY:y =%d t t tfy =%lf r n',dy,fy);
}
if(b& 0x04){
lz = single_read(LSM303AGR_ACC_OUT_Z_L);
hz = single_read(LSM303AGR_ACC_OUT_Z_H);
dz =(int16_t)((uint16_t)(((uint16_t)hz)<<< 8 +((uint16_t)lz)));
fz =(double)(2。/ 32768.)*(double)dz;
pc.printf(' tZ READY:z =%d t t tfz =%lf r n',dz,fz);
}
等待(0.01);
我++;
}
}
以上来自于谷歌翻译
以下为原文
Here the code:
int main() {
uint64_t i = 0;
int16_t dx = 0, dy = 0, dz = 0;
byte data = 0x00, b = 0x00, hx = 0x00, lx = 0x00, hy = 0x00, ly = 0x00, hz = 0x00, lz = 0x00;
double fx = 0., fy = 0., fz = 0.; single_write(LSM303AGR_ACC_CTRL_REG1, 0x27); //write single byte on register
single_write(LSM303AGR_ACC_CTRL_REG2, 0x00);
single_write(LSM303AGR_ACC_CTRL_REG3, 0x00);
single_write(LSM303AGR_ACC_CTRL_REG4, 0x80);
wait(1);
while(1){
b = single_read(LSM303AGR_ACC_STATUS_REG2);
if(b&0x01) {
lx = single_read(LSM303AGR_ACC_OUT_X_L);
hx = single_read(LSM303AGR_ACC_OUT_X_H);
dx = (int16_t)((uint16_t)(((uint16_t)hx)<<8+((uint16_t)lx)));
fx = (double)(2. / 32768.) * (double)dx;
pc.printf('tX READY: x=%dtttfx=%lfrn', dx, fx);
}
if(b&0x02) {
ly = single_read(LSM303AGR_ACC_OUT_Y_L);
hy = single_read(LSM303AGR_ACC_OUT_Y_H);
dy = (int16_t)((uint16_t)(((uint16_t)hy)<<8+((uint16_t)ly)));
fy = (double)(2. / 32768.) * (double)dy;
pc.printf('tY READY: y=%dtttfy=%lfrn', dy, fy);
}
if(b&0x04) {
lz = single_read(LSM303AGR_ACC_OUT_Z_L);
hz = single_read(LSM303AGR_ACC_OUT_Z_H);
dz = (int16_t)((uint16_t)(((uint16_t)hz)<<8+((uint16_t)lz)));
fz = (double)(2. / 32768.) * (double)dz;
pc.printf('tZ READY: z=%dtttfz=%lfrn', dz, fz);
}
wait(0.01);
i++;
}
}
这里的代码:
int main(){
uint64_t i = 0;
int16_t dx = 0,dy = 0,dz = 0;
字节数据= 0x00,b = 0x00,hx = 0x00,lx = 0x00,hy = 0x00,ly = 0x00,hz = 0x00,lz = 0x00;
double fx = 0.,fy = 0.,fz = 0。 single_write(LSM303AGR_ACC_CTRL_REG1,0x27); //在寄存器上写单个字节
single_write(LSM303AGR_ACC_CTRL_REG2,0x00);
single_write(LSM303AGR_ACC_CTRL_REG3,0x00);
single_write(LSM303AGR_ACC_CTRL_REG4,0x80);
等待(1);
而(1){
b = single_read(LSM303AGR_ACC_STATUS_REG2);
if(b&amp; 0x01){
lx = single_read(LSM303AGR_ACC_OUT_X_L);
hx = single_read(LSM303AGR_ACC_OUT_X_H);
dx =(int16_t)((uint16_t)(((uint16_t)hx)&lt;&lt;&lt; 8 +((uint16_t)lx)));
fx =(double)(2。/ 32768.)*(double)dx;
pc.printf(' tX READY:x =%d t t t tfx =%lf r n',dx,fx);
}
if(b&amp; 0x02){
ly = single_read(LSM303AGR_ACC_OUT_Y_L);
hy = single_read(LSM303AGR_ACC_OUT_Y_H);
dy =(int16_t)((uint16_t)(((uint16_t)hy)&lt;&lt; 8 +((uint16_t)ly)));
fy =(double)(2。/ 32768.)*(double)dy;
pc.printf(' tY READY:y =%d t t tfy =%lf r n',dy,fy);
}
if(b&amp; 0x04){
lz = single_read(LSM303AGR_ACC_OUT_Z_L);
hz = single_read(LSM303AGR_ACC_OUT_Z_H);
dz =(int16_t)((uint16_t)(((uint16_t)hz)&lt;&lt;&lt; 8 +((uint16_t)lz)));
fz =(double)(2。/ 32768.)*(double)dz;
pc.printf(' tZ READY:z =%d t t tfz =%lf r n',dz,fz);
}
等待(0.01);
我++;
}
}
以上来自于谷歌翻译
以下为原文
Here the code:
int main() {
uint64_t i = 0;
int16_t dx = 0, dy = 0, dz = 0;
byte data = 0x00, b = 0x00, hx = 0x00, lx = 0x00, hy = 0x00, ly = 0x00, hz = 0x00, lz = 0x00;
double fx = 0., fy = 0., fz = 0.; single_write(LSM303AGR_ACC_CTRL_REG1, 0x27); //write single byte on register
single_write(LSM303AGR_ACC_CTRL_REG2, 0x00);
single_write(LSM303AGR_ACC_CTRL_REG3, 0x00);
single_write(LSM303AGR_ACC_CTRL_REG4, 0x80);
wait(1);
while(1){
b = single_read(LSM303AGR_ACC_STATUS_REG2);
if(b&0x01) {
lx = single_read(LSM303AGR_ACC_OUT_X_L);
hx = single_read(LSM303AGR_ACC_OUT_X_H);
dx = (int16_t)((uint16_t)(((uint16_t)hx)<<8+((uint16_t)lx)));
fx = (double)(2. / 32768.) * (double)dx;
pc.printf('tX READY: x=%dtttfx=%lfrn', dx, fx);
}
if(b&0x02) {
ly = single_read(LSM303AGR_ACC_OUT_Y_L);
hy = single_read(LSM303AGR_ACC_OUT_Y_H);
dy = (int16_t)((uint16_t)(((uint16_t)hy)<<8+((uint16_t)ly)));
fy = (double)(2. / 32768.) * (double)dy;
pc.printf('tY READY: y=%dtttfy=%lfrn', dy, fy);
}
if(b&0x04) {
lz = single_read(LSM303AGR_ACC_OUT_Z_L);
hz = single_read(LSM303AGR_ACC_OUT_Z_H);
dz = (int16_t)((uint16_t)(((uint16_t)hz)<<8+((uint16_t)lz)));
fz = (double)(2. / 32768.) * (double)dz;
pc.printf('tZ READY: z=%dtttfz=%lfrn', dz, fz);
}
wait(0.01);
i++;
}
}
举报