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 LCD_ENABLE_PIN PIN_E0 //// |
- |
|
10 |
#define LCD_RS_PIN PIN_E1 //// |
- |
|
11 |
#define LCD_RW_PIN PIN_E2 //// |
- |
|
12 |
#define LCD_DATA4 PIN_D4 //// |
- |
|
13 |
#define LCD_DATA5 PIN_D5 //// |
- |
|
14 |
#define LCD_DATA6 PIN_D6 //// |
- |
|
15 |
#define LCD_DATA7 PIN_D7 |
- |
|
16 |
#include <lcd.c> |
- |
|
17 |
*/ |
- |
|
18 |
#define SEND_DELAY 50 // Time between two characters on RS232 |
9 |
#define SEND_DELAY 50 // Time between two characters on RS232 |
19 |
|
10 |
|
20 |
char VER[4]=VERSION; // Buffer for concatenate of a version string |
11 |
char VER[4]=VERSION; // Buffer for concatenate of a version string |
21 |
|
12 |
|
22 |
#define ONE_WIRE_PIN PIN_C7 |
13 |
#define ONE_WIRE_PIN PIN_C7 |
23 |
#include "..\ds1820.c" |
14 |
#include "..\ds1820.c" |
24 |
|
15 |
|
- |
|
16 |
#define sht_data_pin PIN_D0 |
- |
|
17 |
#define sht_clk_pin PIN_D1 |
25 |
#include "..\SHT.c" |
18 |
#include "..\SHT.c" |
26 |
|
19 |
|
- |
|
20 |
#define CSN_SPI PIN_C2 |
- |
|
21 |
#include "..\MPL115A1.c" |
27 |
|
22 |
|
28 |
void welcome(void) // Welcome message |
23 |
void welcome(void) // Welcome message |
29 |
{ |
24 |
{ |
30 |
char REV[50]=ID; // Buffer for concatenate of a version string |
25 |
char REV[50]=ID; // Buffer for concatenate of a version string |
31 |
|
26 |
|
32 |
if (REV[strlen(REV)-1]=='$') REV[strlen(REV)-1]=0; |
27 |
if (REV[strlen(REV)-1]=='$') REV[strlen(REV)-1]=0; |
33 |
printf("\r\n\r\n# Mrakomer %s (C) 2011 UST\r\n",VER); // Welcome message |
28 |
printf("\r\n\r\n# Mrakomer %s (C) 2011 UST\r\n",VER); // Welcome message |
34 |
printf("#%s\r\n",&REV[4]); |
29 |
printf("#%s\r\n",&REV[4]); |
35 |
// printf("#\r\n"); |
30 |
// printf("#\r\n"); |
36 |
// 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"); |
37 |
// printf("# h_eat, c_old, o_pen, l_ock, x_open, "); |
32 |
// printf("# h_eat, c_old, o_pen, l_ock, x_open, "); |
38 |
// 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"); |
39 |
// printf("#\r\n"); |
34 |
// printf("#\r\n"); |
40 |
// 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] "); |
41 |
// 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"); |
42 |
|
37 |
|
43 |
//---WDT |
38 |
//---WDT |
44 |
restart_wdt(); |
39 |
restart_wdt(); |
45 |
} |
40 |
} |
46 |
|
41 |
|
47 |
void main() |
42 |
void main() |
48 |
{ |
43 |
{ |
49 |
unsigned int16 seq=0; |
44 |
unsigned int16 seq=0; |
50 |
|
45 |
|
51 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
46 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
52 |
setup_adc(ADC_CLOCK_DIV_2); |
47 |
setup_adc(ADC_CLOCK_DIV_2); |
53 |
setup_spi(SPI_SS_DISABLED); |
- |
|
54 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
48 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
55 |
setup_timer_1(T1_DISABLED); |
49 |
setup_timer_1(T1_DISABLED); |
56 |
setup_timer_2(T2_DISABLED,0,1); |
50 |
setup_timer_2(T2_DISABLED,0,1); |
57 |
setup_ccp1(CCP_OFF); |
51 |
setup_ccp1(CCP_OFF); |
58 |
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 |
59 |
setup_oscillator(OSC_8MHZ); |
53 |
setup_oscillator(OSC_8MHZ); |
60 |
|
- |
|
- |
|
54 |
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_64); |
- |
|
55 |
output_high(CSN_SPI); |
- |
|
56 |
delay_ms(100); |
61 |
|
57 |
|
62 |
printf("Simple Thermomether\r\n",); |
58 |
printf("Simple Thermomether\r\n",); |
63 |
printf("(c) Kaklik 2013\r\n"); |
59 |
printf("(c) Kaklik 2013\r\n"); |
64 |
printf("www.mlab.cz\r\n"); |
60 |
printf("www.mlab.cz\r\n"); |
65 |
|
61 |
|
66 |
welcome(); |
62 |
welcome(); |
67 |
|
- |
|
68 |
/* lcd_init(); |
- |
|
69 |
lcd_putc("(c) Kaklik 2013"); |
- |
|
70 |
lcd_gotoxy(3,2); |
- |
|
71 |
lcd_putc("www.mlab.cz"); |
- |
|
72 |
Delay_ms(2000); |
- |
|
73 |
*/ |
- |
|
74 |
|
63 |
|
75 |
sht_init(); |
64 |
sht_init(); |
- |
|
65 |
MPL_init(); // get correction coefficients from the sensor |
76 |
|
66 |
|
77 |
while (TRUE) |
67 |
while (TRUE) |
78 |
{ |
68 |
{ |
79 |
char output[8]; // Output buffer |
69 |
char output[8]; // Output buffer |
80 |
int8 j; // String pointer |
70 |
int8 j; // String pointer |
81 |
int8 check=0; // Checksum is calculated between '$' and '*' |
71 |
int8 check=0; // Checksum is calculated between '$' and '*' |
82 |
float SHT_temp,SHT_hum; |
72 |
float SHT_temp,SHT_hum; |
- |
|
73 |
float local_temp; |
- |
|
74 |
float barometer_temperature, barometer_pressure; |
83 |
|
75 |
|
84 |
|
- |
|
85 |
// lcd_gotoxy(1,2); |
- |
|
86 |
// printf(lcd_putc,"T: %f K ",ds1820_read()+273.15); |
- |
|
87 |
|
- |
|
88 |
// printf("$T1.0 %f \r\n",ds1820_read()+273.15); |
- |
|
89 |
delay_ms(100); |
76 |
delay_ms(100); |
90 |
{ // printf |
77 |
{ // printf |
91 |
|
78 |
|
92 |
sht_rd(SHT_temp,SHT_hum); |
79 |
sht_rd(SHT_temp,SHT_hum); |
- |
|
80 |
local_temp = ds1820_read()+273.15; |
- |
|
81 |
SHT_temp += 273.15; |
- |
|
82 |
barometer_temperature = MPL_get_temperature() + 273.15; |
- |
|
83 |
barometer_pressure = MPL_get_pressure() * 10.0; // conversion to hectopascals |
93 |
|
84 |
|
94 |
delay_us(SEND_DELAY); |
85 |
delay_us(SEND_DELAY); |
95 |
putc('$'); |
86 |
putc('$'); |
96 |
delay_us(SEND_DELAY); |
87 |
delay_us(SEND_DELAY); |
97 |
sprintf(output,"AWS%s \0",VER); |
88 |
sprintf(output,"AWS%s \0",VER); |
98 |
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++]; } |
99 |
sprintf(output,"%Lu \0", seq); |
90 |
sprintf(output,"%Lu \0", seq); |
100 |
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++]; } |
101 |
sprintf(output,"%f \0", ds1820_read()+273.15); |
92 |
sprintf(output,"%f \0", local_temp ); |
102 |
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++]; } |
103 |
sprintf(output,"%f \0", SHT_temp + 273.15); |
94 |
sprintf(output,"%f \0", SHT_temp); |
104 |
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++]; } |
105 |
sprintf(output,"%f \0", SHT_hum); |
96 |
sprintf(output,"%3.1f \0", SHT_hum); |
- |
|
97 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
- |
|
98 |
sprintf(output,"%f \0", barometer_temperature); |
- |
|
99 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
- |
|
100 |
sprintf(output,"%5.1f \0", barometer_pressure); |
106 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
101 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
107 |
sprintf(output,"*%X\r\n\0", check); |
102 |
sprintf(output,"*%X\r\n\0", check); |
108 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j++]); } |
103 |
j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j++]); } |
109 |
delay_us(SEND_DELAY); |
104 |
delay_us(SEND_DELAY); |
110 |
} |
105 |
} |
111 |
|
106 |
|
112 |
//---WDT |
107 |
//---WDT |
113 |
restart_wdt(); |
108 |
restart_wdt(); |
114 |
seq++; // Increment the number of measurement |
109 |
seq++; // Increment the number of measurement |
115 |
|
- |
|
116 |
} |
110 |
} |
117 |
|
- |
|
118 |
} |
111 |
} |
119 |
|
112 |
|
120 |
//#include "dbloader.c" // Space reservation for the BootLoader |
113 |
//#include "dbloader.c" // Space reservation for the BootLoader |