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