سلام دوستان من کد i2c ماژول MPU6050 رو توی PIC Compiler نوشتم فقط ارور میکرو 16F877A.h داره، حتی همین کتابخونه رو یه بار دیگه دانلود کردم و توی Device ریختم اما بازم نشد. ممنون میشم کمک کنید :sad:
کد رو پایین گذاشتم
کد رو پایین گذاشتم
کد:
#include <16F877A.h> #fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,PUT,NOLVP #include "i2c.h" #use delay(clock=4000000) #include "Flex_LCD420.c" #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) void main() { long input; setup_adc_ports(NO_ANALOGS); setup_adc(ADC_OFF); setup_psp(PSP_DISABLED); setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); setup_timer_1(T1_DISABLED); setup_timer_2(T2_DISABLED,0,1); setup_comparator(NC_NC_NC_NC); setup_vref(FALSE); // TODO: USER CODE!! lcd_init(); i2c_start(); i2c_write(0xd0);/// sensor slave address i2c_write(0x6b);///device reset i2c_write(0x00); i2c_stop(); delay_ms(10); while(1) { lcd_gotoxy(1,1); lcd_putc("test"); i2c_start(); i2c_write(0xd0); /// sensor address i2c_write(0x3b); ///ACCEL_XOUT_H i2c_start(); i2c_write(0xd1); input=i2c_read(0); i2c_write(0xd0); /// sensor address i2c_write(0x3d); ///ACCEL_YOUT_H i2c_start(); i2c_write(0xd1); input=i2c_read(0); i2c_write(0xd0); /// sensor address i2c_write(0x3f); ///ACCEL_ZOUT_H i2c_start(); i2c_write(0xd1); input=i2c_read(0); i2c_write(0xd0)///sensor address i2c_write(0x43);///Gyro_XOUT_H i2c_start(); i2c_write(0xd1); input=i2c_read(0); i2c_write(0xd0); /// sensor address i2c_write(0x45)////Gyro_YOUT_H i2c_start(); i2c_write(0xd1); input=i2c_read(0); i2c_write(0xd0); /// sensor address i2c_write(0x47)/////Gyro_ZOUT_H i2c_start(); i2c_write(0xd1); input=i2c_read(0); //i2c_write(0x68);// device address //input=i2c_read(0x3b);// register address(X accel) i2c_stop(); lcd_gotoxy(2,2); printf(lcd_putc,"%Lu",input); delay_ms(200); lcd_gotoxy(1,1); lcd_putc("best"); delay_ms(100); } }
دیدگاه