复制代码
IIC时序模拟参考了原子的例程,仅作修改引脚,这方面应该没多大问题,就不贴代码了
- void ShortToChar(short sData,unsigned char cData[])
- {
- cData[0]=sData&0xff;
- cData[1]=sData>>8;
- }
- short CharToShort(unsigned char cData[])
- {
- return ((short)cData[1]<<8)|cData[0];
- }
-
- int main(void)
- {
- unsigned char chrTemp[30];
- unsigned char str[100];
- float a[3],w[3],h[3],Angle[3];
-
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//设置系统中断优先级分组2
- delay_init(168); //初始化延时函数
- uart_init(115200); //初始化串口波特率为500000
-
- LCD_Init(); //LCD初始化
- JY901b_Init();
-
- POINT_COLOR=RED;//设置字体为红 {MOD}
-
- while(1)
- {
- delay_ms(100);
-
- IICreadBytes(0x50, AX, 24,&chrTemp[0]);
-
- a[0] = (float)CharToShort(&chrTemp[0])/32768*16;
- a[1] = (float)CharToShort(&chrTemp[2])/32768*16;
- a[2] = (float)CharToShort(&chrTemp[4])/32768*16;
-
- w[0] = (float)CharToShort(&chrTemp[6])/32768*2000;
- w[1] = (float)CharToShort(&chrTemp[8])/32768*2000;
- w[2] = (float)CharToShort(&chrTemp[10])/32768*2000;
-
- h[0] = CharToShort(&chrTemp[12]);
- h[1] = CharToShort(&chrTemp[14]);
- h[2] = CharToShort(&chrTemp[16]);
-
- Angle[0] = (float)CharToShort(&chrTemp[18])/32768*180;
- Angle[1] = (float)CharToShort(&chrTemp[20])/32768*180;
- Angle[2] = (float)CharToShort(&chrTemp[22])/32768*180;
-
- sprintf((char *)str,"0X50:a:%.3f %.3f %.3f
",a[0],a[1],a[2]);
- LCD_ShowString(30,200,200,16,16,str);
-
- sprintf((char *)str,"0X50:w:%.3f %.3f %.3f
",w[0],w[1],w[2]);
- LCD_ShowString(30,220,200,16,16,str);
-
- sprintf((char *)str,"0X50:h:%.0f %.0f %.0f
",h[0],h[1],h[2]);
- LCD_ShowString(30,240,200,16,16,str);
-
- sprintf((char *)str,"0X50:Angle:%.3f %.3f %.3f
",Angle[0],Angle[1],Angle[2]);
- LCD_ShowString(30,260,200,16,16,str);
-
-
-
- }
-
- }
复制代码主函数参考了厂家例程,我在此基础上添加了LCD显示
0X50是模块地址,AX指向X轴加速度寄存器地址
最后在探索者开发板上显示的数据全部是000000000
我觉得思路应该是对的,请大神帮忙看看是哪里出了差错,谢谢
那个售后客服像机器人一样,只会让我参考例程
一周热门 更多>