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