Rev 2781 Rev 2782
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 // DS18B20 sensor connection 13 #define ONE_WIRE_PIN PIN_C7 // DS18B20 sensor connection
14 #include "..\ds1820.c" 14 #include "..\ds1820.c"
15   15  
16 #define sht_data_pin PIN_D0 // SHT11 sensor connection 16 #define sht_data_pin PIN_D0 // SHT11 sensor connection
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 // preassure sensor connection 20 #define CSN_SPI PIN_C2 // preassure sensor connection
21 #include "..\MPL115A1.c" 21 #include "..\MPL115A1.c"
22   22  
-   23 unsigned int16 timer0_overflow_count=0;
-   24 float anemo=0;
-   25  
-   26  
-   27 #int_TIMER1
-   28 void TIMER1_isr(void)
-   29 {
-   30 output_toggle(PIN_D1);
-   31 anemo = ((timer0_overflow_count * 0xFF) + get_timer0())/(32768.0/0xFFFF);
-   32 }
-   33  
-   34 #int_TIMER0
-   35 void TIMER0_isr(void)
-   36 {
-   37 timer0_overflow_count++;
-   38 }
-   39  
-   40  
-   41  
23 void welcome(void) // Welcome message 42 void welcome(void) // Welcome message
24 { 43 {
25 char REV[50]=ID; // Buffer for concatenate of a version string 44 char REV[50]=ID; // Buffer for concatenate of a version string
26   45  
27 if (REV[strlen(REV)-1]=='$') REV[strlen(REV)-1]=0; 46 if (REV[strlen(REV)-1]=='$') REV[strlen(REV)-1]=0;
28 printf("\r\n\r\n# AWS01A %s (C) 2013 www.mlab.cz \r\n",VER); // Welcome message 47 printf("\r\n\r\n# AWS01A %s (C) 2013 www.mlab.cz \r\n",VER); // Welcome message
29 printf("#%s\r\n",&REV[4]); 48 printf("#%s\r\n",&REV[4]);
30 // printf("#\r\n"); 49 // printf("#\r\n");
31 // printf("# commands: h, c, o, l, x, i, r, a, s, u\r\n"); 50 // 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, "); 51 // 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"); 52 // printf("i_nfo, r_epeat, a_uto, s_single, u_pdate\r\n");
34 // printf("#\r\n"); 53 // printf("#\r\n");
35 printf("# ver seq temp[K] hum_temp[K] hum[%%] "); 54 printf("# ver seq temp[K] hum_temp[K] hum[%%] ");
36 printf("bar_temp[K] pressure[hPa] check\r\n\r\n"); 55 printf("bar_temp[K] pressure[hPa] check\r\n\r\n");
37   56  
38 //---WDT 57 //---WDT
39 restart_wdt(); 58 restart_wdt();
40 } 59 }
41   60  
42 void main() 61 void main()
43 { 62 {
44 unsigned int16 seq=0; 63 unsigned int16 seq=0;
45   64  
46 setup_adc_ports(NO_ANALOGS|VSS_VDD); 65 setup_adc_ports(NO_ANALOGS|VSS_VDD);
47 setup_adc(ADC_CLOCK_DIV_2); 66 setup_adc(ADC_CLOCK_DIV_2);
48 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); 67 setup_timer_0(RTCC_EXT_L_TO_H|RTCC_DIV_1);
49 setup_timer_1(T1_DISABLED); 68 setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT);
50 setup_timer_2(T2_DISABLED,0,1); 69 setup_timer_2(T2_DISABLED,0,1);
51 setup_ccp1(CCP_OFF); 70 setup_ccp1(CCP_OFF);
52 setup_comparator(NC_NC_NC_NC); // This device COMP currently not supported by the PICWizard 71 setup_comparator(NC_NC_NC_NC); // This device COMP currently not supported by the PICWizard
53 setup_oscillator(OSC_8MHZ); 72 setup_oscillator(OSC_8MHZ);
-   73 setup_wdt(WDT_1152MS|WDT_DIV_16);
54 setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_64); 74 setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_64);
55 output_high(CSN_SPI); 75 output_high(CSN_SPI);
-   76 enable_interrupts(INT_TIMER1);
-   77 enable_interrupts(INT_TIMER0);
-   78 enable_interrupts(GLOBAL);
-   79  
-   80  
56 delay_ms(100); 81 delay_ms(100);
57   82  
58 welcome(); 83 welcome();
59   84  
60 sht_init(); 85 sht_init();
61 MPL_init(); // get correction coefficients from the sensor 86 MPL_init(); // get correction coefficients from the sensor
62   87  
63 while (TRUE) 88 while (TRUE)
64 { 89 {
65 char output[8]; // Output buffer 90 char output[8]; // Output buffer
66 int8 j; // String pointer 91 int8 j; // String pointer
67 int8 check=0; // Checksum is calculated between '$' and '*' 92 int8 check=0; // Checksum is calculated between '$' and '*'
68 float SHT_temp,SHT_hum; 93 float SHT_temp,SHT_hum;
69 float local_temp; 94 float local_temp;
70 float barometer_temperature, barometer_pressure; 95 float barometer_temperature, barometer_pressure;
71   96  
72 delay_ms(100); 97 delay_ms(100);
73 { // printf 98 { // printf
74   99  
75 sht_rd(SHT_temp,SHT_hum); 100 sht_rd(SHT_temp,SHT_hum);
76 local_temp = ds1820_read()+273.15; 101 local_temp = ds1820_read()+273.15;
77 SHT_temp += 273.15; 102 SHT_temp += 273.15;
78 barometer_temperature = MPL_get_temperature() + 273.15; 103 barometer_temperature = MPL_get_temperature() + 273.15;
79 barometer_pressure = MPL_get_pressure() * 10.0; // conversion to hectopascals 104 barometer_pressure = MPL_get_pressure() * 10.0; // conversion to hectopascals
80 105
81 delay_us(SEND_DELAY); 106 delay_us(SEND_DELAY);
82 putc('$'); 107 putc('$');
83 delay_us(SEND_DELAY); 108 delay_us(SEND_DELAY);
84 sprintf(output,"AWS%s \0",VER); 109 sprintf(output,"AWS%s \0",VER);
85 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } 110 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
86 sprintf(output,"%Lu \0", seq); 111 sprintf(output,"%Lu \0", seq);
87 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } 112 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
88 sprintf(output,"%f \0", local_temp ); 113 sprintf(output,"%f \0", local_temp );
89 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } 114 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
90 sprintf(output,"%f \0", SHT_temp); 115 sprintf(output,"%f \0", SHT_temp);
91 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } 116 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
92 sprintf(output,"%3.1f \0", SHT_hum); 117 sprintf(output,"%3.1f \0", SHT_hum);
93 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } 118 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
94 sprintf(output,"%f \0", barometer_temperature); 119 sprintf(output,"%f \0", barometer_temperature);
95 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } 120 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
96 sprintf(output,"%5.1f \0", barometer_pressure); 121 sprintf(output,"%5.1f \0", barometer_pressure);
97 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; } 122 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
-   123 sprintf(output,"%3.1f \0", anemo);
-   124 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
98 sprintf(output,"*%X\r\n\0", check); 125 sprintf(output,"*%X\r\n\0", check);
99 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j++]); } 126 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j++]); }
100 delay_us(SEND_DELAY); 127 delay_us(SEND_DELAY);
101 } 128 }
102 129
103 //---WDT 130 //---WDT
104 restart_wdt(); 131 restart_wdt();
105 seq++; // Increment the number of measurement 132 seq++; // Increment the number of measurement
106 } 133 }
107 } 134 }
108   135  
109 //#include "dbloader.c" // Space reservation for the BootLoader 136 //#include "dbloader.c" // Space reservation for the BootLoader