Line 6... |
Line 6... |
6 |
{ |
6 |
{ |
7 |
float last,b,anemo_speed; |
7 |
float last,b,anemo_speed; |
8 |
unsigned int16 anemo_round=0; |
8 |
unsigned int16 anemo_round=0; |
9 |
unsigned int16 i; |
9 |
unsigned int16 i; |
10 |
|
10 |
|
11 |
|
- |
|
12 |
//signed int16 X,Y,Z; |
11 |
//signed int16 X,Y,Z; |
13 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
12 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
14 |
setup_adc(ADC_CLOCK_DIV_2); |
13 |
setup_adc(ADC_CLOCK_DIV_2); |
15 |
setup_spi(SPI_SS_DISABLED); |
14 |
setup_spi(SPI_SS_DISABLED); |
16 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
15 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
17 |
setup_timer_1(T1_DISABLED); |
16 |
setup_timer_1(T1_DISABLED); |
18 |
setup_timer_2(T2_DISABLED,0,1); |
17 |
setup_timer_2(T2_DISABLED,0,1); |
19 |
setup_ccp1(CCP_OFF); |
18 |
setup_ccp1(CCP_OFF); |
20 |
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard |
19 |
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard |
21 |
|
20 |
|
- |
|
21 |
printf("Magnetometr: \r\n",); |
- |
|
22 |
printf("(c)mlab JACHO 2013: \r\n",); |
- |
|
23 |
printf("X, Y, Z \r\n",); |
- |
|
24 |
|
- |
|
25 |
|
22 |
// Init the HMC5883L. Set Mode register for |
26 |
// Init the HMC5883L. Set Mode register for |
23 |
// continuous measurements. |
27 |
// continuous measurements. |
24 |
hmc5883l_write_reg(HMC5883L_CFG_A_REG, 0x18); // no average, maximal update range |
28 |
hmc5883l_write_reg(HMC5883L_CFG_A_REG, 0x18); // no average, maximal update range |
25 |
hmc5883l_write_reg(HMC5883L_CFG_B_REG, 0xE0); // maximal range |
29 |
hmc5883l_write_reg(HMC5883L_CFG_B_REG, 0xE0); // maximal range |
26 |
hmc5883l_write_reg(HMC5883L_MODE_REG, 0x00); |
30 |
hmc5883l_write_reg(HMC5883L_MODE_REG, 0x00); |
27 |
|
31 |
|
28 |
// Continuously read and display the x,y,z results. |
32 |
// Continuously read and display the x,y,z results. |
29 |
// Wait at least 67 ms between reads, re the HMC5883L data sheet. |
33 |
// Wait at least 67 ms between reads, re the HMC5883L data sheet. |
30 |
|
34 |
|
31 |
|
35 |
|
32 |
printf("Magnetometr: \r\n",); |
- |
|
33 |
printf("(c)mlab JACHO 2013: \r\n",); |
- |
|
34 |
printf("X, Y, Z \r\n",); |
- |
|
35 |
|
- |
|
36 |
/* while(true) |
- |
|
37 |
{ |
- |
|
38 |
X = mag_readX(); |
- |
|
39 |
Y = mag_readY(); |
- |
|
40 |
Z = mag_readZ(); |
- |
|
41 |
printf("%4Ld %4Ld %4Ld \r\n", X, Y, Z); |
- |
|
42 |
Delay_ms(50); |
- |
|
43 |
|
- |
|
44 |
} |
- |
|
45 |
*/ |
- |
|
46 |
|
- |
|
47 |
while(TRUE) |
36 |
while(TRUE) |
48 |
{ |
37 |
{ |
49 |
|
38 |
|
50 |
// for(i=0;i<=10;i++) |
- |
|
51 |
// { |
- |
|
52 |
hmc5883l_read_data(); |
39 |
hmc5883l_read_data(); |
53 |
|
- |
|
54 |
// b = atan2((float)compass.y,(float)compass.x); // vypocet azimutu z kartezskych souradnic |
- |
|
55 |
// b = (b/3.141596)*180; // prevod na stupne |
- |
|
56 |
// b += 180; |
- |
|
57 |
|
- |
|
58 |
// anemo_speed += (b-last); |
- |
|
59 |
// last=b; |
- |
|
60 |
// delay_ms(10); |
- |
|
61 |
// } |
- |
|
62 |
// anemo_speed=anemo_speed/10; |
- |
|
63 |
|
- |
|
64 |
printf("%6Ld %6Ld %6Ld \n\r", compass.x, compass.y, compass.z); |
40 |
printf("%6Ld %6Ld %6Ld \n\r", compass.x, compass.y, compass.z); |
65 |
// delay_ms(100); |
41 |
delay_ms(100); |
66 |
} |
42 |
} |
67 |
|
43 |
|
68 |
} |
44 |
} |
69 |
|
45 |
|
70 |
|
46 |
|