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