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   15  
17 char VER[4]=VERSION; -  
-   16  
18   17  
19 unsigned int16 timer0_overflow_count; 18 unsigned int16 timer0_overflow_count;
20 float anemo=0; 19 float anemo=0;
21   20  
22   21  
Line 32... Line 31...
32 set_timer0(0); 31 set_timer0(0);
33 set_timer1(0); 32 set_timer1(0);
34   33  
35 } 34 }
36   35  
37 #int_TIMER0 //pro preteceni èítaèe pùlzù od anemometru 36 #int_TIMER0 //pro preteceni èítaèe pùlzù od anemometru (RA4)
38 void TIMER0_isr(void) 37 void TIMER0_isr(void)
39 { 38 {
40 timer0_overflow_count++; 39 timer0_overflow_count++;
41 } 40 }
42   41  
Line 114... Line 113...
114 printf("sht_t[°C] sht_h[%%] Anemo[m/s]check\r\n\r\n"); 113 printf("sht_t[°C] sht_h[%%] Anemo[m/s]check\r\n\r\n");
115 } 114 }
116   115  
117 void main() 116 void main()
118 { 117 {
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); 118 setup_adc_ports(NO_ANALOGS|VSS_VDD);
122 setup_adc(ADC_CLOCK_DIV_2); 119 setup_adc(ADC_CLOCK_DIV_2);
123 setup_spi(SPI_SS_DISABLED); 120 setup_spi(SPI_SS_DISABLED);
124 setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); 121 setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1);
125 setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT); 122 setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT);
Line 133... Line 130...
133 float altimet_a; //vyska z MPL3115 130 float altimet_a; //vyska z MPL3115
134 float sht25_t; //teplota z SHT25 131 float sht25_t; //teplota z SHT25
135 float sht25_h; //relativni vlhkost z SHT25 132 float sht25_h; //relativni vlhkost z SHT25
136 float smer_v; //smer vetru 133 float smer_v; //smer vetru
137 134
138 unsigned int16 poradi=0; //cislo vzorku -  
-   135  
139 unsigned int8 sht_config; 136 unsigned int8 sht_config;
140   137  
-   138  
-   139  
141 //nastaveni SHT25 140 //nastaveni SHT25
142 SHT25_soft_reset(); 141 SHT25_soft_reset();
143 sht_config = SHT25_RH12_T14 | SHT25_HEATER_OFF; //vypnuti topeni v SHT25 142 sht_config = SHT25_RH12_T14 | SHT25_HEATER_OFF; //vypnuti topeni v SHT25
144 SHT25_setup(sht_config); 143 SHT25_setup(sht_config);
145   144  
146 //nastavení pøerušení pro anemometr 145 //nastavení pøerušení pro anemometr
147 enable_interrupts(INT_TIMER1); 146 enable_interrupts(INT_TIMER1);
148 enable_interrupts(INT_TIMER0); 147 enable_interrupts(INT_TIMER0);
149 enable_interrupts(GLOBAL); 148 enable_interrupts(GLOBAL);
150 restart_wdt(); //---WDT -  
151   149  
-   150  
152 uvitani(); 151 //uvitani();
153 set_mag(); //nastaveni magnetometru pro smer vetru 152 set_mag(); //nastaveni magnetometru pro smer vetru
154   153  
155 // vynulovani promenych pro anemometr 154 // vynulovani promenych pro anemometr
156 set_timer0(0); 155 set_timer0(0);
157 set_timer1(0); 156 set_timer1(0);
158 timer0_overflow_count=0; 157 timer0_overflow_count=0;
159 anemo=0; 158 anemo=0;
160 159
161 restart_wdt(); //---WDT 160
162   161  
163 while(TRUE) 162 while(TRUE)
164 { 163 {
165 char output[12]; // vystupni zasobnik -  
166 int8 j; // ukazatel na retezec -  
167 int8 check=0; // Checksum is calculated between '$' and '*' -  
168 -  
169 164
-   165 char dataOUT[60];
-   166  
170 mpl3115_setP(); //nastaveni pro tlak a teplotu 167 mpl3115_setP(); //nastaveni pro tlak a teplotu
171 delay_ms (500); 168 delay_ms (500);
172 altimet_t=mpl3115_T(); 169 altimet_t=mpl3115_T();
173 altimet_p=mpl3115_P(); 170 altimet_p=mpl3115_P();
174 171
175 mpl3115_setA(); //nastaveni pro vysku a teplotu 172 mpl3115_setA(); //nastaveni pro vysku a teplotu
176 delay_ms (500); 173 delay_ms (500);
177 altimet_a=mpl3115_A(); 174 altimet_a=mpl3115_A();
178 175
179 sht25_t=SHT25_get_temp(); //mereni hodnot z SHT25 176 sht25_t=SHT25_get_temp(); //mereni hodnot z SHT25
180 sht25_h=SHT25_get_hum(); 177 sht25_h=SHT25_get_hum();
181 -  
182 smer_v=azimut(); //vrati azimut aktualniho smeru vetru -  
183 178
-   179 smer_v=azimut(); //vrati azimut aktualniho smeru vetru
184 180
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++]; } 181 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);
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); -  
203 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } -  
-   182
204 sprintf(output,"%5.2f \0", anemo); 183 printf(dataOUT);
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); 184 int i=0;
207 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j++]); } -  
208 delay_us(SEND_DELAY); 185 for(i=0,i<40;i++)
209 186 {
210 poradi++; 187 delay_ms(1000);
211 restart_wdt(); 188 }
212 } 189 }
213   190  
214 } 191 }
215   192  
216   -  
217   -