Rev 960 Rev 1045
Line 10... Line 10...
10   10  
11 #include "SHT25.h" 11 #include "SHT25.h"
12 #include "MPL3115.h" 12 #include "MPL3115.h"
13 #include "HMC5883L.h" 13 #include "HMC5883L.h"
14   14  
15 #define SEND_DELAY 50 // Cas mezi dvema znaky na RS232 -  
16   -  
17 char VER[4]=VERSION; -  
18   -  
19 unsigned int16 timer0_overflow_count; 15 unsigned int16 timer0_overflow_count;
20 float anemo=0; 16 float anemo=0;
21   17  
22   -  
23   -  
24 #int_TIMER1 18 #int_TIMER1
25 void TIMER1_isr(void) 19 void TIMER1_isr(void)
26 { 20 {
27 // 32.768 kHz krystal pro timer1 oscilátor 21 // 32.768 kHz krystal pro timer1 oscilátor
28 anemo = ((timer0_overflow_count * 0xFF) + get_timer0())/(32768.0/0xFFFF); // pocet pulzu za 1s 22 anemo = ((timer0_overflow_count * 0xFF) + get_timer0())/(32768.0/0xFFFF); // pocet pulzu za 1s
Line 99... Line 93...
99 return b; 93 return b;
100 94
101 } 95 }
102   96  
103   97  
104   -  
105   -  
106   -  
107   -  
108 void uvitani(void) // uvodni zprava 98 void uvitani(void) // uvodni zprava
109 { 99 {
110 printf("\r\n\r\n# Meteorologicka stanice %s (C) 2013 www.mlab.cz \r\n",VERSION); 100 printf("\r\n\r\n# Meteorologicka stanice %s (C) 2013 www.mlab.cz \r\n",VERSION);
111 printf("\r\n# Autor: %s Posledni uprava: %s \r\n",AUTOR, DATE);// Welcome message 101 printf("\r\n# Autor: %s Posledni uprava: %s \r\n",AUTOR, DATE);// Welcome message
112 printf("# ver poradi "); 102 printf("# ver poradi ");
113 printf("altimet_t[°C] altimet_a[m] altimet_p[Pa] "); 103 printf("altimet_t[°C] altimet_a[m] altimet_p[Pa] ");
114 printf("sht_t[°C] sht_h[%%] Anemo[m/s]check\r\n\r\n"); 104 printf("sht_t[°C] sht_h[%%] Anemo[m/s]check\r\n\r\n");
115 } 105 }
116   106  
117 void main() 107 void main()
118 { 108 {
119 setup_wdt(WDT_2304MS); //nastavení resetu pokud nedojde v cas k jeho vynulovani -  
120 restart_wdt(); //---WDT -  
121 setup_adc_ports(NO_ANALOGS|VSS_VDD); 109 setup_adc_ports(NO_ANALOGS|VSS_VDD);
122 setup_adc(ADC_CLOCK_DIV_2); 110 setup_adc(ADC_CLOCK_DIV_2);
123 setup_spi(SPI_SS_DISABLED); 111 setup_spi(SPI_SS_DISABLED);
124 setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); 112 setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1);
125 setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT); 113 setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT);
Line 133... Line 121...
133 float altimet_a; //vyska z MPL3115 121 float altimet_a; //vyska z MPL3115
134 float sht25_t; //teplota z SHT25 122 float sht25_t; //teplota z SHT25
135 float sht25_h; //relativni vlhkost z SHT25 123 float sht25_h; //relativni vlhkost z SHT25
136 float smer_v; //smer vetru 124 float smer_v; //smer vetru
137 125
138 unsigned int16 poradi=0; //cislo vzorku -  
139 unsigned int8 sht_config; 126 unsigned int8 sht_config;
140   127  
141 //nastaveni SHT25 128 //nastaveni SHT25
142 SHT25_soft_reset(); 129 SHT25_soft_reset();
143 sht_config = SHT25_RH12_T14 | SHT25_HEATER_OFF; //vypnuti topeni v SHT25 130 sht_config = SHT25_RH12_T14 | SHT25_HEATER_OFF; //vypnuti topeni v SHT25
Line 145... Line 132...
145   132  
146 //nastavení pøerušení pro anemometr 133 //nastavení pøerušení pro anemometr
147 enable_interrupts(INT_TIMER1); 134 enable_interrupts(INT_TIMER1);
148 enable_interrupts(INT_TIMER0); 135 enable_interrupts(INT_TIMER0);
149 enable_interrupts(GLOBAL); 136 enable_interrupts(GLOBAL);
150 restart_wdt(); //---WDT -  
151   137  
-   138  
152 uvitani(); 139 //uvitani();
153 set_mag(); //nastaveni magnetometru pro smer vetru 140 set_mag(); //nastaveni magnetometru pro smer vetru
154   141  
155 // vynulovani promenych pro anemometr 142 // vynulovani promenych pro anemometr
156 set_timer0(0); 143 set_timer0(0);
157 set_timer1(0); 144 set_timer1(0);
158 timer0_overflow_count=0; 145 timer0_overflow_count=0;
159 anemo=0; 146 anemo=0;
-   147
160 148
161 restart_wdt(); //---WDT -  
162   149  
163 while(TRUE) 150 while(TRUE)
164 { 151 {
165 char output[12]; // vystupni zasobnik -  
166 int8 j; // ukazatel na retezec -  
167 int8 check=0; // Checksum is calculated between '$' and '*' -  
168 -  
169 152
-   153 char dataOUT[60];
-   154  
170 mpl3115_setP(); //nastaveni pro tlak a teplotu 155 mpl3115_setP(); //nastaveni pro tlak a teplotu
171 delay_ms (500); 156 delay_ms (500);
172 altimet_t=mpl3115_T(); 157 altimet_t=mpl3115_T();
173 altimet_p=mpl3115_P(); 158 altimet_p=mpl3115_P();
174 159
175 mpl3115_setA(); //nastaveni pro vysku a teplotu 160 mpl3115_setA(); //nastaveni pro vysku a teplotu
176 delay_ms (500); 161 delay_ms (500);
177 altimet_a=mpl3115_A(); 162 altimet_a=mpl3115_A();
178 163
179 sht25_t=SHT25_get_temp(); //mereni hodnot z SHT25 164 sht25_t=SHT25_get_temp(); //mereni hodnot z SHT25
180 sht25_h=SHT25_get_hum(); 165 sht25_h=SHT25_get_hum();
181 -  
182 smer_v=azimut(); //vrati azimut aktualniho smeru vetru -  
183 -  
184 166
185 delay_us(SEND_DELAY); -  
186 putc('$'); -  
187 delay_us(SEND_DELAY); -  
188 sprintf(output,"MST%s \0",VER); -  
189 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } -  
190 sprintf(output,"%4.0Lu \0", poradi); -  
191 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } -  
192 sprintf(output,"%6.2f \0", altimet_t ); -  
193 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } -  
194 sprintf(output,"%7.2f \0", altimet_a); -  
195 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } -  
196 sprintf(output,"%9.2f \0", altimet_p); -  
197 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } -  
198 sprintf(output,"%6.2f \0", sht25_t); -  
199 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } -  
200 sprintf(output,"%6.2f \0", sht25_h); -  
201 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } -  
202 sprintf(output,"%6.2f \0", smer_v); 167 smer_v=azimut(); //vrati azimut aktualniho smeru vetru
203 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } -  
204 sprintf(output,"%5.2f \0", anemo); -  
205 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } -  
206 sprintf(output,"*%X\r\n\0", check); -  
207 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j++]); } -  
208 delay_us(SEND_DELAY); -  
209 168
-   169 sprintf(dataOUT, " %6.2f %7.2f %9.2f %6.2f %6.2f %5.2f %6.2f", altimet_t, altimet_a, altimet_p, sht25_t, sht25_h, smer_v, anemo);
-   170
-   171 printf(dataOUT); //zaslani hodnot na seriovou linku
210 poradi++; 172 int i=0;
-   173 for(i=0;i<40;i++)
-   174 {
211 restart_wdt(); 175 delay_ms(1000);
-   176 }
212 } 177 }
213   178  
214 } 179 }
215   180  
216   -  
217   -