Rev 2990 Rev 2996
Line 1... Line -...
1   -  
2 //Meteorologicka cast -  
3 #define VERSION "0.1" 1 #define VERSION "0.1"
4 #define ID "$Id: main.c 2916 2013-04-14 17:42:03Z kaklik $" 2 #define ID "$Id: main.c 2916 2013-04-14 17:42:03Z kaklik $"
5   3  
6 #include <main.h> 4 #include <main.h>
7 #include <math.h> 5 #include <math.h>
Line 9... Line 7...
9   7  
10 #include "SHT25.h" 8 #include "SHT25.h"
11 #include "MPL3115.h" 9 #include "MPL3115.h"
12 #include "HMC5883L.h" 10 #include "HMC5883L.h"
13   11  
14 /*unsigned int16 timer0_overflow_count; 12 unsigned int16 timer0_overflow_count;
15 float anemo=0; 13 float anemo=0;
-   14 unsigned int8 rain;
16   15  
17 #int_TIMER1 16 #int_TIMER1
18 void TIMER1_isr(void) 17 void TIMER1_isr(void)
19 { 18 {
20 // 32.768 kHz krystal pro timer1 oscilátor 19 // 32.768 kHz krystal pro timer1 oscilátor
21 anemo = ((timer0_overflow_count * 0xFF) + get_timer0())/(32768.0/0xFFFF); // pocet pulzu za 1s 20 anemo = ((timer0_overflow_count * 0xFF) + get_timer0())/(32768.0/0xFFFF); // pocet pulzu za 1s
22 anemo = anemo / 2; //pocet otacek za sekundu -  
23   21  
24 timer0_overflow_count=0; //nulovani 22 timer0_overflow_count=0; //nulovani
25 set_timer0(0); 23 set_timer0(0);
26 set_timer1(0); 24 set_timer1(0);
27   -  
-   25 output_toggle(PIN_E0);
28 } 26 }
29   27  
30 #int_TIMER0 //pro preteceni èítaèe pùlzù od anemometru (RA4) 28 #int_TIMER0 //pro preteceni èítaèe pùlzù od anemometru (RA4)
31 void TIMER0_isr(void) 29 void TIMER0_isr(void)
32 { 30 {
33 timer0_overflow_count++; 31 timer0_overflow_count++;
34 }*/ 32 }
35   33  
-   34 #INT_EXT
36 float wind_speed(void) 35 void EXT_isr() //interrup from rain sensor clip.
37 { 36 {
38 signed int16 Y,Z; -  
39 float b; 37 rain++;
40 Y = mag_readY(); -  
41 Z = mag_readZ(); -  
42   -  
43 b = atan2((float)Y,(float)Z); // vypocet azimutu z kartezskych souradnic 38 if (input(PIN_B0)) ext_int_edge( H_TO_L );
44 b = (b/3.141596)*180; // prevod na stupne 39 if (!input(PIN_B0)) ext_int_edge( L_TO_H );
45 b += 180; -  
46 return b; -  
47 } 40 }
48   41  
49   -  
50   -  
51 float wind_direction(void) //vypocet azimutu smeru vetru 42 float wind_direction(void) //vypocet azimutu smeru vetru
52 { 43 {
53 signed int16 X,Y,Z; 44 signed int16 X,Y,Z;
54 float b; 45 float b;
55 X = mag_readX(); 46 X = mag_readX();
Line 67... Line 58...
67 { 58 {
68 printf("\r\n\r\n# Meteorologicka stanice %s (C) 2013 www.mlab.cz \r\n",VERSION); 59 printf("\r\n\r\n# Meteorologicka stanice %s (C) 2013 www.mlab.cz \r\n",VERSION);
69 printf("\r\n %s \r\n",ID);// Welcome message 60 printf("\r\n %s \r\n",ID);// Welcome message
70 printf("# ver poradi "); 61 printf("# ver poradi ");
71 printf("altimet_t[C] altimet_a[m] altimet_p[Pa] "); 62 printf("altimet_t[C] altimet_a[m] altimet_p[Pa] ");
72 printf("sht_t[C] sht_h[%%] Anemo[m/s]check\r\n\r\n"); 63 printf("sht_t[C] sht_h[%%] sht_config Wind_direction Anemo[pls/s]check\r\n\r\n");
73 } 64 }
74   65  
75 void main() 66 void main()
76 { 67 {
77 setup_adc_ports(NO_ANALOGS|VSS_VDD); 68 setup_adc_ports(NO_ANALOGS|VSS_VDD);
Line 88... Line 79...
88 float altimet_p; //tlak z MPL3115 79 float altimet_p; //tlak z MPL3115
89 float altimet_a; //vyska z MPL3115 80 float altimet_a; //vyska z MPL3115
90 float sht25_t; //teplota z SHT25 81 float sht25_t; //teplota z SHT25
91 float sht25_h; //relativni vlhkost z SHT25 82 float sht25_h; //relativni vlhkost z SHT25
92 float smer_v; //smer vetru 83 float smer_v; //smer vetru
93 float anemo=0; -  
94 84
95 unsigned int8 sht_config; 85 unsigned int8 sht_config;
96   86  
97 //nastaveni SHT25 87 //nastaveni SHT25
98 SHT25_soft_reset(); 88 SHT25_soft_reset();
99 sht_config = SHT25_RH12_T14 | SHT25_HEATER_OFF; //vypnuti topeni v SHT25 89 sht_config = SHT25_RH12_T14 | SHT25_HEATER_OFF; //vypnuti topeni v SHT25
100 SHT25_setup(sht_config); 90 SHT25_setup(sht_config);
101   91  
102 //nastavení pøerušení pro anemometr 92 //nastavení pøerušení pro anemometr
103 /*enable_interrupts(INT_TIMER1); 93 enable_interrupts(INT_TIMER1);
104 enable_interrupts(INT_TIMER0); 94 enable_interrupts(INT_TIMER0);
-   95 enable_interrupts(INT_EXT);
105 enable_interrupts(GLOBAL); 96 enable_interrupts(GLOBAL);
106 // vynulovani promenych pro anemometr 97 // vynulovani promenych pro anemometr
107 set_timer0(0); 98 set_timer0(0);
108 set_timer1(0); 99 set_timer1(0);
109 timer0_overflow_count=0; 100 timer0_overflow_count=0;
-   101 rain=0;
110 */ 102  
111   103  
112 welcome(); 104 welcome();
113 set_mag(); //nastaveni magnetometru pro smer vetru 105 set_mag(); //nastaveni magnetometru pro smer vetru
114   106  
115 while(TRUE) 107 while(TRUE)
Line 136... Line 128...
136 sht25_t = SHT25_get_temp(); //mereni hodnot z SHT25 128 sht25_t = SHT25_get_temp(); //mereni hodnot z SHT25
137 sht25_h = SHT25_get_hum(); 129 sht25_h = SHT25_get_hum();
138 SHT25_setup(sht_config); 130 SHT25_setup(sht_config);
139 131
140 smer_v = wind_direction(); //vrati azimut aktualniho smeru vetru 132 smer_v = wind_direction(); //vrati azimut aktualniho smeru vetru
141 anemo = wind_speed(); -  
142   133  
143 printf(" %6.2f %7.2f %9.2f %6.2f %6.2f %X %5.2f %6.2f \n\r", altimet_t, altimet_a, altimet_p, sht25_t, sht25_h, sht_config, smer_v, anemo); 134 printf(" %6.2f %7.2f %9.2f %6.2f %6.2f %X %5.2f %6.1f %u \n\r", altimet_t, altimet_a, altimet_p, sht25_t, sht25_h, sht_config, smer_v, anemo, rain);
144 135
145 delay_ms(1000); 136 delay_ms(1000);
-   137 rain=0;
146 i++; 138 i++;
147 } 139 }
148 } 140 }
149   141