L3GD20 problem in reading values usng PIC18f4550

hi
I have got Pololu minIMU-9V2, in which I’m trying to read gyroscope values. When i connect my sensor its always showing X=-1, and when i disconnect my sensor its showing X=10223 0r X=20877. Since it has got pull up resistor i didn’t connect external pull up resistor while connecting with PIC controller.im using CCS compiler, in my demo board it shows 4mhz crystal, for that i confused whether to use HS in fuse or any thing.
my code is

#Include <18f4550.h>
//#use delay(xtal=20Mhz)
//#fuses NOWDT,HS
#fuses HS,MCLR,NOWDT,NOPROTECT,NOLVP,USBDIV,PLL5,CPUDIV1,VREGEN
#use delay(clock=2000000)
#use i2c(Master,sda=PIN_B0,scl=PIN_B1)
#define LCD_ENABLE_PIN PIN_C2
#define LCD_RS_PIN PIN_C1
#define LCD_RW_PIN PIN_C0
#define DATA_PORT  PORTD
#include <lcd.c>

#define gyro_ADD_R 0xD3
#define gyro_ADD_W 0xD2
#define CTRL_REG1 0x20
#define CTRL_REG2 0x21
#define CTRL_REG3 0x22
#define CTRL_REG4 0x23
#define CTRL_REG5 0x24

int16 x=0;
int8 xM=0,xL=0;

void writeRegister(int8 reg,int8 value)
 {
    i2c_start();
    i2c_write(gyro_ADD_W);     
    i2c_write(reg);       
    i2c_write(value);           
    i2c_stop();             
 }

void init_gyro()
{
writeRegister(CTRL_REG1,0b00001111);
writeRegister(CTRL_REG2,0b00001000);
writeRegister(CTRL_REG3,0b00001000);
writeRegister(CTRL_REG4,0b10110000);        //10110000
writeRegister(CTRL_REG5,0b00000000);
}

void main()
{
lcd_init();
lcd_gotoxy(1,1);
printf(lcd_putc," L3GD20");   // l3g4200d
delay_ms(1000);
init_gyro();

while(true)
{
    i2c_start();
    i2c_write(0XD2);             
    i2c_write(0x28);
    i2c_start();
    i2c_write(0XD3);           
    xL=i2c_read();         
    xM=i2c_read(0);
    x=make16(xM,xL);
    i2c_stop();
    printf(lcd_putc"\f");
    lcd_gotoxy(1,2);
    printf(lcd_putc,"x=%Ld",x);
    delay_ms(50);
}

}

regards

Try the CCSC forums. Regardless of whether the code and the mpu wiring can even in principle communicate correctly with the chip, there are several problems with your code. It is hard to imagine that it even compiles.

This line says the clock frequency is 2 MHz and all delays are based on that value:
#use delay(clock=2000000)

Does this line NOT generate an error message?
printf(lcd_putc"\f");

The CCS forum folks recommend to use this I2C scanner program to see if your hardware and wiring are working correctly.
ccsinfo.com/forum/viewtopic. … hlight=i2c