Rev Author Line No. Line
1045 jacho 1 #include <main.h>
2 #define EEPROM_SDA PIN_B0
3 #define EEPROM_SCL PIN_B1
4 #use i2c(master, sda=EEPROM_SDA, scl=EEPROM_SCL)
5 #use rs232(baud=9600,parity=N,xmit=PIN_B3,rcv=PIN_B2,bits=8) //rcv TXD xmit RXD
6 #include <math.h>
7 #include <HMC5883L.h>
8  
9  
10  
11  
12  
13  
14  
15  
16 float azimut (void) //vypocet aktualni vysky panelu
17 {
18 signed int16 x,y,z;
19  
20 x= mag_readX();
21 y= mag_readY();
22 z= mag_readY();
23  
24  
25 float a, b;
26 a=(float)y/x;
27 b=atan(a);
28 b = (b/3.14)*180;
29 b=abs(b);
30  
31  
32  
33  
34 if(x==0) //osetreni proti deleni 0
35 {
36 printf("Elektronický kompas0\r\n",);
37 if(y>0)
38 {
39 b=90;
40 }
41 else
42 {
43 b=270;
44 }
45 }
46 else
47 {
48 if(x>0)
49 {
50 if(y>=0)
51 {
52 b=180+b;
53 printf("180+b\r\n",);
54 }
55 else
56 {
57 b=180-b;
58 printf("180-b\r\n",);
59 }
60 }
61 else
62 {
63 if(y>=0)
64 {
65 b=360-b;
66 printf("360-b\r\n",);
67 }
68 else
69 {
70 b=b;
71 printf("b\r\n",);
72 }
73 }
74  
75 }
76  
77 return b;
78  
79 }
80  
81 void main()
82 {
83  
84 setup_adc_ports(NO_ANALOGS|VSS_VDD);
85 setup_adc(ADC_CLOCK_DIV_2);
86 setup_spi(SPI_SS_DISABLED);
87 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
88 setup_timer_1(T1_DISABLED);
89 setup_timer_2(T2_DISABLED,0,1);
90 setup_ccp1(CCP_OFF);
91 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
92  
93 printf("Elektronický kompas\r\n",);
94 float az,k=0;
95 set_mag();
96 signed int16 X,Y,Z;
97 while(true)
98 {
99 az=azimut();
100  
101  
102  
103  
104 printf("Elektronický kompas \r\n",);
105 printf("Simple Thermomether %10.2f \r\n", az);
106  
107 //X=mag_readX();
108 //Y=mag_readY();
109 //Z=mag_readZ();
110 printf("Simple Thermometherx %Ld \r\n", X);
111 printf("Simple Thermomethery %Ld \r\n", Y);
112 printf("Simple Thermometherz %Ld \r\n", Z);
113 Delay_ms(2000);
114  
115 }
116 }