Rev Author Line No. Line
1045 jacho 1 #include "C:\Users\Honza\Documents\pic\poloha_slunce\main.h"
2  
3 #include "math.h"
4  
5 #define PIN_SDA PIN_B0
6 #define PIN_SCL PIN_B1
7 #use i2c(master, sda=PIN_SDA, scl=PIN_SCL)
8 //set RS232
9 #use rs232(baud=9600,parity=N,xmit=PIN_C7,rcv=PIN_C6,bits=8) //rcv TXD xmit RXD
10  
11  
12 signed int16 AZIMUT;
13 signed int ELEVACE;
14  
15 int stupne (float rad)
16 {
17 int a =(int) ((rad/3.14)*180);
18 return a;
19 }
20  
21 float rad (float stup)
22 {
23 float a = ((stup/180)*3.14);
24 return a;
25 }
26  
27 //provede vypocet dnu od zacatku roku
28 int16 den (int m, int16 d) //vstupem je mesic a den
29 {
30 switch (m) {
31  
32 case 1: d=d;
33  
34 break;
35  
36 case 2: d=31+d;
37  
38 break;
39  
40 case 3: d=58+d;
41  
42 break;
43  
44 case 4: d=89+d;
45  
46 break;
47 case 5: d=119+d;
48  
49 break;
50  
51 case 6: d=150+d;
52  
53 break;
54 case 7: d=180+d;
55  
56 break;
57  
58 case 8: d=211+d;
59  
60 break;
61 case 9: d=242+d;
62  
63 break;
64  
65 case 10: d=262+d;
66  
67 break;
68 case 11: d=303+d;
69  
70 break;
71  
72 case 12: d=333+d;
73  
74 break;
75  
76 default:printf("chyba");
77  
78 break; }
79  
80  
81 printf("Den: %ld\r\n", d);
82 return d;
83  
84 }
85  
86 float deklinace (float d) //vstupem je den v roce
87 {
88 float b = 0.98630137;
89 d=((rad(23.45))*sin(rad(b*(d-81))));
90 return d;
91  
92 }
93  
94 float lstm (int gmt) //vstupem je GMT dane lokality
95 {
96 float a;
97 a=((rad(15))*gmt);
98 return a;
99 }
100  
101  
102 float eot (float d) //vstupem je den v roce
103 {
104 float a;
105 a=rad(0.98630137*(d-81));
106 a=9.87*sin(2*a)-7.53*cos(a)-1.5*sin(a);
107 return a;
108  
109 }
110  
111  
112 float tc (int delka, float lstm, float eot) //vstupem je zemepisná delka, LSTM, EoT
113 {
114 float a;
115 a=4*(float)(delka-lstm)+eot;
116 return a;
117 }
118  
119  
120 float lst (float lt, float tc) //vstupem je den GMT dane lokality
121 {
122 float a;
123 a=lt+(tc/60);
124 return a;
125 }
126  
127 float hra (float lst) //vstupem je den v roce
128 {
129 lst=(rad(15))*(lst-12);
130 return lst;
131  
132 }
133  
134 void poziceSL(int m, int d, int h, int min, int gmt, float sirka, float delka) //vstupem je mesic, den, hodina, minuty, GMT, zemepisna sirka ve stupnich
135 {
136 float den1;
137 float ele,azi,deklin, lstm1, eot1, tc1, lst1, hra1;
138 float lt = h+(min/60);
139  
140 den1=(float) den(m,d);
141 deklin=deklinace(den1);
142 lstm1=lstm(gmt);
143 eot1=eot(den1);
144 tc1=tc(delka, lstm1, eot1);
145 lst1=lst(lt,tc1);
146 hra1=hra(lst1);
147  
148 sirka=rad(sirka);
149 ele=asin((sin(deklin)*sin(sirka))+(cos(deklin)*cos(sirka)*cos(hra1)));
150 azi = acos(((sin(deklin)*cos(sirka))-(cos(deklin)*sin(sirka)*cos(hra1)))/(cos(ele)));
151  
152 //printf("Azimut: %6.3f\r\n", azi);
153 //printf("Elevce: %6.3f\r\n", ele);
154 ELEVACE=stupne(ele);
155 AZIMUT= stupne(azi);
156 if(hra1>0)
157 {
158 AZIMUT= 360-AZIMUT;
159 }
160 }
161  
162 void main()
163 {
164  
165 setup_adc_ports(NO_ANALOGS|VSS_VDD);
166 setup_adc(ADC_CLOCK_DIV_2);
167 setup_spi(SPI_SS_DISABLED);
168 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
169 setup_timer_1(T1_DISABLED);
170 setup_timer_2(T2_DISABLED,0,1);
171 setup_ccp1(CCP_OFF);
172 setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
173  
174 //TODO: User Code
175  
176 while(TRUE)
177 {
178 //do promenne AZIMUT vlosti azimut a do ELEVACE elevaci slunce
179 poziceSL(11, 18, 14, 0, 0, 49, 14); //int mesic, den, hodina, minuta, odchylka èasu od GMT, sirka, delka
180  
181  
182 printf("Azimut: %ld\r\n", AZIMUT);
183 printf("Elevce: %d\r\n", ELEVACE);
184 delay_ms(2000);
185  
186 }
187  
188  
189  
190  
191 }