졸작의뢰는 ▶LINK 로 와주세요
댓글 환영입니다.
http://www.sonsivri.to/forum/index.php?topic=59978.0
MPU-6050 6-Axis Accelerometer/Gyroscope with 16F877A - CCS C Code
Related to the acceleration sensors,
many questions unanswered in the forums and saw the unfinished work.
Codes associated with acceleration sensors,
I'll be posting the help of the codes used in the forums.
관련된 to the 가속도 센서들에,
많은 질문들 답변없는 in the 포럼에서 and 본 the 미환성 작업을.
코드들 관련된 with 가속도 센서들과,
이건 will be 코드팅될것이다. the help에 of the 코드들의 사용된 in the 포럼들에서.
Some mathematical formulas taken from their pdf files of the acceleration sensor.
Some numbers, because it does not allow the processor bits
I wrote using the appropriate numbers.
CCS C is very efficient in this regard.
8-bit inefficiency is able to absorb ("math.h").
Proton and Picbasic Pro may be errors.
I'm glad you publish corrections.
We may in the future use of these codes to balance the robot and share code.
Good work everyone.
몇몇 수학적 공식들 취득한 from 그것들의 pdf 파일들에서 of the 가속도 센서의.
몇몇 숫자들 because it doesn't not 허락하지않기때문에. the 프로세서 비트들을
난 썼다. 사용하며 the 적합한 숫자들을.
CCSC는 매우 효율적이다. in 이 관련에서.
8비트 비효율은 가능게한다. to 없애는게
프로톤 and 픽베이직 프로는 may be 에러가될것이다.
난 기쁘다. 올바른걸 publish하게되서
우린 may in 미래에 사용할것이다. of 이 크도들을 to 균형잡기위해 the 로봇을 and 공유하자 코드를.
모두 즐거운 작업
▼▼▼▼▼▼▼▼▼▼▼▼▼▼
#include <16f877A.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES HS //Dont change
#use delay(clock=20MHz)
#use I2C(master, sda=PIN_d0, scl=PIN_d1, slow)
//You can change, according your board ports
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7)
//You can change, according your board ports
#include "EXLCD.C" //You can change, according your board ports
//#include "EXLCD416.C" //You can change, according your board ports
#include "MPU6050.C"
#include <math.h>
signed int8 A_data[6];
signed int8 temp_data[2];
signed int8 G_data[6];
signed int16 Xa=0,Ya=0,Za=0;
signed int16 temp=0;
signed int16 Xg=0,Yg=0,Zg=0;
void main()
{
delay_ms(2);
lcd_init();
mpu6050_init();
printf(lcd_putc,"\f");
lcd_gotoxy(1,1);
printf(lcd_putc," MPU6050 Gyro ");
lcd_gotoxy(1,2);
printf(lcd_putc," Accelerometer ");
delay_ms(1000);
printf(lcd_putc,"\f");
while(TRUE)
{
A_data[0]=mpu6050_read(0x3B); //Read X axis(LSB)
A_data[1]=mpu6050_read(0x3C); //Read X axis(MSB)
A_data[2]=mpu6050_read(0x3D); //Read Y axis(LSB)
A_data[3]=mpu6050_read(0x3E); //Read Y axis(MSB)
A_data[4]=mpu6050_read(0x3F); //Read Z axis(LSB)
A_data[5]=mpu6050_read(0x40); //Read Z axis(MSB)
temp_data[0]=mpu6050_read(0x41);
temp_data[1]=mpu6050_read(0x42);
G_data[0]=mpu6050_read(0x43); //Read X axis(LSB)
G_data[1]=mpu6050_read(0x44); //Read X axis(MSB)
G_data[2]=mpu6050_read(0x45); //Read Y axis(LSB)
G_data[3]=mpu6050_read(0x46); //Read Y axis(MSB)
G_data[4]=mpu6050_read(0x47); //Read Z axis(LSB)
G_data[5]=mpu6050_read(0x48); //Read Z axis(MSB)
Xa=make16(A_data[0],A_data[1]);
Ya=make16(A_data[2],A_data[3]);
Za=make16(A_data[4],A_data[5]);
temp=make16(temp_data[0],temp_data[1]);
temp=temp/340 + 36.53;
Xg=make16(G_data[0],G_data[1]);
Yg=make16(G_data[2],G_data[3]);
Zg=make16(G_data[4],G_data[5]);
float Heading = atan2((signed int16)Ya,(signed int16)Xa)* 180 / pi + 180;
lcd_gotoxy(1,1);
printf(lcd_putc,"X:%ld ",Xa);
lcd_gotoxy(10,1);
printf(lcd_putc,"Y:%ld ",Ya);
lcd_gotoxy(1,2);
printf(lcd_putc,"Z:%ld ",Za);
lcd_gotoxy(10,2);
printf(lcd_putc,"H:%f ",heading);
/* For 4x16 LCD
lcd_gotoxy(1,3);
printf(lcd_putc,"Xg:%ld ",Xg);
lcd_gotoxy(9,3);
printf(lcd_putc,"Yg:%ld ",Yg);
lcd_gotoxy(1,4);
printf(lcd_putc,"Zg:%ld ",Zg);
lcd_gotoxy(9,4);
printf(lcd_putc,"T :%ld ",temp);
*/
printf("\n\r H: %f X: %ld Y: %ld Z: %ld T: %ld \n\r",Heading,Xg,Yg,Zg,temp);
delay_ms(100);
}
}
▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲
▼▼▼▼▼▼▼▼▼▼▼▼▼▼▼
// MPU6050 required Registers
#define W_DATA 0xD0
#define R_DATA 0xD1
#define PWR_MGMT_1 0x6B
#define PWR_MGMT_2 0x6C
#define SMPRT_DIV 0x19
#define CONFIG_R 0x1A
#define GYRO_CONFIG 0x1B
#define ACCEL_CONFIG 0x1C
#define ACCEL_XOUT_H 0x3B
#define ACCEL_XOUT_L 0x3C
#define ACCEL_YOUT_H 0x3D
#define ACCEL_YOUT_L 0x3E
#define ACCEL_ZOUT_H 0x3F
#define ACCEL_ZOUT_L 0x40
#define TEMP_OUT_H 0x41
#define TEMP_OUT_L 0x42
#define GYRO_XOUT_H 0x43
#define GYRO_XOUT_L 0x44
#define GYRO_YOUT_H 0x45
#define GYRO_YOUT_L 0x46
#define GYRO_ZOUT_H 0x47
#define GYRO_ZOUT_L 0x48
void mpu6050_write(int add, int data)
{
i2c_start();
i2c_write(W_DATA);
i2c_write(add);
i2c_write(data);
i2c_stop();
}
int16 mpu6050_read(int add)
{
int retval;
i2c_start();
i2c_write(W_DATA);
i2c_write(add);
i2c_start();
i2c_write(R_DATA);
retval=i2c_read(0);
i2c_stop();
return retval;
}
void mpu6050_init()
{
mpu6050_write(PWR_MGMT_1, 0x80);
delay_ms(100);
mpu6050_write(PWR_MGMT_1, 0x00);
delay_ms(100);
mpu6050_write(CONFIG_R, 0x01);
delay_ms(10);
mpu6050_write(GYRO_CONFIG, 0x00);
}
▲▲▲▲▲▲▲▲▲▲▲▲▲▲▲