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