Rev 2980 Rev 2984
Line 9... Line 9...
9   9  
10 #include "SHT25.h" 10 #include "SHT25.h"
11 #include "MPL3115.h" 11 #include "MPL3115.h"
12 #include "HMC5883L.h" 12 #include "HMC5883L.h"
13   13  
14 unsigned int16 timer0_overflow_count; 14 /*unsigned int16 timer0_overflow_count;
15 float anemo=0; 15 float anemo=0;
16   16  
17 #int_TIMER1 17 #int_TIMER1
18 void TIMER1_isr(void) 18 void TIMER1_isr(void)
19 { 19 {
Line 29... Line 29...
29   29  
30 #int_TIMER0 //pro preteceni èítaèe pùlzù od anemometru (RA4) 30 #int_TIMER0 //pro preteceni èítaèe pùlzù od anemometru (RA4)
31 void TIMER0_isr(void) 31 void TIMER0_isr(void)
32 { 32 {
33 timer0_overflow_count++; 33 timer0_overflow_count++;
-   34 }*/
-   35  
-   36 float wind_speed(void)
-   37 {
-   38 signed int16 Y,Z;
-   39 float b;
-   40 Y = mag_readY();
-   41 Z = mag_readZ();
-   42  
-   43 b = atan2((float)Y,(float)Z); // vypocet azimutu z kartezskych souradnic
-   44 b = (b/3.141596)*180; // prevod na stupne
-   45 b += 180;
-   46 return b;
34 } 47 }
35   48  
36   49  
-   50  
37 float azimut (void) //vypocet azimutu smeru vetru 51 float wind_direction(void) //vypocet azimutu smeru vetru
38 { 52 {
39 signed int16 X,Y,Z; 53 signed int16 X,Y,Z;
40 X= mag_readX(); 54 float b;
41 Y= mag_readY(); 55 X = mag_readX();
42 Z= mag_readZ(); 56 Y = mag_readY();
43   -  
44 float a, b; -  
45 a=(float)Y/X; -  
46 b=atan(a); -  
47 b = (b/3.14)*180; -  
48 b=abs(b); -  
49   57
50 if(X==0) //osetreni proti deleni 0 -  
51 { -  
52 if(Y>0) -  
53 { -  
54 b=90; -  
55 } -  
56 else -  
57 { -  
58 b=270; -  
59 } -  
60 } -  
61 else -  
62 { -  
63 if(X>0) -  
64 { -  
65 if(Y>=0) -  
66 { -  
67 b=180+b; -  
68 -  
69 } -  
70 else -  
71 { -  
72 b=180-b; -  
73 -  
74 } -  
75 } -  
76 else -  
77 { -  
78 if(Y>=0) -  
79 { -  
80 b=360-b; -  
81 -  
82 } -  
83 else -  
84 { -  
85 b=b; -  
86 -  
87 } -  
88 } -  
89 -  
90 } -  
91   58  
-   59 b = atan2((float)Y,(float)X); // vypocet azimutu z kartezskych souradnic
-   60 b = (b/3.141596)*180; // prevod na stupne
92 return b; 61 b += 180;
93 62 return b;
94 } 63 }
95   64  
96   65  
97 void uvitani(void) // uvodni zprava 66 void welcome(void) // uvodni zprava
98 { 67 {
99 printf("\r\n\r\n# Meteorologicka stanice %s (C) 2013 www.mlab.cz \r\n",VERSION); 68 printf("\r\n\r\n# Meteorologicka stanice %s (C) 2013 www.mlab.cz \r\n",VERSION);
100 printf("\r\n %s \r\n",ID);// Welcome message 69 printf("\r\n %s \r\n",ID);// Welcome message
101 printf("# ver poradi "); 70 printf("# ver poradi ");
102 printf("altimet_t[°C] altimet_a[m] altimet_p[Pa] "); 71 printf("altimet_t[C] altimet_a[m] altimet_p[Pa] ");
103 printf("sht_t[°C] sht_h[%%] Anemo[m/s]check\r\n\r\n"); 72 printf("sht_t[C] sht_h[%%] Anemo[m/s]check\r\n\r\n");
104 } 73 }
105   74  
106 void main() 75 void main()
107 { 76 {
108 setup_adc_ports(NO_ANALOGS|VSS_VDD); 77 setup_adc_ports(NO_ANALOGS|VSS_VDD);
Line 119... Line 88...
119 float altimet_p; //tlak z MPL3115 88 float altimet_p; //tlak z MPL3115
120 float altimet_a; //vyska z MPL3115 89 float altimet_a; //vyska z MPL3115
121 float sht25_t; //teplota z SHT25 90 float sht25_t; //teplota z SHT25
122 float sht25_h; //relativni vlhkost z SHT25 91 float sht25_h; //relativni vlhkost z SHT25
123 float smer_v; //smer vetru 92 float smer_v; //smer vetru
-   93 float anemo=0;
124 94
125 unsigned int8 sht_config; 95 unsigned int8 sht_config;
126   96  
127 //nastaveni SHT25 97 //nastaveni SHT25
128 SHT25_soft_reset(); 98 SHT25_soft_reset();
129 sht_config = SHT25_RH12_T14 | SHT25_HEATER_OFF; //vypnuti topeni v SHT25 99 sht_config = SHT25_RH12_T14 | SHT25_HEATER_OFF; //vypnuti topeni v SHT25
130 SHT25_setup(sht_config); 100 SHT25_setup(sht_config);
131   101  
132 //nastavení pøerušení pro anemometr 102 //nastavení pøerušení pro anemometr
133 enable_interrupts(INT_TIMER1); 103 /*enable_interrupts(INT_TIMER1);
134 enable_interrupts(INT_TIMER0); 104 enable_interrupts(INT_TIMER0);
135 enable_interrupts(GLOBAL); 105 enable_interrupts(GLOBAL);
136   -  
137   -  
138 //uvitani(); -  
139 set_mag(); //nastaveni magnetometru pro smer vetru -  
140   -  
141 // vynulovani promenych pro anemometr 106 // vynulovani promenych pro anemometr
142 set_timer0(0); 107 set_timer0(0);
143 set_timer1(0); 108 set_timer1(0);
144 timer0_overflow_count=0; 109 timer0_overflow_count=0;
145 anemo=0; -  
146 110 */
147 111  
-   112 welcome();
-   113 set_mag(); //nastaveni magnetometru pro smer vetru
148   114  
149 while(TRUE) 115 while(TRUE)
150 { 116 {
151 char dataOUT[60]; -  
152 int i=0; 117 int i=0;
153   118  
154 mpl3115_setP(); //nastaveni pro tlak a teplotu 119 mpl3115_setP(); //nastaveni pro tlak a teplotu
155 delay_ms (500); 120 delay_ms (500);
156 altimet_t=mpl3115_T(); 121 altimet_t=mpl3115_T();
157 altimet_p=mpl3115_P(); 122 altimet_p=mpl3115_P();
158 123
159 mpl3115_setA(); //nastaveni pro vysku a teplotu 124 mpl3115_setA(); //nastaveni pro vysku a teplotu
160 delay_ms (500); 125 delay_ms (500);
161 altimet_a=mpl3115_A(); 126 altimet_a = mpl3115_A();
162 127
163 sht25_t=SHT25_get_temp(); //mereni hodnot z SHT25 128 sht25_t = SHT25_get_temp(); //mereni hodnot z SHT25
164 sht25_h=SHT25_get_hum(); 129 sht25_h = SHT25_get_hum();
165 -  
166 smer_v=azimut(); //vrati azimut aktualniho smeru vetru -  
167 130
168 sprintf(dataOUT, " %6.2f %7.2f %9.2f %6.2f %6.2f %5.2f %6.2f \n\r", altimet_t, altimet_a, altimet_p, sht25_t, sht25_h, smer_v, anemo); 131 smer_v = wind_direction(); //vrati azimut aktualniho smeru vetru
169 -  
170 printf(dataOUT); //zaslani hodnot na seriovou linku 132 anemo = wind_speed();
171   133  
-   134 printf(" %6.2f %7.2f %9.2f %6.2f %6.2f %5.2f %6.2f \n\r", altimet_t, altimet_a, altimet_p, sht25_t, sht25_h, smer_v, anemo);
-   135
172 delay_ms(1000); 136 delay_ms(1000);
173 } 137 }
174 } 138 }
175   139