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 |
{ |
2984 |
kaklik |
7 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
|
|
8 |
setup_adc(ADC_CLOCK_DIV_2); |
|
|
9 |
setup_spi(SPI_SS_DISABLED); |
|
|
10 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
|
|
11 |
setup_timer_1(T1_DISABLED); |
|
|
12 |
setup_timer_2(T2_DISABLED,0,1); |
|
|
13 |
setup_ccp1(CCP_OFF); |
3275 |
kaklik |
14 |
setup_comparator(NC_NC_NC_NC); |
2926 |
jacho |
15 |
|
2998 |
kaklik |
16 |
printf("Magnetometr: \r\n",); |
3275 |
kaklik |
17 |
printf("(c)mlab.cz kaklik 2013: \r\n",); |
2998 |
kaklik |
18 |
printf("X, Y, Z \r\n",); |
|
|
19 |
|
|
|
20 |
|
2985 |
kaklik |
21 |
// Init the HMC5883L. Set Mode register for |
|
|
22 |
// continuous measurements. |
|
|
23 |
hmc5883l_write_reg(HMC5883L_CFG_A_REG, 0x18); // no average, maximal update range |
3275 |
kaklik |
24 |
hmc5883l_write_reg(HMC5883L_CFG_B_REG, 0x00); // minimal range |
2985 |
kaklik |
25 |
hmc5883l_write_reg(HMC5883L_MODE_REG, 0x00); |
2926 |
jacho |
26 |
|
2985 |
kaklik |
27 |
// Continuously read and display the x,y,z results. |
|
|
28 |
// Wait at least 67 ms between reads, re the HMC5883L data sheet. |
|
|
29 |
|
|
|
30 |
|
|
|
31 |
while(TRUE) |
|
|
32 |
{ |
|
|
33 |
|
2998 |
kaklik |
34 |
hmc5883l_read_data(); |
|
|
35 |
printf("%6Ld %6Ld %6Ld \n\r", compass.x, compass.y, compass.z); |
|
|
36 |
delay_ms(100); |
2985 |
kaklik |
37 |
} |
|
|
38 |
|
2926 |
jacho |
39 |
} |
2985 |
kaklik |
40 |
|
|
|
41 |
|
|
|
42 |
|