| Line 1... |
Line 1... |
| 1 |
/**** Automatic weather station 01A ****/ |
1 |
/**** Automatic weather station 01A ****/ |
| 2 |
#define VERSION "0.1" |
2 |
#define VERSION "0.1" |
| 3 |
#define ID "$Id: main.c 2907 2013-04-13 20:52:25Z kaklik $" |
3 |
#define ID "$Id: main.c 2913 2013-04-14 12:36:15Z kaklik $" |
| 4 |
#include "main.h" |
4 |
#include "main.h" |
| 5 |
#include ".\common\dbloader.h" |
5 |
#include ".\common\dbloader.h" |
| 6 |
#include <string.h> |
6 |
#include <string.h> |
| 7 |
|
7 |
|
| 8 |
#CASE // Case sensitive compiler |
8 |
#CASE // Case sensitive compiler |
| Line 16... |
Line 16... |
| 16 |
|
16 |
|
| 17 |
#define sht_data_pin PIN_D0 // SHT11 sensor connection |
17 |
#define sht_data_pin PIN_D0 // SHT11 sensor connection |
| 18 |
#define sht_clk_pin PIN_D1 |
18 |
#define sht_clk_pin PIN_D1 |
| 19 |
#include "..\SHT.c" |
19 |
#include "..\SHT.c" |
| 20 |
|
20 |
|
| - |
|
21 |
#use i2c(master, sda=PIN_C4, scl=PIN_C3) |
| - |
|
22 |
#include "..\SHT25.h" |
| - |
|
23 |
|
| 21 |
#define CSN_SPI PIN_C2 // preassure sensor connection |
24 |
#define CSN_SPI PIN_C2 // preassure sensor connection |
| 22 |
#include "..\MPL115A1.c" |
25 |
#include "..\MPL115A1.c" |
| 23 |
|
26 |
|
| 24 |
unsigned int16 timer0_overflow_count=0; |
27 |
unsigned int16 timer0_overflow_count=0; |
| 25 |
float anemo=0; |
28 |
float anemo=0; |
| Line 43... |
Line 46... |
| 43 |
void TIMER0_isr(void) |
46 |
void TIMER0_isr(void) |
| 44 |
{ |
47 |
{ |
| 45 |
timer0_overflow_count++; |
48 |
timer0_overflow_count++; |
| 46 |
} |
49 |
} |
| 47 |
|
50 |
|
| 48 |
#int_default |
51 |
/*#int_default |
| 49 |
void default_isr() |
52 |
void default_isr() |
| 50 |
{ |
53 |
{ |
| 51 |
printf("Unexplained interrupt\r\n"); |
54 |
printf("Unexplained interrupt\r\n"); |
| 52 |
} |
55 |
} |
| 53 |
|
56 |
*/ |
| 54 |
void welcome(void) // Welcome message |
57 |
void welcome(void) // Welcome message |
| 55 |
{ |
58 |
{ |
| 56 |
char REV[50]=ID; // Buffer for concatenate of a version string |
59 |
char REV[50]=ID; // Buffer for concatenate of a version string |
| 57 |
|
60 |
|
| 58 |
if (REV[strlen(REV)-1]=='$') REV[strlen(REV)-1]=0; |
61 |
if (REV[strlen(REV)-1]=='$') REV[strlen(REV)-1]=0; |
| 59 |
printf("\r\n\r\n# AWS01A %s (C) 2013 www.mlab.cz \r\n",VER); // Welcome message |
62 |
printf("\r\n\r\n# AWS01A %s (C) 2013 www.mlab.cz \r\n",VER); // Welcome message |
| 60 |
printf("#%s\r\n",&REV[4]); |
63 |
printf("#%s\r\n",&REV[4]); |
| - |
|
64 |
// printf("# ver seq "); |
| 61 |
printf("# ver seq temp[mK] hum_temp[mK] hum[%%] "); |
65 |
// printf("#temp[mK] hum_temp[mK] hum[%%] "); |
| 62 |
printf("bar_temp[mK] pressure[hPa] Anemo[m/s]check\r\n\r\n"); |
66 |
// printf("bar_temp[mK] pressure[hPa] Anemo[m/s]check\r\n\r\n"); |
| 63 |
} |
67 |
} |
| 64 |
|
68 |
|
| 65 |
void main() |
69 |
void main() |
| 66 |
{ |
70 |
{ |
| 67 |
unsigned int16 seq=0; |
71 |
unsigned int16 seq=0; |
| Line 71... |
Line 75... |
| 71 |
restart_wdt(); //---WDT |
75 |
restart_wdt(); //---WDT |
| 72 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
76 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
| 73 |
setup_adc(ADC_CLOCK_DIV_2); |
77 |
setup_adc(ADC_CLOCK_DIV_2); |
| 74 |
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); |
78 |
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); |
| 75 |
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT); |
79 |
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT); |
| 76 |
// setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); |
- |
|
| 77 |
setup_timer_2(T2_DISABLED,0,1); |
80 |
setup_timer_2(T2_DISABLED,0,1); |
| 78 |
setup_ccp1(CCP_OFF); |
81 |
setup_ccp1(CCP_OFF); |
| 79 |
setup_comparator(NC_NC_NC_NC); // This device COMP currently not supported by the PICWizard |
82 |
setup_comparator(NC_NC_NC_NC); // This device COMP currently not supported by the PICWizard |
| 80 |
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_64); |
83 |
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_64); |
| 81 |
output_high(CSN_SPI); |
84 |
output_high(CSN_SPI); |
| Line 89... |
Line 92... |
| 89 |
restart_wdt(); //---WDT |
92 |
restart_wdt(); //---WDT |
| 90 |
|
93 |
|
| 91 |
sht_init(); |
94 |
sht_init(); |
| 92 |
barometer_present = MPL_init(); // get correction coefficients from the sensor |
95 |
barometer_present = MPL_init(); // get correction coefficients from the sensor |
| 93 |
|
96 |
|
| - |
|
97 |
SHT25_soft_reset(); |
| - |
|
98 |
|
| 94 |
restart_wdt(); //---WDT |
99 |
restart_wdt(); //---WDT |
| 95 |
|
100 |
|
| 96 |
while (TRUE) |
101 |
while (TRUE) |
| 97 |
{ |
102 |
{ |
| 98 |
char output[8]; // Output buffer |
103 |
char output[8]; // Output buffer |
| Line 108... |
Line 113... |
| 108 |
|
113 |
|
| 109 |
local_temp = ds1820_read()+27315; |
114 |
local_temp = ds1820_read()+27315; |
| 110 |
sht_rd(SHT_temp1,SHT_hum1); |
115 |
sht_rd(SHT_temp1,SHT_hum1); |
| 111 |
SHT_temp1 = (SHT_temp1 + 273.15)*100; |
116 |
SHT_temp1 = (SHT_temp1 + 273.15)*100; |
| 112 |
|
117 |
|
| - |
|
118 |
SHT_temp2 = SHT25_get_temp(); |
| - |
|
119 |
SHT_hum2 = SHT25_get_hum(); |
| - |
|
120 |
|
| 113 |
if (barometer_present == TRUE) |
121 |
if (barometer_present == TRUE) |
| 114 |
{ |
122 |
{ |
| 115 |
barometer_temperature = (MPL_get_temperature() + 273.15)*100; |
123 |
barometer_temperature = (MPL_get_temperature() + 273.15)*100; |
| 116 |
barometer_pressure = MPL_get_pressure() * 10.0; // conversion to hectopascals |
124 |
barometer_pressure = MPL_get_pressure() * 10.0; // conversion to hectopascals |
| 117 |
} |
125 |
} |