8,6 → 8,8 |
#CASE // Case sensitive compiler |
|
#define SEND_DELAY 50 // Time between two characters on RS232 |
#define RESPONSE_DELAY 100 // Reaction time after receiving a command |
#define MEASURE_DELAY 1000 // Delay to a next measurement |
|
char VER[4]=VERSION; // Buffer for concatenate of a version string |
|
25,27 → 27,33 |
#include "..\MPL115A1.c" |
|
unsigned int16 timer0_overflow_count; |
float anemo; |
unsigned int16 timer1_overflow_count; |
float anemo_max; |
|
int1 barometer_present; |
|
float anemo_compute() |
{ |
float anemo; |
anemo = ((timer0_overflow_count * 0xFF) + get_timer0())/(((timer1_overflow_count * 0xFFFF) + get_timer1())/32768.0); // pulses per second calculation |
anemo = anemo / 10.5; // frequency divided by anemomether constant. |
return anemo; |
} |
|
#int_TIMER1 |
void TIMER1_isr(void) |
{ |
// wind speed calculation 32.768 kHz crystal on timer1 oscilator expected. |
anemo = ((timer0_overflow_count * 0xFF) + get_timer0())/(0xFFFF/32768.0); // pulses per second calculation |
anemo = anemo / 10.5; // frequency divided by anemomether constant. |
float anemo; |
anemo = anemo_compute(); |
if (anemo > anemo_max) anemo_max=anemo; |
|
timer0_overflow_count=0; |
set_timer0(0); |
set_timer1(0); |
output_toggle(PIN_E0); |
timer1_overflow_count++; |
} |
|
#int_TIMER0 // anemometr pulses counting timer owerflow |
#int_TIMER0 // anemometr pulses counting timer owerflow |
void TIMER0_isr(void) |
{ |
timer0_overflow_count++; |
timer0_overflow_count++; |
} |
|
/*#int_default |
66,9 → 74,22 |
// printf("bar_temp[mK] pressure[hPa] Anemo[m/s]check\r\n\r\n"); |
} |
|
void print_slow(char *output, int8 *check) |
{ |
int8 j; // String pointer |
j=0; |
while(output[j]!=0) |
{ |
delay_us(SEND_DELAY); |
putc(output[j]); |
*check^=output[j++]; |
} |
} |
|
|
void main() |
{ |
unsigned int16 seq=0; |
unsigned int16 seq=0; |
|
setup_oscillator(OSC_8MHZ); // pri prouziti bootloaderu neni treba nastavovat |
setup_wdt(WDT_2304MS); |
82,6 → 103,8 |
setup_comparator(NC_NC_NC_NC); // This device COMP currently not supported by the PICWizard |
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_64); |
output_high(CSN_SPI); |
int1 repeat; |
float anemo; |
|
welcome(); // welcome print and device indentification |
|
103,72 → 126,123 |
set_timer1(0); |
timer0_overflow_count=0; |
anemo=0; |
repeat=TRUE; |
|
restart_wdt(); //---WDT |
delay_ms(1000); |
|
while (TRUE) |
{ |
char output[8]; // Output buffer |
int8 j; // String pointer |
int8 check=0; // Checksum is calculated between '$' and '*' |
float SHT_temp1=0,SHT_hum1=0; |
float SHT_temp2=0,SHT_hum2=0; |
float local_temp; |
float barometer_temperature, barometer_pressure; |
do |
{ |
delay_ms(RESPONSE_DELAY); |
//---WDT |
restart_wdt(); |
} while (!kbhit()&&!repeat); |
|
delay_ms(1000); |
{ // printf |
//---WDT |
restart_wdt(); |
|
local_temp = ds1820_read()+27315; |
sht_rd(SHT_temp1,SHT_hum1); |
SHT_temp1 = (SHT_temp1 + 273.15)*100; |
{ // Retrieve command |
char ch='k'; |
|
if(kbhit()) ch=getc(); |
|
switch (ch) |
{ |
case 'i': |
welcome(); // Information about version, etc... |
break; // Only when dome is closed |
|
case 's': |
repeat=FALSE; // Single measure mode |
break; |
|
case 'r': |
repeat=TRUE; // Repeat mode |
break; |
|
case 'u': |
reset_cpu(); // Update firmware |
} |
} |
|
char output[8]; // Output buffer |
int8 check=0; // Checksum is calculated between '$' and '*' |
float SHT_temp1=0,SHT_hum1=0; |
float SHT_temp2=0,SHT_hum2=0; |
float local_temp; |
float barometer_temperature, barometer_pressure; |
float anemo; |
|
|
{ // printf |
|
local_temp = ds1820_read()+27315; |
sht_rd(SHT_temp1,SHT_hum1); |
SHT_temp1 = (SHT_temp1 + 273.15)*100; |
|
SHT_temp2 = SHT25_get_temp(); |
SHT_hum2 = SHT25_get_hum(); |
SHT_temp2 = (SHT_temp2 + 273.15)*100; |
SHT_temp2 = SHT25_get_temp(); |
SHT_hum2 = SHT25_get_hum(); |
SHT_temp2 = (SHT_temp2 + 273.15)*100; |
if (barometer_present == TRUE) |
{ |
barometer_temperature = (MPL_get_temperature() + 273.15)*100; |
barometer_pressure = MPL_get_pressure() * 10.0; // conversion to hectopascals |
} |
else |
{ |
barometer_temperature = 0; |
barometer_pressure = 0; |
} |
|
if (barometer_present == TRUE) |
{ |
barometer_temperature = (MPL_get_temperature() + 273.15)*100; |
barometer_pressure = MPL_get_pressure() * 10.0; // conversion to hectopascals |
} |
else |
{ |
barometer_temperature = 0; |
barometer_pressure = 0; |
} |
|
delay_us(SEND_DELAY); |
putc('$'); |
delay_us(SEND_DELAY); |
sprintf(output,"AWS%s \0",VER); |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
print_slow(output, &check); |
sprintf(output,"%Lu \0", seq); |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
print_slow(output, &check); |
sprintf(output,"%5.0f \0", local_temp ); |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
print_slow(output, &check); |
sprintf(output,"%5.0f \0", SHT_temp1); |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
print_slow(output, &check); |
sprintf(output,"%3.1f \0", SHT_hum1); |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
print_slow(output, &check); |
sprintf(output,"%5.0f \0", SHT_temp2); |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
print_slow(output, &check); |
sprintf(output,"%3.1f \0", SHT_hum2); |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
print_slow(output, &check); |
sprintf(output,"%5.0f \0", barometer_temperature); |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
print_slow(output, &check); |
sprintf(output,"%5.1f \0", barometer_pressure); |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
sprintf(output,"%3.1f \0", anemo); |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
print_slow(output, &check); |
|
//anemo = ((timer0_overflow_count * 0xFF) + get_timer0())/(((timer1_overflow_count * 0xFFFF) + get_timer1())/32768.0); // pulses per second calculation |
//anemo = anemo / 10.5; // frequency divided by anemomether constant. |
sprintf(output,"%3.1f \0", anemo_compute()); |
|
timer0_overflow_count=0; |
timer1_overflow_count=0; |
set_timer0(0); |
set_timer1(0); |
|
print_slow(output, &check); |
//sprintf(output,"%3.1f \0", anemo_max); |
//print_slow(output, &check); |
|
//anemo_max = 0; |
|
sprintf(output,"*%X\r\n\0", check); |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j++]); } |
print_slow(output, &check); |
|
delay_us(SEND_DELAY); |
} |
|
//---WDT |
restart_wdt(); |
seq++; // Increment the number of measurement |
seq++; // Increment the number of measurement |
delay_ms(MEASURE_DELAY); |
} |
} |
|