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 2899 2013-04-11 22:07:54Z kaklik $" |
3 |
#define ID "$Id: main.c 2907 2013-04-13 20:52:25Z 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 22... |
Line 22... |
22 |
#include "..\MPL115A1.c" |
22 |
#include "..\MPL115A1.c" |
23 |
|
23 |
|
24 |
unsigned int16 timer0_overflow_count=0; |
24 |
unsigned int16 timer0_overflow_count=0; |
25 |
float anemo=0; |
25 |
float anemo=0; |
26 |
|
26 |
|
- |
|
27 |
int1 barometer_present; |
27 |
|
28 |
|
28 |
#int_TIMER1 |
29 |
#int_TIMER1 |
29 |
void TIMER1_isr(void) |
30 |
void TIMER1_isr(void) |
30 |
{ |
31 |
{ |
31 |
output_toggle(PIN_E0); |
32 |
// wind speed calculation 32.768 kHz crystal on timer1 oscilator expected. |
- |
|
33 |
anemo = ((timer0_overflow_count * 0xFF) + get_timer0())/(32768.0/0xFFFF); // pulses per second calculation |
32 |
set_timer1(0); |
34 |
anemo = anemo / 10.5; // frequency divided by anemomether constant. |
33 |
|
35 |
|
34 |
// anemo = ((timer0_overflow_count * 0xFF) + get_timer0())/(32768.0/0xFFFF); |
- |
|
35 |
// timer0_overflow_count=0; |
36 |
timer0_overflow_count=0; |
36 |
// set_timer0(0); |
37 |
set_timer0(0); |
- |
|
38 |
set_timer1(0); |
- |
|
39 |
output_toggle(PIN_E0); |
37 |
} |
40 |
} |
38 |
|
41 |
|
39 |
#int_TIMER0 |
42 |
#int_TIMER0 |
40 |
void TIMER0_isr(void) |
43 |
void TIMER0_isr(void) |
41 |
{ |
44 |
{ |
42 |
timer0_overflow_count++; |
45 |
timer0_overflow_count++; |
43 |
} |
46 |
} |
44 |
|
47 |
|
45 |
#int_default |
48 |
#int_default |
46 |
default_isr() |
49 |
void default_isr() |
47 |
{ |
50 |
{ |
48 |
|
- |
|
49 |
printf("Unexplained interrupt\r\n"); |
51 |
printf("Unexplained interrupt\r\n"); |
50 |
|
- |
|
51 |
} |
52 |
} |
52 |
|
53 |
|
53 |
void welcome(void) // Welcome message |
54 |
void welcome(void) // Welcome message |
54 |
{ |
55 |
{ |
55 |
char REV[50]=ID; // Buffer for concatenate of a version string |
56 |
char REV[50]=ID; // Buffer for concatenate of a version string |
56 |
|
57 |
|
57 |
if (REV[strlen(REV)-1]=='$') REV[strlen(REV)-1]=0; |
58 |
if (REV[strlen(REV)-1]=='$') REV[strlen(REV)-1]=0; |
58 |
printf("\r\n\r\n# AWS01A %s (C) 2013 www.mlab.cz \r\n",VER); // Welcome message |
59 |
printf("\r\n\r\n# AWS01A %s (C) 2013 www.mlab.cz \r\n",VER); // Welcome message |
59 |
printf("#%s\r\n",&REV[4]); |
60 |
printf("#%s\r\n",&REV[4]); |
60 |
printf("# ver seq temp[mK] hum_temp[mK] hum[%%] "); |
61 |
printf("# ver seq temp[mK] hum_temp[mK] hum[%%] "); |
61 |
printf("bar_temp[mK] pressure[hPa] Anemo[pls/s]check\r\n\r\n"); |
62 |
printf("bar_temp[mK] pressure[hPa] Anemo[m/s]check\r\n\r\n"); |
62 |
} |
63 |
} |
63 |
|
64 |
|
64 |
void main() |
65 |
void main() |
65 |
{ |
66 |
{ |
66 |
unsigned int16 seq=0; |
67 |
unsigned int16 seq=0; |
Line 69... |
Line 70... |
69 |
setup_wdt(WDT_2304MS); |
70 |
setup_wdt(WDT_2304MS); |
70 |
restart_wdt(); //---WDT |
71 |
restart_wdt(); //---WDT |
71 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
72 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
72 |
setup_adc(ADC_CLOCK_DIV_2); |
73 |
setup_adc(ADC_CLOCK_DIV_2); |
73 |
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); |
74 |
setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1); |
74 |
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1);//|T1_CLK_OUT); |
75 |
setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT); |
75 |
// setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); |
76 |
// setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); |
76 |
setup_timer_2(T2_DISABLED,0,1); |
77 |
setup_timer_2(T2_DISABLED,0,1); |
77 |
setup_ccp1(CCP_OFF); |
78 |
setup_ccp1(CCP_OFF); |
78 |
setup_comparator(NC_NC_NC_NC); // This device COMP currently not supported by the PICWizard |
79 |
setup_comparator(NC_NC_NC_NC); // This device COMP currently not supported by the PICWizard |
79 |
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_64); |
80 |
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_64); |
80 |
output_high(CSN_SPI); |
81 |
output_high(CSN_SPI); |
81 |
|
82 |
|
82 |
welcome(); // welcome print and device indentification |
83 |
welcome(); // welcome print and device indentification |
83 |
output_low(PIN_E1); |
- |
|
84 |
|
84 |
|
85 |
enable_interrupts(INT_TIMER1); // interrupts used for anemometer readings |
85 |
enable_interrupts(INT_TIMER1); // interrupts used for anemometer readings |
86 |
enable_interrupts(INT_TIMER0); |
86 |
enable_interrupts(INT_TIMER0); |
87 |
// disable_interrupts(INT_RDA); |
- |
|
88 |
enable_interrupts(GLOBAL); |
87 |
enable_interrupts(GLOBAL); |
89 |
output_high(PIN_E1); |
- |
|
90 |
|
88 |
|
91 |
restart_wdt(); //---WDT |
89 |
restart_wdt(); //---WDT |
92 |
|
90 |
|
93 |
sht_init(); |
91 |
sht_init(); |
94 |
MPL_init(); // get correction coefficients from the sensor |
92 |
barometer_present = MPL_init(); // get correction coefficients from the sensor |
95 |
|
93 |
|
96 |
restart_wdt(); //---WDT |
94 |
restart_wdt(); //---WDT |
97 |
|
95 |
|
98 |
while (TRUE) |
96 |
while (TRUE) |
99 |
{ |
97 |
{ |
100 |
char output[8]; // Output buffer |
98 |
char output[8]; // Output buffer |
101 |
int8 j; // String pointer |
99 |
int8 j; // String pointer |
102 |
int8 check=0; // Checksum is calculated between '$' and '*' |
100 |
int8 check=0; // Checksum is calculated between '$' and '*' |
- |
|
101 |
float SHT_temp1=0,SHT_hum1=0; |
103 |
float SHT_temp=0,SHT_hum=0; |
102 |
float SHT_temp2=0,SHT_hum2=0; |
104 |
float local_temp; |
103 |
float local_temp; |
105 |
float barometer_temperature, barometer_pressure; |
104 |
float barometer_temperature, barometer_pressure; |
106 |
|
105 |
|
107 |
delay_ms(1000); |
106 |
delay_ms(1000); |
108 |
{ // printf |
107 |
{ // printf |
109 |
|
108 |
|
110 |
local_temp = ds1820_read()+27315; |
109 |
local_temp = ds1820_read()+27315; |
111 |
sht_rd(SHT_temp,SHT_hum); |
110 |
sht_rd(SHT_temp1,SHT_hum1); |
112 |
SHT_temp = (SHT_temp + 273.15)*100; |
111 |
SHT_temp1 = (SHT_temp1 + 273.15)*100; |
- |
|
112 |
|
- |
|
113 |
if (barometer_present == TRUE) |
- |
|
114 |
{ |
113 |
barometer_temperature = (MPL_get_temperature() + 273.15)*100; |
115 |
barometer_temperature = (MPL_get_temperature() + 273.15)*100; |
114 |
barometer_pressure = MPL_get_pressure() * 10.0; // conversion to hectopascals |
116 |
barometer_pressure = MPL_get_pressure() * 10.0; // conversion to hectopascals |
- |
|
117 |
} |
- |
|
118 |
else |
- |
|
119 |
{ |
- |
|
120 |
barometer_temperature = 0; |
- |
|
121 |
barometer_pressure = 0; |
- |
|
122 |
} |
115 |
|
123 |
|
116 |
delay_us(SEND_DELAY); |
124 |
delay_us(SEND_DELAY); |
117 |
putc('$'); |
125 |
putc('$'); |
118 |
delay_us(SEND_DELAY); |
126 |
delay_us(SEND_DELAY); |
119 |
sprintf(output,"AWS%s \0",VER); |
127 |
sprintf(output,"AWS%s \0",VER); |
120 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
128 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
121 |
sprintf(output,"%Lu \0", seq); |
129 |
sprintf(output,"%Lu \0", seq); |
122 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
130 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
123 |
sprintf(output,"%5.0f \0", local_temp ); |
131 |
sprintf(output,"%5.0f \0", local_temp ); |
124 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
132 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
125 |
sprintf(output,"%5.0f \0", SHT_temp); |
133 |
sprintf(output,"%5.0f \0", SHT_temp1); |
126 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
134 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
127 |
sprintf(output,"%3.1f \0", SHT_hum); |
135 |
sprintf(output,"%3.1f \0", SHT_hum1); |
- |
|
136 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
- |
|
137 |
sprintf(output,"%5.0f \0", SHT_temp2); |
- |
|
138 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
- |
|
139 |
sprintf(output,"%3.1f \0", SHT_hum2); |
128 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
140 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
129 |
sprintf(output,"%5.0f \0", barometer_temperature); |
141 |
sprintf(output,"%5.0f \0", barometer_temperature); |
130 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
142 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
131 |
sprintf(output,"%5.1f \0", barometer_pressure); |
143 |
sprintf(output,"%5.1f \0", barometer_pressure); |
132 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
144 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
Line 134... |
Line 146... |
134 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
146 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
135 |
sprintf(output,"*%X\r\n\0", check); |
147 |
sprintf(output,"*%X\r\n\0", check); |
136 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j++]); } |
148 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j++]); } |
137 |
delay_us(SEND_DELAY); |
149 |
delay_us(SEND_DELAY); |
138 |
} |
150 |
} |
139 |
// output_toggle(PIN_E0); |
- |
|
- |
|
151 |
|
140 |
//---WDT |
152 |
//---WDT |
141 |
restart_wdt(); |
153 |
restart_wdt(); |
142 |
seq++; // Increment the number of measurement |
154 |
seq++; // Increment the number of measurement |
143 |
} |
155 |
} |
144 |
} |
156 |
} |