/Designs/Measuring_instruments/AWS01B/SW/PIC16F887/main.c
1,5 → 1,3
 
//Meteorologicka cast
#define VERSION "0.1"
#define ID "$Id: main.c 2916 2013-04-14 17:42:03Z kaklik $"
 
11,8 → 9,9
#include "MPL3115.h"
#include "HMC5883L.h"
 
/*unsigned int16 timer0_overflow_count;
unsigned int16 timer0_overflow_count;
float anemo=0;
unsigned int8 rain;
 
#int_TIMER1
void TIMER1_isr(void)
19,35 → 18,27
{
// 32.768 kHz krystal pro timer1 oscilátor
anemo = ((timer0_overflow_count * 0xFF) + get_timer0())/(32768.0/0xFFFF); // pocet pulzu za 1s
anemo = anemo / 2; //pocet otacek za sekundu
 
timer0_overflow_count=0; //nulovani
set_timer0(0);
set_timer1(0);
 
output_toggle(PIN_E0);
}
 
#int_TIMER0 //pro preteceni èítaèe pùlzù od anemometru (RA4)
void TIMER0_isr(void)
{
timer0_overflow_count++;
}*/
timer0_overflow_count++;
}
 
float wind_speed(void)
#INT_EXT
void EXT_isr() //interrup from rain sensor clip.
{
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;
rain++;
if (input(PIN_B0)) ext_int_edge( H_TO_L );
if (!input(PIN_B0)) ext_int_edge( L_TO_H );
}
 
 
 
float wind_direction(void) //vypocet azimutu smeru vetru
{
signed int16 X,Y,Z;
69,7 → 60,7
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("sht_t[C] sht_h[%%] sht_config Wind_direction Anemo[pls/s]check\r\n\r\n");
}
 
void main()
90,7 → 81,6
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;
 
100,15 → 90,17
SHT25_setup(sht_config);
 
//nastavení pøerušení pro anemometr
/*enable_interrupts(INT_TIMER1);
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_TIMER0);
enable_interrupts(INT_EXT);
enable_interrupts(GLOBAL);
// vynulovani promenych pro anemometr
set_timer0(0);
set_timer1(0);
timer0_overflow_count=0;
*/
rain=0;
 
 
welcome();
set_mag(); //nastaveni magnetometru pro smer vetru
 
138,11 → 130,11
SHT25_setup(sht_config);
smer_v = wind_direction(); //vrati azimut aktualniho smeru vetru
anemo = wind_speed();
 
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);
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);
delay_ms(1000);
rain=0;
i++;
}
}