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