Rev Author Line No. Line
2962 jacho 1 void setAK (void) //nastaveni akcelerometru
2 {
3 i2c_start();
4 I2C_Write(AK_W);
5 I2C_write(0x2A);
6 I2C_write(0x01); //nastavi aktivni stav
7  
8 i2c_stop();
9 }
10  
11  
12 int16 akR (int8 H, int8 L) //vycitani hodnot z akcelerometru
13 {
14 unsigned int8 XL=0,XH=0;
15 signed int16 x;
16  
17 i2c_start();
18 I2C_Write(AK_W);
19 I2C_write(H);
20 i2c_start();
21 I2C_Write(AK_R);
22 XH=i2c_read(0);
23 i2c_stop();
24  
25 i2c_start();
26 I2C_Write(AK_W);
27 I2C_write(L);
28 i2c_start();
29 I2C_Write(AK_R);
30 XL=i2c_read(0);
31 i2c_stop();
32  
33 x = (((unsigned int16) XH << 8) + XL ); //prevod na 16bit hodnotu
34 x=x/4;
35  
36 return x;
37 }
38  
39 int16 akX (void)
40 {
41 int16 X;
42 X= akR (AK_XH, AK_XL);
43 return X;
44 }
45  
46 int16 akY (void)
47 {
48 int16 Y;
49 Y= akR (AK_YH, AK_YL);
50 return Y;
51 }
52  
53 int16 akZ (void)
54 {
55 int16 Z;
56 Z= akR (AK_ZH, AK_ZL);
57 return Z;
58 }
59