Help with L3G4200D

Hi all,
I have a problem on reading angular rate data

This is my code:

#include "main.h"
#include "gyro.c"



void Write1Byte(int8,int8);
unsigned int8 Read(int8);

   int16 x=0,y=0,z=0;
   unsigned int8 X_L=0,X_H=0,Y_L=0,Y_H=0,Z_L=0,Z_H=0;
   


void main()
{
 

   SET_TRIS_D( 0x0F );
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_CLOCK_DIV_2);
   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);

  
   delay_ms(10);
  
   Write1Byte(CTRL_REG1,0b00001111);
   delay_ms(10);
   Write1Byte(CTRL_REG2,0b00000000);
   delay_ms(10);
   Write1Byte(CTRL_REG3,0b00000000);
   delay_ms(10);
   Write1Byte(CTRL_REG4,0b10100000);
   delay_ms(10);
   Write1Byte(CTRL_REG5,0b00000000);
   delay_ms(10);
   
   
   

     
  
  


  while(1)
   {
    
  
  
   X_L=Read(OUT_X_L);
   X_H=Read(OUT_X_H);
 
   Y_L=Read(OUT_Y_L);
   Y_H=Read(OUT_Y_H);
   
   Z_L=Read(OUT_Z_L);
   Z_H=Read(OUT_Z_H);
  

   

    
   fprintf(pc," x_h=%u  x_l=%u  ,  y_h=%u  y_l=%u  ,  Z_h=%u   Z_l=%u \n\r\ ",X_H,X_L,Y_H,Y_L,Z_H,Z_L);
   fprintf(pc,"X=%Ld\n\r\n\r",x);  
   
   X_L=0;
   X_H=0;
   
   Y_L=0;
   Y_H=0;
   
   Z_L=0;
   Z_H=0;
    
   delay_ms(100);
   output_toggle(pin_c0);
  
  
   }
   //TODO: User Code

}


void Write1Byte(int8 reg,int8 data)
{
   i2c_start();   
   i2c_write(0b11010000);
   i2c_write(reg);
   i2c_write(data);
   i2c_stop();
  
}


 unsigned int8 Read(int8 reg)
{
   unsigned int8 R=0;
   i2c_start();
   i2c_write(0b11010000);
   i2c_write(reg);
   i2c_stop();
   i2c_start();
   i2c_write(0b11010001);
   R=i2c_read(0);
   i2c_stop();
   
   return R;

}

and this is my data :
x_l=11 x_h=160 y_l=249 y_h=10 z_l=5 z_h=227
x_l=11 x_h=161 y_l=249 y_h=11 z_l=5 z_h=229
x_l=11 x_h=159 y_l=249 y_h=2 z_l=5 z_h=225
x_l=11 x_h=157 y_l=249 y_h=5 z_l=5 z_h=224
x_l=11 x_h=150 y_l=249 y_h=11 z_l=5 z_h=231

pls help me!!!

What exactly is your problem? Seems like your getting correct data from your sensor.

when I don't move the gyro and it's on a horizontal surface, the output values are not zero, they are noisy and don't have a fixed amount

What library do you use? Have you tried this one? GitHub - pololu/l3g4200d-arduino: Arduino library for the Pololu L3G4200D carrier board (deprecated; replaced by https://github.com/pololu/L3G)

it's my library:

#define CTRL_REG1     0x20
#define CTRL_REG2     0x21
#define CTRL_REG3     0x22
#define CTRL_REG4     0x23
#define CTRL_REG5     0x24
#define REFERENCE     0x25
#define OUT_TEMP      0x26
#define STATUS_REG    0x27

#define OUT_X_L       0x28
#define OUT_X_H       0x29
#define OUT_Y_L       0x2A
#define OUT_Y_H       0x2B
#define OUT_Z_L       0x2C
#define OUT_Z_H       0x2D

#define INT1_CFG      0x30
#define INT1_SRC      0x31

#define INT1_TSH_XH   0x32
#define INT1_TSH_XL   0x33
#define INT1_TSH_YH   0x34
#define INT1_TSH_YL   0x35
#define INT1_TSH_ZH   0x36
#define INT1_TSH_ZL   0x37

#define INT1_DURATION 0x38
   fprintf(pc," x_h=%u  x_l=%u  ,  y_h=%u  y_l=%u  ,  Z_h=%u   Z_l=%u \n\r\ ",X_H,X_L,Y_H,Y_L,Z_H,Z_L);

and this is my data :
x_l=11 x_h=160 y_l=249 y_h=10 z_l=5 z_h=227
x_l=11 x_h=161 y_l=249 y_h=11 z_l=5 z_h=229
x_l=11 x_h=159 y_l=249 y_h=2 z_l=5 z_h=225
x_l=11 x_h=157 y_l=249 y_h=5 z_l=5 z_h=224
x_l=11 x_h=150 y_l=249 y_h=11 z_l=5 z_h=231

You should provide output and code that actually match before confusing everyone.

Anyway the values you get back are fine, you are simply not combining them into a signed 16 bit int:

    int X = (Read (OUT_X_H) << 8) | Read (OUT_X_L) ;
    int Y = (Read (OUT_Y_H) << 8) | Read (OUT_Y_L) ;
    int Z = (Read (OUT_Z_H) << 8) | Read (OUT_Z_L) ;

You then simply need to tare the values in a calibration step.