Rev Author Line No. Line
2926 jacho 1 #include "main.h"
2984 kaklik 2 #include "HMC5883L.h"
2926 jacho 3  
4 void main()
5 {
2985 kaklik 6 int1 last;
7 unsigned int16 anemo_round=0;
8 unsigned int16 i;
9  
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  
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
24 hmc5883l_write_reg(HMC5883L_CFG_B_REG, 0xE0); // maximal range
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  
2984 kaklik 31 printf("Magnetometr: \r\n",);
32 printf("(c)mlab JACHO 2013: \r\n",);
33 printf("X, Y, Z \r\n",);
2926 jacho 34  
2985 kaklik 35 /* while(true)
2984 kaklik 36 {
37 X = mag_readX();
38 Y = mag_readY();
39 Z = mag_readZ();
40 printf("%4Ld %4Ld %4Ld \r\n", X, Y, Z);
41 Delay_ms(50);
2926 jacho 42  
2984 kaklik 43 }
2985 kaklik 44 */
45  
46 while(TRUE)
47 {
48  
49 for( i=0;i<=1000;i++)
50 {
51 // delay_ms();
52 hmc5883l_read_data();
53  
54 if(compass.x < 0)
55 {
56 if(last == 1) anemo_round++;
57 last=0;
58 }
59 if(compass.x > 0) last=1;
60 }
61  
62 printf("%6Ld %6Ld %6Ld %6Ld \n\r", compass.x, compass.y, compass.z, anemo_round);
63 anemo_round=0;
64 }
65  
2926 jacho 66 }
2985 kaklik 67  
68  
69