/Designs/Measuring_instruments/AWS01B/SW/PIC16F887/main.c
11,7 → 11,7
#include "MPL3115.h"
#include "HMC5883L.h"
 
unsigned int16 timer0_overflow_count;
/*unsigned int16 timer0_overflow_count;
float anemo=0;
 
#int_TIMER1
31,76 → 31,45
void TIMER0_isr(void)
{
timer0_overflow_count++;
}*/
 
float wind_speed(void)
{
signed int16 Y,Z;
float b;
Y = mag_readY();
Z = mag_readZ();
 
b = atan2((float)Y,(float)Z); // vypocet azimutu z kartezskych souradnic
b = (b/3.141596)*180; // prevod na stupne
b += 180;
return b;
}
 
 
float azimut (void) //vypocet azimutu smeru vetru
 
float wind_direction(void) //vypocet azimutu smeru vetru
{
signed int16 X,Y,Z;
X= mag_readX();
Y= mag_readY();
Z= mag_readZ();
float b;
X = mag_readX();
Y = mag_readY();
 
float a, b;
a=(float)Y/X;
b=atan(a);
b = (b/3.14)*180;
b=abs(b);
 
if(X==0) //osetreni proti deleni 0
{
if(Y>0)
{
b=90;
}
else
{
b=270;
}
}
else
{
if(X>0)
{
if(Y>=0)
{
b=180+b;
}
else
{
b=180-b;
}
}
else
{
if(Y>=0)
{
b=360-b;
}
else
{
b=b;
}
}
}
 
return b;
b = atan2((float)Y,(float)X); // vypocet azimutu z kartezskych souradnic
b = (b/3.141596)*180; // prevod na stupne
b += 180;
return b;
}
 
 
void uvitani(void) // uvodni zprava
void welcome(void) // uvodni zprava
{
printf("\r\n\r\n# Meteorologicka stanice %s (C) 2013 www.mlab.cz \r\n",VERSION);
printf("\r\n %s \r\n",ID);// Welcome message
printf("# ver poradi ");
printf("altimet_t[°C] altimet_a[m] altimet_p[Pa] ");
printf("sht_t[°C] sht_h[%%] Anemo[m/s]check\r\n\r\n");
printf("altimet_t[C] altimet_a[m] altimet_p[Pa] ");
printf("sht_t[C] sht_h[%%] Anemo[m/s]check\r\n\r\n");
}
 
void main()
121,6 → 90,7
float sht25_t; //teplota z SHT25
float sht25_h; //relativni vlhkost z SHT25
float smer_v; //smer vetru
float anemo=0;
unsigned int8 sht_config;
 
130,25 → 100,20
SHT25_setup(sht_config);
 
//nastavení pøerušení pro anemometr
enable_interrupts(INT_TIMER1);
/*enable_interrupts(INT_TIMER1);
enable_interrupts(INT_TIMER0);
enable_interrupts(GLOBAL);
 
 
//uvitani();
set_mag(); //nastaveni magnetometru pro smer vetru
 
// vynulovani promenych pro anemometr
set_timer0(0);
set_timer1(0);
timer0_overflow_count=0;
anemo=0;
*/
 
welcome();
set_mag(); //nastaveni magnetometru pro smer vetru
 
while(TRUE)
{
char dataOUT[60];
int i=0;
 
mpl3115_setP(); //nastaveni pro tlak a teplotu
158,17 → 123,16
mpl3115_setA(); //nastaveni pro vysku a teplotu
delay_ms (500);
altimet_a=mpl3115_A();
altimet_a = mpl3115_A();
sht25_t=SHT25_get_temp(); //mereni hodnot z SHT25
sht25_h=SHT25_get_hum();
sht25_t = SHT25_get_temp(); //mereni hodnot z SHT25
sht25_h = SHT25_get_hum();
smer_v=azimut(); //vrati azimut aktualniho smeru vetru
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);
smer_v = wind_direction(); //vrati azimut aktualniho smeru vetru
anemo = wind_speed();
 
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);
printf(dataOUT); //zaslani hodnot na seriovou linku
 
delay_ms(1000);
}
}