1 |
/**** Automatic weather station 01A ****/ |
1 |
/**** Automatic weather station 01A ****/ |
2 |
#define VERSION "0.1" |
2 |
#define VERSION "0.1" |
3 |
#define ID "$Id: irmrak4.c 2177 2011-09-05 18:56:16Z kaklik $" |
3 |
#define ID "$Id: irmrak4.c 2177 2011-09-05 18:56:16Z kaklik $" |
4 |
#include "main.h" |
4 |
#include "main.h" |
5 |
#include <string.h> |
5 |
#include <string.h> |
6 |
|
6 |
|
7 |
#CASE // Case sensitive compiler |
7 |
#CASE // Case sensitive compiler |
8 |
|
8 |
|
9 |
#define SEND_DELAY 50 // Time between two characters on RS232 |
9 |
#define SEND_DELAY 50 // Time between two characters on RS232 |
10 |
|
10 |
|
11 |
char VER[4]=VERSION; // Buffer for concatenate of a version string |
11 |
char VER[4]=VERSION; // Buffer for concatenate of a version string |
12 |
|
12 |
|
13 |
#define ONE_WIRE_PIN PIN_C7 |
13 |
#define ONE_WIRE_PIN PIN_C7 |
14 |
#include "..\ds1820.c" |
14 |
#include "..\ds1820.c" |
15 |
|
15 |
|
16 |
#define sht_data_pin PIN_D0 |
16 |
#define sht_data_pin PIN_D0 |
17 |
#define sht_clk_pin PIN_D1 |
17 |
#define sht_clk_pin PIN_D1 |
18 |
#include "..\SHT.c" |
18 |
#include "..\SHT.c" |
19 |
|
19 |
|
20 |
#define CSN_SPI PIN_C2 |
20 |
#define CSN_SPI PIN_C2 |
21 |
#include "..\MPL115A1.c" |
21 |
#include "..\MPL115A1.c" |
22 |
|
22 |
|
23 |
void welcome(void) // Welcome message |
23 |
void welcome(void) // Welcome message |
24 |
{ |
24 |
{ |
25 |
char REV[50]=ID; // Buffer for concatenate of a version string |
25 |
char REV[50]=ID; // Buffer for concatenate of a version string |
26 |
|
26 |
|
27 |
if (REV[strlen(REV)-1]=='$') REV[strlen(REV)-1]=0; |
27 |
if (REV[strlen(REV)-1]=='$') REV[strlen(REV)-1]=0; |
28 |
printf("\r\n\r\n# Mrakomer %s (C) 2011 UST\r\n",VER); // Welcome message |
28 |
printf("\r\n\r\n# AWS01A %s (C) 2013 www.mlab.cz \r\n",VER); // Welcome message |
29 |
printf("#%s\r\n",&REV[4]); |
29 |
printf("#%s\r\n",&REV[4]); |
30 |
// printf("#\r\n"); |
30 |
// printf("#\r\n"); |
31 |
// printf("# commands: h, c, o, l, x, i, r, a, s, u\r\n"); |
31 |
// printf("# commands: h, c, o, l, x, i, r, a, s, u\r\n"); |
32 |
// printf("# h_eat, c_old, o_pen, l_ock, x_open, "); |
32 |
// printf("# h_eat, c_old, o_pen, l_ock, x_open, "); |
33 |
// printf("i_nfo, r_epeat, a_uto, s_single, u_pdate\r\n"); |
33 |
// printf("i_nfo, r_epeat, a_uto, s_single, u_pdate\r\n"); |
34 |
// printf("#\r\n"); |
34 |
// printf("#\r\n"); |
35 |
// printf("# ver seq in[1/100 C] sky[1/100 C] sky[1/100 C] "); |
35 |
// printf("# ver seq in[1/100 C] sky[1/100 C] sky[1/100 C] "); |
36 |
// printf("out[1/100 C] heat[s] dome[s] check\r\n\r\n"); |
36 |
// printf("out[1/100 C] heat[s] dome[s] check\r\n\r\n"); |
37 |
|
37 |
|
38 |
//---WDT |
38 |
//---WDT |
39 |
restart_wdt(); |
39 |
restart_wdt(); |
40 |
} |
40 |
} |
41 |
|
41 |
|
42 |
void main() |
42 |
void main() |
43 |
{ |
43 |
{ |
44 |
unsigned int16 seq=0; |
44 |
unsigned int16 seq=0; |
45 |
|
45 |
|
46 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
46 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
47 |
setup_adc(ADC_CLOCK_DIV_2); |
47 |
setup_adc(ADC_CLOCK_DIV_2); |
48 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
48 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
49 |
setup_timer_1(T1_DISABLED); |
49 |
setup_timer_1(T1_DISABLED); |
50 |
setup_timer_2(T2_DISABLED,0,1); |
50 |
setup_timer_2(T2_DISABLED,0,1); |
51 |
setup_ccp1(CCP_OFF); |
51 |
setup_ccp1(CCP_OFF); |
52 |
setup_comparator(NC_NC_NC_NC); // This device COMP currently not supported by the PICWizard |
52 |
setup_comparator(NC_NC_NC_NC); // This device COMP currently not supported by the PICWizard |
53 |
setup_oscillator(OSC_8MHZ); |
53 |
setup_oscillator(OSC_8MHZ); |
54 |
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_64); |
54 |
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_64); |
55 |
output_high(CSN_SPI); |
55 |
output_high(CSN_SPI); |
56 |
delay_ms(100); |
56 |
delay_ms(100); |
57 |
|
57 |
|
58 |
printf("Simple Thermomether\r\n",); |
- |
|
59 |
printf("(c) Kaklik 2013\r\n"); |
- |
|
60 |
printf("www.mlab.cz\r\n"); |
- |
|
61 |
|
- |
|
62 |
welcome(); |
58 |
welcome(); |
63 |
|
59 |
|
64 |
sht_init(); |
60 |
sht_init(); |
65 |
MPL_init(); // get correction coefficients from the sensor |
61 |
MPL_init(); // get correction coefficients from the sensor |
66 |
|
62 |
|
67 |
while (TRUE) |
63 |
while (TRUE) |
68 |
{ |
64 |
{ |
69 |
char output[8]; // Output buffer |
65 |
char output[8]; // Output buffer |
70 |
int8 j; // String pointer |
66 |
int8 j; // String pointer |
71 |
int8 check=0; // Checksum is calculated between '$' and '*' |
67 |
int8 check=0; // Checksum is calculated between '$' and '*' |
72 |
float SHT_temp,SHT_hum; |
68 |
float SHT_temp,SHT_hum; |
73 |
float local_temp; |
69 |
float local_temp; |
74 |
float barometer_temperature, barometer_pressure; |
70 |
float barometer_temperature, barometer_pressure; |
75 |
|
71 |
|
76 |
delay_ms(100); |
72 |
delay_ms(100); |
77 |
{ // printf |
73 |
{ // printf |
78 |
|
74 |
|
79 |
sht_rd(SHT_temp,SHT_hum); |
75 |
sht_rd(SHT_temp,SHT_hum); |
80 |
local_temp = ds1820_read()+273.15; |
76 |
local_temp = ds1820_read()+273.15; |
81 |
SHT_temp += 273.15; |
77 |
SHT_temp += 273.15; |
82 |
barometer_temperature = MPL_get_temperature() + 273.15; |
78 |
barometer_temperature = MPL_get_temperature() + 273.15; |
83 |
barometer_pressure = MPL_get_pressure() * 10.0; // conversion to hectopascals |
79 |
barometer_pressure = MPL_get_pressure() * 10.0; // conversion to hectopascals |
84 |
|
80 |
|
85 |
delay_us(SEND_DELAY); |
81 |
delay_us(SEND_DELAY); |
86 |
putc('$'); |
82 |
putc('$'); |
87 |
delay_us(SEND_DELAY); |
83 |
delay_us(SEND_DELAY); |
88 |
sprintf(output,"AWS%s \0",VER); |
84 |
sprintf(output,"AWS%s \0",VER); |
89 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
85 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
90 |
sprintf(output,"%Lu \0", seq); |
86 |
sprintf(output,"%Lu \0", seq); |
91 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
87 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
92 |
sprintf(output,"%f \0", local_temp ); |
88 |
sprintf(output,"%f \0", local_temp ); |
93 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
89 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
94 |
sprintf(output,"%f \0", SHT_temp); |
90 |
sprintf(output,"%f \0", SHT_temp); |
95 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
91 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
96 |
sprintf(output,"%3.1f \0", SHT_hum); |
92 |
sprintf(output,"%3.1f \0", SHT_hum); |
97 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
93 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
98 |
sprintf(output,"%f \0", barometer_temperature); |
94 |
sprintf(output,"%f \0", barometer_temperature); |
99 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
95 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
100 |
sprintf(output,"%5.1f \0", barometer_pressure); |
96 |
sprintf(output,"%5.1f \0", barometer_pressure); |
101 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
97 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
102 |
sprintf(output,"*%X\r\n\0", check); |
98 |
sprintf(output,"*%X\r\n\0", check); |
103 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j++]); } |
99 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j++]); } |
104 |
delay_us(SEND_DELAY); |
100 |
delay_us(SEND_DELAY); |
105 |
} |
101 |
} |
106 |
|
102 |
|
107 |
//---WDT |
103 |
//---WDT |
108 |
restart_wdt(); |
104 |
restart_wdt(); |
109 |
seq++; // Increment the number of measurement |
105 |
seq++; // Increment the number of measurement |
110 |
} |
106 |
} |
111 |
} |
107 |
} |
112 |
|
108 |
|
113 |
//#include "dbloader.c" // Space reservation for the BootLoader |
109 |
//#include "dbloader.c" // Space reservation for the BootLoader |