2980 |
kaklik |
1 |
|
|
|
2 |
//Meteorologicka cast |
|
|
3 |
#define VERSION "0.1" |
|
|
4 |
#define ID "$Id: main.c 2916 2013-04-14 17:42:03Z kaklik $" |
|
|
5 |
|
|
|
6 |
#include <main.h> |
|
|
7 |
#include <math.h> |
|
|
8 |
#include <string.h> |
|
|
9 |
|
|
|
10 |
#include "SHT25.h" |
|
|
11 |
#include "MPL3115.h" |
|
|
12 |
#include "HMC5883L.h" |
|
|
13 |
|
2984 |
kaklik |
14 |
/*unsigned int16 timer0_overflow_count; |
2980 |
kaklik |
15 |
float anemo=0; |
|
|
16 |
|
|
|
17 |
#int_TIMER1 |
|
|
18 |
void TIMER1_isr(void) |
|
|
19 |
{ |
|
|
20 |
// 32.768 kHz krystal pro timer1 oscilátor |
|
|
21 |
anemo = ((timer0_overflow_count * 0xFF) + get_timer0())/(32768.0/0xFFFF); // pocet pulzu za 1s |
|
|
22 |
anemo = anemo / 2; //pocet otacek za sekundu |
|
|
23 |
|
|
|
24 |
timer0_overflow_count=0; //nulovani |
|
|
25 |
set_timer0(0); |
|
|
26 |
set_timer1(0); |
|
|
27 |
|
|
|
28 |
} |
|
|
29 |
|
|
|
30 |
#int_TIMER0 //pro preteceni èítaèe pùlzù od anemometru (RA4) |
|
|
31 |
void TIMER0_isr(void) |
|
|
32 |
{ |
|
|
33 |
timer0_overflow_count++; |
2984 |
kaklik |
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; |
2980 |
kaklik |
47 |
} |
|
|
48 |
|
|
|
49 |
|
2984 |
kaklik |
50 |
|
|
|
51 |
float wind_direction(void) //vypocet azimutu smeru vetru |
2980 |
kaklik |
52 |
{ |
|
|
53 |
signed int16 X,Y,Z; |
2984 |
kaklik |
54 |
float b; |
|
|
55 |
X = mag_readX(); |
|
|
56 |
Y = mag_readY(); |
|
|
57 |
|
2980 |
kaklik |
58 |
|
2984 |
kaklik |
59 |
b = atan2((float)Y,(float)X); // vypocet azimutu z kartezskych souradnic |
|
|
60 |
b = (b/3.141596)*180; // prevod na stupne |
|
|
61 |
b += 180; |
|
|
62 |
return b; |
2980 |
kaklik |
63 |
} |
|
|
64 |
|
|
|
65 |
|
2984 |
kaklik |
66 |
void welcome(void) // uvodni zprava |
2980 |
kaklik |
67 |
{ |
|
|
68 |
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 |
|
|
70 |
printf("# ver poradi "); |
2984 |
kaklik |
71 |
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"); |
2980 |
kaklik |
73 |
} |
|
|
74 |
|
|
|
75 |
void main() |
|
|
76 |
{ |
|
|
77 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
|
|
78 |
setup_adc(ADC_CLOCK_DIV_2); |
|
|
79 |
setup_spi(SPI_SS_DISABLED); |
|
|
80 |
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); |
|
|
81 |
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT); |
|
|
82 |
setup_timer_2(T2_DISABLED,0,1); |
|
|
83 |
setup_ccp1(CCP_OFF); |
|
|
84 |
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard |
|
|
85 |
|
|
|
86 |
|
|
|
87 |
float altimet_t; //teplota z MPL3115 |
|
|
88 |
float altimet_p; //tlak z MPL3115 |
|
|
89 |
float altimet_a; //vyska z MPL3115 |
|
|
90 |
float sht25_t; //teplota z SHT25 |
|
|
91 |
float sht25_h; //relativni vlhkost z SHT25 |
|
|
92 |
float smer_v; //smer vetru |
2984 |
kaklik |
93 |
float anemo=0; |
2980 |
kaklik |
94 |
|
|
|
95 |
unsigned int8 sht_config; |
|
|
96 |
|
|
|
97 |
//nastaveni SHT25 |
|
|
98 |
SHT25_soft_reset(); |
|
|
99 |
sht_config = SHT25_RH12_T14 | SHT25_HEATER_OFF; //vypnuti topeni v SHT25 |
|
|
100 |
SHT25_setup(sht_config); |
|
|
101 |
|
|
|
102 |
//nastavení pøeruení pro anemometr |
2984 |
kaklik |
103 |
/*enable_interrupts(INT_TIMER1); |
2980 |
kaklik |
104 |
enable_interrupts(INT_TIMER0); |
|
|
105 |
enable_interrupts(GLOBAL); |
|
|
106 |
// vynulovani promenych pro anemometr |
|
|
107 |
set_timer0(0); |
|
|
108 |
set_timer1(0); |
|
|
109 |
timer0_overflow_count=0; |
2984 |
kaklik |
110 |
*/ |
2980 |
kaklik |
111 |
|
2984 |
kaklik |
112 |
welcome(); |
|
|
113 |
set_mag(); //nastaveni magnetometru pro smer vetru |
|
|
114 |
|
2980 |
kaklik |
115 |
while(TRUE) |
|
|
116 |
{ |
|
|
117 |
int i=0; |
|
|
118 |
|
|
|
119 |
mpl3115_setP(); //nastaveni pro tlak a teplotu |
|
|
120 |
delay_ms (500); |
|
|
121 |
altimet_t=mpl3115_T(); |
|
|
122 |
altimet_p=mpl3115_P(); |
|
|
123 |
|
|
|
124 |
mpl3115_setA(); //nastaveni pro vysku a teplotu |
|
|
125 |
delay_ms (500); |
2984 |
kaklik |
126 |
altimet_a = mpl3115_A(); |
2980 |
kaklik |
127 |
|
2984 |
kaklik |
128 |
sht25_t = SHT25_get_temp(); //mereni hodnot z SHT25 |
|
|
129 |
sht25_h = SHT25_get_hum(); |
2980 |
kaklik |
130 |
|
2984 |
kaklik |
131 |
smer_v = wind_direction(); //vrati azimut aktualniho smeru vetru |
|
|
132 |
anemo = wind_speed(); |
|
|
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); |
2980 |
kaklik |
135 |
|
|
|
136 |
delay_ms(1000); |
|
|
137 |
} |
|
|
138 |
} |
|
|
139 |
|