Rev Author Line No. Line
1045 jacho 1 void set_mag (void) //uvodni nastaveni na kontinualni mereni, rozsah ± 8.1 Ga, frekvence mereni 15HZ
2 {
3 i2c_start(); //nastavení Configuration Register A
4 I2C_Write(MAG_ADDR_W);
5 I2C_Write(0x00);
6 I2C_Write(0x70);
7 i2c_stop();
8 Delay_ms(6);
9  
10 i2c_start(); //nastavení Configuration Register B
11 I2C_Write(MAG_ADDR_W);
12 I2C_Write(0x01);
13 I2C_Write(MAG_ROZ810);
14 i2c_stop();
15  
16 Delay_ms(6);
17  
18 i2c_start(); //nastveni Mode Register
19 I2C_Write(MAG_ADDR_W);
20 I2C_Write(0x02);
21 I2C_Write(0x00);
22 i2c_stop();
23 Delay_ms(6);
24 }
25  
26 void set_mag_roz (unsigned int8 h) //nastavy rozsah
27 {
28  
29 //
30  
31  
32 i2c_start();
33 I2C_Write(MAG_ADDR_W);
34 I2C_Write(0x01);
35 I2C_Write(h);
36 i2c_stop();
37  
38 Delay_ms(6);
39  
40  
41 }
42  
43  
44 byte mag_read(byte reg) //pro cteni reg
45 {
46  
47 i2c_start();
48 I2C_Write(MAG_ADDR_W);
49 I2C_write(reg);
50 i2c_stop();
51 i2c_start();
52 I2C_Write(MAG_ADDR_R);
53 reg=i2c_read(0);
54 return reg;
55 }
56  
57  
58 signed int16 mag_vypocet(unsigned int8 h, unsigned int8 l) //prepocet na 16bit cislo
59 {
60 signed int16 x;
61 x = (((unsigned int16) h << 8) + l );
62 return x;
63 }
64  
65  
66 signed int16 mag_readX(void) //nacteni osy x
67 {
68 unsigned int8 h,l;
69 signed int16 x;
70 h=mag_read(0x03);
71 l=mag_read(0x04);
72 x=mag_vypocet(h,l);
73 return x;
74  
75 }
76  
77  
78 signed int16 mag_readY(void) //nacteni osy x
79 {
80 unsigned int8 h,l;
81 signed int16 x;
82 h=mag_read(0x07);
83 l=mag_read(0x08);
84 x=mag_vypocet(h,l);
85 return x;
86  
87 }
88  
89  
90 signed int16 mag_readZ(void) //nacteni osy x
91 {
92 unsigned int8 h,l;
93 signed int16 x;
94 h=mag_read(0x05);
95 l=mag_read(0x06);
96 x=mag_vypocet(h,l);
97 return x;
98  
99 }
100  
101