Rev Author Line No. Line
1045 jacho 1 //#include "C:\Users\Honza\Documents\pic\meteo_stanice\main.h"
2  
3 //Meteorologicka cast
4 #define VERSION "0.1"
5 #define AUTOR "Jan Chroust"
6 #define DATE "15.4.2013"
7  
8 #include <math.h>
9 #include <string.h>
10  
11  
12  
13 //set I2C
14 #define PIN_SDA PIN_B0
15 #define PIN_SCL PIN_B1
16 #use i2c(master, sda=PIN_SDA, scl=PIN_SCL)
17 //set RS232
18 #use rs232(baud=9600,parity=N,xmit=PIN_B3,rcv=PIN_B2,bits=8) //rcv TXD xmit RXD
19  
20  
21  
22 #include "main.h"
23 #include "SHT25.h"
24 #include "MPL3115.h"
25 #define SEND_DELAY 50 // Cas mezi dvema znaky na RS232
26  
27  
28 char VER[4]=VERSION; // Ulozeni verze do retezce
29  
30 void uvitani(void) // uvodni zprava
31 {
32 printf("\r\n\r\n# Meteorologicka stanice %s (C) 2013 www.mlab.cz \r\n",VERSION);
33 printf("\r\n# Autor: %s Posledni uprava: %s \r\n",AUTOR, DATE);// Welcome message
34 printf("# ver poradi ");
35 printf("altimet_t[°C] altimet_a[m] altimet_p[Pa] ");
36 printf("sht_t[°C] sht_h[%%] Anemo[m/s]check\r\n\r\n");
37 }
38  
39 void main ()
40 {
41 setup_adc_ports(NO_ANALOGS|VSS_VDD);
42 setup_adc(ADC_CLOCK_DIV_2);
43 setup_spi(SPI_SS_DISABLED);
44 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
45 setup_timer_1(T1_DISABLED);
46 setup_timer_2(T2_DISABLED,0,1);
47 setup_ccp1(CCP_OFF);
48 setup_comparator(NC_NC_NC_NC);
49  
50 float altimet_t; //teplota z MPL3115
51 float altimet_p; //tlak z MPL3115
52 float altimet_a; //vyska z MPL3115
53 float sht25_t; //teplota z SHT25
54 float sht25_h; //relativni vlhkost z SHT25
55  
56 unsigned int16 poradi=0; //cislo vzorku
57 //sht_config = SHT25_RH12_T14 | SHT25_HEATER_OFF; //vypnuti topeni v SHT25
58 uvitani();
59  
60  
61 while(TRUE)
62 {
63 char output[12]; // vystupni zasobnik
64 int8 j; // ukazatel na retezec
65 int8 check=0; // Checksum is calculated between '$' and '*'
66 unsigned int sht_config;
67  
68 mpl3115_setP(); //nastaveni pro tlak a teplotu
69 delay_ms (500);
70 altimet_t=mpl3115_T();
71 altimet_p=mpl3115_P();
72  
73 mpl3115_setA(); //nastaveni pro vysku a teplotu
74 delay_ms (500);
75 altimet_a=mpl3115_A();
76  
77  
78  
79 //SHT25_setup(sht_config),sht_config);
80  
81  
82  
83 sht25_t=SHT25_get_temp();
84 sht25_h=SHT25_get_hum();
85  
86  
87 delay_us(SEND_DELAY);
88 putc('$');
89 delay_us(SEND_DELAY);
90 sprintf(output,"MST%s \0",VER);
91 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
92 sprintf(output,"%4.0Lu \0", poradi);
93 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
94 sprintf(output,"%3.2f \0", altimet_t );
95 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
96 sprintf(output,"%5.2f \0", altimet_a);
97 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
98 sprintf(output,"%6.2f \0", altimet_p);
99 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
100 sprintf(output,"%5.2f \0", sht25_t);
101 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
102 sprintf(output,"%3.2f \0", sht25_h);
103 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
104 sprintf(output,"%5.0f \0", altimet_t);
105 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
106 sprintf(output,"%5.1f \0", altimet_t);
107 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
108 sprintf(output,"%3.1f \0", altimet_t);
109 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j]); check^=output[j++]; }
110 sprintf(output,"*%X\r\n\0", check);
111 j=0; while(output[j]!=0) { delay_us(SEND_DELAY); putc(output[j++]); }
112 delay_us(SEND_DELAY);
113  
114 poradi++;
115  
116  
117  
118  
119  
120  
121  
122  
123 }
124  
125  
126 }