標(biāo)題:
求助 ! ADXL345顯示在串口助手上
[打印本頁(yè)]
作者:
51dasttwbd
時(shí)間:
2018-7-29 10:49
標(biāo)題:
求助 ! ADXL345顯示在串口助手上
求助各位大神。!怎么讓ADXL345 加速度傳感器可以在 串口助手上顯示出來(lái) 下面是我 仿編的 程序 串口上不能顯示 加速度的變化值
# include "sys.h"
# include "delay.h"
# include "printf.h"
# include "adxl345.h"
# include "usart.h"
# include "led.h"
# include "key.h"
void Delay (u32 i)
{
while(i--);
}
int main(void)
{
u8 key;
u8 t=0;
double x,y,z;
double angx,angy,angz;
delay_init();
LED_Init();
KEY_Init();
printf_init();
I2C_INIT();
ADXL345_Init();
while(1)
{
if(t%10==0)
{
ADX_GetXYZ_Value((short*)&x, (short*)&y,(short*) &z);
printf("x:%f \n",x);
printf("y: %f \n",y);
printf("z: %f\n",z);
Delay(6000000);
angx=ADXL345_Get_Angle(x,y,z,1);
angy=ADXL345_Get_Angle(x,y,z,2);
angz=ADXL345_Get_Angle(x,y,z,0);
printf("角度x%f\r\n",angx);
printf("角度y%f\r\n",angy);
printf("角度z%f\r\n",angz);
Delay(6000000);
}
key=KEY_Scan(0);
if(key==KEY_UP)
{
LED1=0;
ADXL345_AUTO_Adjust((short*)&x, (short*)&y, (short*)&z);
LED1=1;
}
delay_ms(10);
t++;
if(t==20)
{
t=0;
LED0=!LED0;
}
}
}
復(fù)制代碼
作者:
51dasttwbd
時(shí)間:
2018-7-29 19:33
有哪位 大神 可以幫下忙嘛~~~ 小弟 非常感激
作者:
guangshi_wq
時(shí)間:
2018-7-30 01:53
主函數(shù)加上;
TMOD=0X21; /*T1 MODE 2 timer,T0 MODE 16 timer*/
PCON=0X80; /*SMOD=1 如果把這句注釋,波特率9600*/
SCON=0X50; /*MODE 1 REN=1*/
TCON=0X01; /*TR0=1,TR1=1,IT0=1,IT1=1*/
TH1=0XFd; /*11.0592M,fd,12m,f3;波特率19200*/
TL1=0XFd;
TR1=1;
調(diào)用處加上
SBUF=0x0a;// /*回車*/把0x0a換成你的變量名;
while(TI==0);
TI=0;
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1