1 |
/**** IR Mrakomer 4 ****/ |
1 |
/**** IR Mrakomer 4 ****/ |
2 |
#define VERSION "4.1" |
2 |
#define VERSION "4.1" |
3 |
#define ID "$Id: irmrak4.c 1703 2010-12-05 12:43:15Z kakl $" |
3 |
#define ID "$Id: irmrak4.c 1705 2010-12-05 19:24:34Z kakl $" |
4 |
|
4 |
|
5 |
#include "irmrak4.h" |
5 |
#include "irmrak4.h" |
6 |
#include <TOUCH.C> |
- |
|
7 |
|
6 |
|
8 |
#bit CREN = 0x18.4 // USART registers |
7 |
#bit CREN = 0x18.4 // USART registers |
9 |
#bit SPEN = 0x18.7 |
8 |
#bit SPEN = 0x18.7 |
10 |
#bit OERR = 0x18.1 |
9 |
#bit OERR = 0x18.1 |
11 |
#bit FERR = 0x18.2 |
10 |
#bit FERR = 0x18.2 |
12 |
|
11 |
|
13 |
#include <string.h> |
12 |
#include <string.h> |
14 |
|
13 |
|
15 |
#CASE // Case sensitive compiler |
14 |
#CASE // Case sensitive compiler |
16 |
|
15 |
|
17 |
#define MAXHEAT 20 // Number of cycles for heating |
16 |
#define MAXHEAT 20 // Number of cycles for heating |
18 |
#define MAXOPEN 20 // Number of cycles for dome open |
17 |
#define MAXOPEN 20 // Number of cycles for dome open |
19 |
#define MEASURE_DELAY 6000 // Delay to a next measurement |
18 |
#define MEASURE_DELAY 6000 // Delay to a next measurement |
20 |
#define RESPONSE_DELAY 100 // Reaction time after receiving a command |
19 |
#define RESPONSE_DELAY 100 // Reaction time after receiving a command |
21 |
#define SAFETY_COUNT 90 // Time of one emergency cycle |
20 |
#define SAFETY_COUNT 90 // Time of one emergency cycle |
22 |
#define SEND_DELAY 50 // Time between two characters on RS232 |
21 |
#define SEND_DELAY 50 // Time between two characters on RS232 |
23 |
#define ERROR -32000 // Error flag |
- |
|
24 |
|
22 |
|
25 |
#define DOME PIN_B4 // Dome controll port |
23 |
#define DOME PIN_B4 // Dome controll port |
26 |
#define HEATING PIN_B3 // Heating for defrosting |
24 |
#define HEATING PIN_B3 // Heating for defrosting |
27 |
|
25 |
|
28 |
|
26 |
|
29 |
char VER[4]=VERSION; // Buffer for concatenate of a version string |
27 |
char VER[4]=VERSION; // Buffer for concatenate of a version string |
30 |
|
28 |
|
31 |
int8 heat; // Status variables |
29 |
int8 heat; // Status variables |
32 |
int8 open; |
30 |
int8 open; |
33 |
|
31 |
|
34 |
inline void toggle_dome(void) // Wire exercise |
32 |
inline void toggle_dome(void) // Wire exercise |
35 |
{ |
33 |
{ |
36 |
if (open>0) |
34 |
if (open>0) |
37 |
{output_toggle(DOME);} // Toggle = Open Dome |
35 |
{output_toggle(DOME);} // Toggle = Open Dome |
38 |
else |
36 |
else |
39 |
{output_high(DOME);} // Do not toggle = Close Dome |
37 |
{output_high(DOME);} // Do not toggle = Close Dome |
40 |
} |
38 |
} |
41 |
|
39 |
|
42 |
void delay(int16 cycles) // Wire exercise with delay |
40 |
void delay(int16 cycles) // Wire exercise with delay |
43 |
{ |
41 |
{ |
44 |
int16 i; |
42 |
int16 i; |
45 |
|
43 |
|
46 |
for(i=0; i<cycles; i++) {toggle_dome(); delay_us(100);} |
44 |
for(i=0; i<cycles; i++) {toggle_dome(); delay_us(100);} |
47 |
} |
45 |
} |
48 |
|
46 |
|
49 |
void welcome(void) // Welcome message |
47 |
void welcome(void) // Welcome message |
50 |
{ |
48 |
{ |
51 |
char REV[50]=ID; // Buffer for concatenate of a version string |
49 |
char REV[50]=ID; // Buffer for concatenate of a version string |
52 |
|
50 |
|
53 |
if (REV[strlen(REV)-1]=='$') REV[strlen(REV)-1]=0; |
51 |
if (REV[strlen(REV)-1]=='$') REV[strlen(REV)-1]=0; |
54 |
printf("\n\r\n\r# Mrakomer %s (C) 2007 KAKL\n\r",VER); // Welcome message |
52 |
printf("\r\n\r\n# Mrakomer %s (C) 2007 UST\n\r",VER); // Welcome message |
55 |
printf("#%s\n\r",&REV[4]); |
53 |
printf("#%s\r\n",&REV[4]); |
56 |
printf("#\n\r"); |
54 |
printf("#\r\n"); |
57 |
printf("# h - Switch On Heating for 20s.\n\r"); |
- |
|
58 |
printf("# c - Need Colder. Switch Off Heating.\n\r"); |
- |
|
59 |
printf("# o - Open the Dome for 20s.\n\r"); |
- |
|
60 |
printf("# l - Lock the Dome.\n\r"); |
55 |
printf("# commands:\r\n"); |
61 |
printf("# x - Open the Dome and switch On Heating.\n\r"); |
- |
|
62 |
printf("# i - Print this Information.\n\r"); |
56 |
printf("# h_eat, c_old, o_pen, l_ock, x_open, "); |
63 |
printf("# r - Repeat measure every second.\n\r"); |
57 |
printf("i_nfo, r_epeat, a_uto, s_single, u_pdate\r\n"); |
64 |
printf("# s - Single measure.\n\r"); |
- |
|
65 |
printf("# u - Update firmware. Go to the Boot Loader.\n\r"); |
- |
|
66 |
printf("#\n\r"); |
58 |
printf("#\r\n"); |
67 |
printf("# <ver> <sequence> <inside[1/100 C]> <sky[1/100 C]> <sky[1/100 C]> "); |
59 |
printf("# <ver> <sequence> <inside[1/100 C]> <sky[1/100 C]> <sky[1/100 C]> "); |
68 |
printf("<ambient[1/100 C]> <heating[s]> <dome[s]> <check>\n\r\n\r"); |
60 |
printf("<ambient[1/100 C]> <heating[s]> <dome[s]> <check>\r\n\r\n"); |
- |
|
61 |
|
69 |
//---WDT |
62 |
//---WDT |
70 |
restart_wdt(); |
63 |
restart_wdt(); |
71 |
} |
64 |
} |
72 |
|
65 |
|
73 |
|
66 |
|
74 |
#include "smb.c" // System Management Bus driver |
67 |
#include "smb.c" // System Management Bus driver |
- |
|
68 |
#include "TOUCH.C" |
75 |
|
69 |
|
76 |
|
70 |
|
77 |
// Read sensor's RAM |
71 |
// Read sensor's RAM |
78 |
// Returns temperature in °K |
72 |
// Returns temperature in °K |
79 |
int16 ReadTemp(int8 addr, int8 select) |
73 |
int16 ReadTemp(int8 addr, int8 select) |
80 |
{ |
74 |
{ |
81 |
unsigned char arr[6]; // Buffer for the sent bytes |
75 |
unsigned char arr[6]; // Buffer for the sent bytes |
82 |
int8 crc; // Readed CRC |
76 |
int8 crc; // Readed CRC |
83 |
int16 temp; // Readed temperature |
77 |
int16 temp; // Readed temperature |
84 |
|
78 |
|
85 |
addr<<=1; |
79 |
addr<<=1; |
86 |
|
80 |
|
87 |
SMB_STOP_bit(); //If slave send NACK stop comunication |
81 |
SMB_STOP_bit(); //If slave send NACK stop comunication |
88 |
SMB_START_bit(); //Start condition |
82 |
SMB_START_bit(); //Start condition |
89 |
SMB_TX_byte(addr); |
83 |
SMB_TX_byte(addr); |
90 |
SMB_TX_byte(RAM_Access|select); |
84 |
SMB_TX_byte(RAM_Access|select); |
91 |
SMB_START_bit(); //Repeated Start condition |
85 |
SMB_START_bit(); //Repeated Start condition |
92 |
SMB_TX_byte(addr); |
86 |
SMB_TX_byte(addr); |
93 |
arr[2]=SMB_RX_byte(ACK); //Read low data,master must send ACK |
87 |
arr[2]=SMB_RX_byte(ACK); //Read low data,master must send ACK |
94 |
arr[1]=SMB_RX_byte(ACK); //Read high data,master must send ACK |
88 |
arr[1]=SMB_RX_byte(ACK); //Read high data,master must send ACK |
95 |
temp=make16(arr[1],arr[2]); |
89 |
temp=make16(arr[1],arr[2]); |
96 |
crc=SMB_RX_byte(NACK); //Read PEC byte, master must send NACK |
90 |
crc=SMB_RX_byte(NACK); //Read PEC byte, master must send NACK |
97 |
SMB_STOP_bit(); //Stop condition |
91 |
SMB_STOP_bit(); //Stop condition |
98 |
|
92 |
|
99 |
arr[5]=addr; |
93 |
arr[5]=addr; |
100 |
arr[4]=RAM_Access|select; |
94 |
arr[4]=RAM_Access|select; |
101 |
arr[3]=addr; |
95 |
arr[3]=addr; |
102 |
arr[0]=0; |
96 |
arr[0]=0; |
103 |
if (crc != PEC_calculation(arr)) temp=0; // Calculate and check CRC |
97 |
if (crc != PEC_calculation(arr)) temp=0; // Calculate and check CRC |
104 |
|
98 |
|
105 |
return temp; |
99 |
return temp; |
106 |
} |
100 |
} |
107 |
|
101 |
|
108 |
// compute CRC |
102 |
// compute CRC |
109 |
// *sn - pointer to the byte array |
103 |
// *sn - pointer to the byte array |
110 |
// num - length of array |
104 |
// num - length of array |
111 |
inline int8 TM_check_CRC(unsigned int8 *sn, unsigned int8 num) |
105 |
inline int8 TM_check_CRC(unsigned int8 *sn, unsigned int8 num) |
112 |
{ |
106 |
{ |
113 |
// CRC table |
107 |
// CRC table |
114 |
const int8 TouchCRC[256]= { |
108 |
const int8 TouchCRC[256]= { |
115 |
0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65, |
109 |
0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65, |
116 |
157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220, |
110 |
157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220, |
117 |
35, 125, 159, 193, 66, 28, 254, 160, 225, 191, 93, 3, 128, 222, 60, 98, |
111 |
35, 125, 159, 193, 66, 28, 254, 160, 225, 191, 93, 3, 128, 222, 60, 98, |
118 |
190, 224, 2, 92, 223, 129, 99, 61, 124, 34, 192, 158, 29, 67, 161, 255, |
112 |
190, 224, 2, 92, 223, 129, 99, 61, 124, 34, 192, 158, 29, 67, 161, 255, |
119 |
70, 24, 250, 164, 39, 121, 155, 197, 132, 218, 56, 102, 229, 187, 89, 7, |
113 |
70, 24, 250, 164, 39, 121, 155, 197, 132, 218, 56, 102, 229, 187, 89, 7, |
120 |
219, 133, 103, 57, 186, 228, 6, 88, 25, 71, 165, 251, 120, 38, 196, 154, |
114 |
219, 133, 103, 57, 186, 228, 6, 88, 25, 71, 165, 251, 120, 38, 196, 154, |
121 |
101, 59, 217, 135, 4, 90, 184, 230, 167, 249, 27, 69, 198, 152, 122, 36, |
115 |
101, 59, 217, 135, 4, 90, 184, 230, 167, 249, 27, 69, 198, 152, 122, 36, |
122 |
248, 166, 68, 26, 153, 199, 37, 123, 58, 100, 134, 216, 91, 5, 231, 185, |
116 |
248, 166, 68, 26, 153, 199, 37, 123, 58, 100, 134, 216, 91, 5, 231, 185, |
123 |
140, 210, 48, 110, 237, 179, 81, 15, 78, 16, 242, 172, 47, 113, 147, 205, |
117 |
140, 210, 48, 110, 237, 179, 81, 15, 78, 16, 242, 172, 47, 113, 147, 205, |
124 |
17, 79, 173, 243, 112, 46, 204, 146, 211, 141, 111, 49, 178, 236, 14, 80, |
118 |
17, 79, 173, 243, 112, 46, 204, 146, 211, 141, 111, 49, 178, 236, 14, 80, |
125 |
175, 241, 19, 77, 206, 144, 114, 44, 109, 51, 209, 143, 12, 82, 176, 238, |
119 |
175, 241, 19, 77, 206, 144, 114, 44, 109, 51, 209, 143, 12, 82, 176, 238, |
126 |
50, 108, 142, 208, 83, 13, 239, 177, 240, 174, 76, 18, 145, 207, 45, 115, |
120 |
50, 108, 142, 208, 83, 13, 239, 177, 240, 174, 76, 18, 145, 207, 45, 115, |
127 |
202, 148, 118, 40, 171, 245, 23, 73, 8, 86, 180, 234, 105, 55, 213, 139, |
121 |
202, 148, 118, 40, 171, 245, 23, 73, 8, 86, 180, 234, 105, 55, 213, 139, |
128 |
87, 9, 235, 181, 54, 104, 138, 212, 149, 203, 41, 119, 244, 170, 72, 22, |
122 |
87, 9, 235, 181, 54, 104, 138, 212, 149, 203, 41, 119, 244, 170, 72, 22, |
129 |
233, 183, 85, 11, 136, 214, 52, 106, 43, 117, 151, 201, 74, 20, 246, 168, |
123 |
233, 183, 85, 11, 136, 214, 52, 106, 43, 117, 151, 201, 74, 20, 246, 168, |
130 |
116, 42, 200, 150, 21, 75, 169, 247, 182, 232, 10, 84, 215, 137, 107, 53}; |
124 |
116, 42, 200, 150, 21, 75, 169, 247, 182, 232, 10, 84, 215, 137, 107, 53}; |
131 |
|
125 |
|
132 |
int8 CRC; |
126 |
int8 CRC; |
133 |
int8 i; |
127 |
int8 i; |
134 |
|
128 |
|
135 |
CRC=0; |
129 |
CRC=0; |
136 |
for(i=0;i<num;i++) CRC=TouchCRC[CRC ^ *(sn+i)]; |
130 |
for(i=0;i<num;i++) CRC=TouchCRC[CRC ^ *(sn+i)]; |
137 |
return(CRC); |
131 |
return(CRC); |
138 |
} |
132 |
} |
139 |
|
133 |
|
140 |
|
134 |
|
141 |
/*-------------------------------- MAIN --------------------------------------*/ |
135 |
/*-------------------------------- MAIN --------------------------------------*/ |
142 |
void main() |
136 |
void main() |
143 |
{ |
137 |
{ |
144 |
unsigned int16 seq, temp, tempa; |
138 |
unsigned int16 seq, temp, tempa; |
145 |
signed int16 ta, to1, to2, tTouch; |
139 |
signed int16 ta, to1, to2, tTouch; |
146 |
int8 tLSB,tMSB; // Temperatures from TouchMemory |
140 |
int8 tLSB,tMSB; // Temperatures from TouchMemory |
147 |
int8 safety_counter; |
141 |
int8 safety_counter; |
- |
|
142 |
int1 repeat; // Status flags |
148 |
int1 repeat; |
143 |
int1 automatic; |
149 |
|
144 |
|
150 |
output_high(DOME); // Close Dome |
145 |
output_high(DOME); // Close Dome |
151 |
output_low(HEATING); // Heating off |
146 |
output_low(HEATING); // Heating off |
152 |
|
147 |
|
153 |
delay_ms(1000); |
148 |
delay_ms(1000); |
154 |
restart_wdt(); |
149 |
restart_wdt(); |
155 |
|
150 |
|
156 |
seq=0; // Variables initiation |
151 |
seq=0; // Variables initiation |
157 |
heat=0; |
152 |
heat=0; |
158 |
open=0; |
153 |
open=0; |
159 |
repeat=TRUE; |
154 |
repeat=TRUE; |
160 |
|
155 |
|
161 |
welcome(); |
156 |
welcome(); |
162 |
|
157 |
|
163 |
tempa=ReadTemp(SA, RAM_Tamb); // Dummy read |
158 |
tempa=ReadTemp(SA, RAM_Tamb); // Dummy read |
164 |
temp=ReadTemp(SA, RAM_Tobj1); |
159 |
temp=ReadTemp(SA, RAM_Tobj1); |
165 |
touch_present(); //Issues a reset of Touch Memory device |
160 |
touch_present(); //Issues a reset of Touch Memory device |
166 |
touch_write_byte(0xCC); |
161 |
touch_write_byte(0xCC); |
167 |
touch_write_byte(0x44); |
162 |
touch_write_byte(0x44); |
168 |
|
163 |
|
169 |
delay_ms(1000); |
164 |
delay_ms(1000); |
170 |
//---WDT |
165 |
//---WDT |
171 |
restart_wdt(); |
166 |
restart_wdt(); |
172 |
|
167 |
|
173 |
while(TRUE) // Main Loop |
168 |
while(TRUE) // Main Loop |
174 |
{ |
169 |
{ |
175 |
safety_counter=SAFETY_COUNT; // Heating and Dome Count Down |
170 |
safety_counter=SAFETY_COUNT; // Heating and Dome Count Down |
176 |
do |
171 |
do |
177 |
{ |
172 |
{ |
178 |
if (safety_counter<SAFETY_COUNT) safety_counter++; |
173 |
if (safety_counter<SAFETY_COUNT) safety_counter++; |
179 |
|
174 |
|
180 |
delay(RESPONSE_DELAY); |
175 |
delay(RESPONSE_DELAY); |
181 |
|
176 |
|
182 |
if (safety_counter>=SAFETY_COUNT) |
177 |
if (safety_counter>=SAFETY_COUNT) |
183 |
{ |
178 |
{ |
184 |
if (heat>0) heat--; |
179 |
if (heat>0) heat--; |
185 |
if (open>0) open--; |
180 |
if (open>0) open--; |
186 |
|
181 |
|
187 |
if (heat>0) { output_high(HEATING); } else { output_low(HEATING); } |
182 |
if (heat>0) { output_high(HEATING); } else { output_low(HEATING); } |
188 |
|
183 |
|
189 |
safety_counter=0; |
184 |
safety_counter=0; |
190 |
//---WDT |
185 |
//---WDT |
191 |
restart_wdt(); |
186 |
restart_wdt(); |
192 |
} |
187 |
} |
193 |
} while (!kbhit()&&!repeat); |
188 |
} while (!kbhit()&&!repeat); |
194 |
|
189 |
|
195 |
//---WDT |
190 |
//---WDT |
196 |
restart_wdt(); |
191 |
restart_wdt(); |
197 |
{ // Retrieve command |
192 |
{ // Retrieve command |
198 |
char ch='k'; |
193 |
char ch='k'; |
199 |
|
194 |
|
200 |
if(kbhit()) ch=getc(); |
195 |
if(kbhit()) ch=getc(); |
201 |
|
196 |
|
202 |
switch (ch) |
197 |
switch (ch) |
203 |
{ |
198 |
{ |
204 |
case 'h': |
199 |
case 'h': |
205 |
heat=MAXHEAT; // Need heating |
200 |
heat=MAXHEAT; // Need heating |
- |
|
201 |
automatic=FALSE; |
206 |
break; |
202 |
break; |
207 |
|
203 |
|
208 |
case 'c': |
204 |
case 'c': |
209 |
heat=0; // Need colder |
205 |
heat=0; // Need colder |
- |
|
206 |
automatic=FALSE; |
210 |
break; |
207 |
break; |
211 |
|
208 |
|
212 |
case 'o': |
209 |
case 'o': |
213 |
open=MAXOPEN; // Open the dome |
210 |
open=MAXOPEN; // Open the dome |
- |
|
211 |
automatic=FALSE; |
214 |
break; |
212 |
break; |
215 |
|
213 |
|
216 |
case 'x': |
214 |
case 'x': |
217 |
open=MAXOPEN; // Open the dome |
215 |
open=MAXOPEN; // Open the dome |
218 |
heat=MAXHEAT; // Need heating |
216 |
heat=MAXHEAT; // Need heating |
- |
|
217 |
automatic=FALSE; |
219 |
break; |
218 |
break; |
220 |
|
219 |
|
221 |
case 'l': |
220 |
case 'l': |
222 |
open=0; // Lock the dome |
221 |
open=0; // Lock the dome |
- |
|
222 |
automatic=FALSE; |
223 |
break; |
223 |
break; |
224 |
|
224 |
|
225 |
case 'i': |
225 |
case 'i': |
226 |
if (open==0) welcome(); // Information about version, etc... |
226 |
if (open==0) welcome(); // Information about version, etc... |
227 |
break; // Only when dome is closed |
227 |
break; // Only when dome is closed |
228 |
|
228 |
|
229 |
case 'r': |
229 |
case 'r': |
230 |
repeat=TRUE; // Repeated measure mode |
230 |
repeat=TRUE; // Repeated measure mode |
- |
|
231 |
automatic=FALSE; |
231 |
break; |
232 |
break; |
232 |
|
233 |
|
233 |
case 's': |
234 |
case 's': |
234 |
repeat=FALSE; // Single measure mode |
235 |
repeat=FALSE; // Single measure mode |
- |
|
236 |
automatic=FALSE; |
- |
|
237 |
break; |
- |
|
238 |
|
- |
|
239 |
case 'a': |
- |
|
240 |
repeat=TRUE; // Automatic mode |
- |
|
241 |
automatic=TRUE; |
235 |
break; |
242 |
break; |
236 |
|
243 |
|
237 |
case 'u': |
244 |
case 'u': |
238 |
reset_cpu(); // Update firmware |
245 |
reset_cpu(); // Update firmware |
239 |
} |
246 |
} |
240 |
} |
247 |
} |
241 |
// while(kbhit()) getc(); // Flush USART buffer |
248 |
// while(kbhit()) getc(); // Flush USART buffer |
242 |
CREN=0; CREN=1; // Reinitialise USART |
249 |
CREN=0; CREN=1; // Reinitialise USART |
243 |
|
250 |
|
244 |
seq++; // Increment the number of measurement |
251 |
seq++; // Increment the number of measurement |
245 |
|
252 |
|
246 |
tempa=ReadTemp(SA, RAM_Tamb); // Read temperatures from sensor |
253 |
tempa=ReadTemp(SA, RAM_Tamb); // Read temperatures from sensor |
247 |
ta=tempa*2-27315; // °K -> °C |
254 |
ta=tempa*2-27315; // °K -> °C |
248 |
|
255 |
|
249 |
temp=ReadTemp(SA, RAM_Tobj1); |
256 |
temp=ReadTemp(SA, RAM_Tobj1); |
250 |
to1=temp*2-27315; |
257 |
to1=temp*2-27315; |
251 |
temp=ReadTemp(SA, RAM_Tobj2); |
258 |
temp=ReadTemp(SA, RAM_Tobj2); |
252 |
to2=temp*2-27315; |
259 |
to2=temp*2-27315; |
253 |
|
260 |
|
254 |
touch_present(); //Issues a reset of Touch Memory device |
261 |
touch_present(); //Issues a reset of Touch Memory device |
255 |
touch_write_byte(0xCC); |
262 |
touch_write_byte(0xCC); |
256 |
touch_write_byte(0x44); |
263 |
touch_write_byte(0x44); |
257 |
|
264 |
|
258 |
//---WDT |
265 |
//---WDT |
259 |
restart_wdt(); |
266 |
restart_wdt(); |
260 |
delay(MEASURE_DELAY); // Delay to a next measurement |
267 |
delay(MEASURE_DELAY); // Delay to a next measurement |
261 |
|
268 |
|
262 |
{ |
269 |
{ |
263 |
int8 SN[10]; |
270 |
int8 SN[10]; |
264 |
int8 n; |
271 |
int8 n; |
265 |
|
272 |
|
266 |
touch_present(); //Issues a reset and returns true if the touch device is there. |
273 |
touch_present(); //Issues a reset and returns true if the touch device is there. |
267 |
touch_write_byte(0xCC); |
274 |
touch_write_byte(0xCC); |
268 |
touch_write_byte(0xBE); |
275 |
touch_write_byte(0xBE); |
269 |
for(n=0;n<9;n++) SN[n]=touch_read_byte(); |
276 |
for(n=0;n<9;n++) SN[n]=touch_read_byte(); |
270 |
tLSB=SN[0]; |
277 |
tLSB=SN[0]; |
271 |
tMSB=SN[1]; |
278 |
tMSB=SN[1]; |
272 |
if ((SN[8]==TM_check_CRC(SN,8))&&(SN[7]==0x10)) // Check CRC and family code to prevent O's error |
279 |
if ((SN[8]==TM_check_CRC(SN,8))&&(SN[7]==0x10)) // Check CRC and family code to prevent O's error |
273 |
{ |
280 |
{ |
274 |
tTouch=make16(tMSB,tLSB); |
281 |
tTouch=make16(tMSB,tLSB); |
- |
|
282 |
tTouch=tTouch*6+tTouch/4; // 1bit = 0,0625gradC recalculate to 1/100gradC |
275 |
} |
283 |
} |
276 |
else |
284 |
else |
277 |
{ |
285 |
{ |
278 |
tTouch=ERROR; |
286 |
tTouch=-27315; |
279 |
} |
287 |
} |
280 |
|
- |
|
281 |
for(n=0;n<9;n++) printf("%X ",SN[n]); |
- |
|
282 |
|
- |
|
283 |
//!!! printf("CRC %u %u ",SN[8],TM_check_CRC(SN,8)); |
- |
|
284 |
//!!! printf("%.4f ",tTouch*6.25); |
- |
|
285 |
} |
288 |
} |
286 |
|
289 |
|
- |
|
290 |
if(automatic) // Solve automatic mode |
- |
|
291 |
{ |
- |
|
292 |
if(ta<1800) heat=MAXHEAT; // Need heating |
- |
|
293 |
if((abs(to1-to2)<200)&&(tTouch>to1)&&(abs(tTouch/4-to1)>500)) |
- |
|
294 |
open=MAXOPEN; // Open the dome |
- |
|
295 |
} |
- |
|
296 |
|
287 |
{ // printf |
297 |
{ // printf |
288 |
char output[8]; // Output buffer |
298 |
char output[8]; // Output buffer |
289 |
int8 j; // String pointer |
299 |
int8 j; // String pointer |
290 |
int8 check=0; // Checksum is calculated between '$' and '*' |
300 |
int8 check=0; // Checksum is calculated between '$' and '*' |
291 |
|
301 |
|
292 |
delay(SEND_DELAY); |
302 |
delay(SEND_DELAY); |
293 |
putc('$'); |
303 |
putc('$'); |
294 |
delay(SEND_DELAY); |
304 |
delay(SEND_DELAY); |
295 |
sprintf(output,"M%s \0",VER); |
305 |
sprintf(output,"M%s \0",VER); |
296 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
306 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
297 |
sprintf(output,"%Lu \0", seq); |
307 |
sprintf(output,"%Lu \0", seq); |
298 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
308 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
299 |
sprintf(output,"%Ld \0", ta); |
309 |
sprintf(output,"%Ld \0", ta); |
300 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
310 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
301 |
sprintf(output,"%Ld \0", to1); |
311 |
sprintf(output,"%Ld \0", to1); |
302 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
312 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
303 |
sprintf(output,"%Ld \0", to2); |
313 |
sprintf(output,"%Ld \0", to2); |
304 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
314 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
305 |
if(tTouch==ERROR) |
- |
|
306 |
{ |
- |
|
307 |
sprintf(output,"-27315 \0"); // Error condition |
315 |
sprintf(output,"%Ld \0",tTouch); |
308 |
} |
- |
|
309 |
else |
- |
|
310 |
{ |
- |
|
311 |
sprintf(output,"%Ld \0",tTouch*6+(tTouch/4)); // 1bit = 0,0625gradC |
- |
|
312 |
} |
- |
|
313 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
316 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
314 |
sprintf(output,"%u \0", heat); |
317 |
sprintf(output,"%u \0", heat); |
315 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
318 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
316 |
sprintf(output,"%u \0", open); |
319 |
sprintf(output,"%u \0", open); |
317 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
320 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
318 |
sprintf(output,"*%X\r\n\0", check); |
321 |
sprintf(output,"*%X\r\n\0", check); |
319 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j++]); } |
322 |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j++]); } |
320 |
delay(SEND_DELAY); |
323 |
delay(SEND_DELAY); |
321 |
} |
324 |
} |
322 |
|
325 |
|
323 |
|
- |
|
324 |
//---WDT |
326 |
//---WDT |
325 |
restart_wdt(); |
327 |
restart_wdt(); |
326 |
} |
328 |
} |
327 |
} |
329 |
} |
328 |
|
330 |
|
329 |
|
331 |
|
330 |
//#include "dbloader.c" // Space reservation for the BootLoader |
332 |
#include "dbloader.c" // Space reservation for the BootLoader |