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