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