#include "D:\1\main.h"
#include <lcd.c>
unsigned int x,who;
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3)
///////////////////////////////DEVICE ADDRESS/////////////////////////////////
#define I2C_Gyro 0xD0
///////////////////////////////REGISTER ADDRESS/////////////////////////////////
#define GYRO_outX 0x29
#define GYRO_outY 0x2B
#define GYRO_outZ 0x2D
/////////////////////////////////// FUNCTIONS ////////////////////////////////
BYTE read_sensor(BYTE device, BYTE reg)
{
BYTE data;
i2c_start();
i2c_write(device);
i2c_write(reg);
i2c_start();
i2c_write(device+1);
data=i2c_read(0);
i2c_stop();
return(data);
}
////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////// MAIN ///////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
void main()
{
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!!
trisc3=0;
trisc4=1;
trisc5=0;
while(1)
{
x=102;
who=read_sensor(I2C_Gyro,0x26);
x=read_sensor(I2C_Gyro,0x28);
lcd_init();
lcd_putc("\f"); // Clear display
lcd_gotoxy(1,1);
printf(lcd_putc,"X: %d %d",x,who);
printf("\n\r %d",x);
delay_ms(200);
}
}