2926 |
jacho |
1 |
#include "main.h" |
2984 |
kaklik |
2 |
#include "HMC5883L.h" |
2988 |
kaklik |
3 |
#include <math.h> |
2926 |
jacho |
4 |
|
|
|
5 |
void main() |
|
|
6 |
{ |
2988 |
kaklik |
7 |
float last,b,anemo_speed; |
2985 |
kaklik |
8 |
unsigned int16 anemo_round=0; |
|
|
9 |
unsigned int16 i; |
|
|
10 |
|
|
|
11 |
|
|
|
12 |
//signed int16 X,Y,Z; |
2984 |
kaklik |
13 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
|
|
14 |
setup_adc(ADC_CLOCK_DIV_2); |
|
|
15 |
setup_spi(SPI_SS_DISABLED); |
|
|
16 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
|
|
17 |
setup_timer_1(T1_DISABLED); |
|
|
18 |
setup_timer_2(T2_DISABLED,0,1); |
|
|
19 |
setup_ccp1(CCP_OFF); |
|
|
20 |
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard |
2926 |
jacho |
21 |
|
2985 |
kaklik |
22 |
// Init the HMC5883L. Set Mode register for |
|
|
23 |
// continuous measurements. |
|
|
24 |
hmc5883l_write_reg(HMC5883L_CFG_A_REG, 0x18); // no average, maximal update range |
|
|
25 |
hmc5883l_write_reg(HMC5883L_CFG_B_REG, 0xE0); // maximal range |
|
|
26 |
hmc5883l_write_reg(HMC5883L_MODE_REG, 0x00); |
2926 |
jacho |
27 |
|
2985 |
kaklik |
28 |
// Continuously read and display the x,y,z results. |
|
|
29 |
// Wait at least 67 ms between reads, re the HMC5883L data sheet. |
|
|
30 |
|
|
|
31 |
|
2984 |
kaklik |
32 |
printf("Magnetometr: \r\n",); |
|
|
33 |
printf("(c)mlab JACHO 2013: \r\n",); |
|
|
34 |
printf("X, Y, Z \r\n",); |
2926 |
jacho |
35 |
|
2985 |
kaklik |
36 |
/* while(true) |
2984 |
kaklik |
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); |
2926 |
jacho |
43 |
|
2984 |
kaklik |
44 |
} |
2985 |
kaklik |
45 |
*/ |
|
|
46 |
|
|
|
47 |
while(TRUE) |
|
|
48 |
{ |
|
|
49 |
|
2988 |
kaklik |
50 |
// for(i=0;i<=10;i++) |
|
|
51 |
// { |
|
|
52 |
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; |
2985 |
kaklik |
57 |
|
2988 |
kaklik |
58 |
// anemo_speed += (b-last); |
|
|
59 |
// last=b; |
|
|
60 |
// delay_ms(10); |
|
|
61 |
// } |
|
|
62 |
// anemo_speed=anemo_speed/10; |
2985 |
kaklik |
63 |
|
2988 |
kaklik |
64 |
printf("%6Ld %6Ld %6Ld \n\r", compass.x, compass.y, compass.z); |
|
|
65 |
// delay_ms(100); |
2985 |
kaklik |
66 |
} |
|
|
67 |
|
2926 |
jacho |
68 |
} |
2985 |
kaklik |
69 |
|
|
|
70 |
|
|
|
71 |
|