/Designs/MRAKOMER4/SW/2zone/irmrak4.c
3,6 → 3,7
#define ID "$Id$"
 
#include "irmrak4.h"
#include <TOUCH.C>
 
#bit CREN = 0x18.4 // USART registers
#bit SPEN = 0x18.7
19,6 → 20,7
#define RESPONSE_DELAY 100 // Reaction time after receiving a command
#define SAFETY_COUNT 90 // Time of one emergency cycle
#define SEND_DELAY 50 // Time between two characters on RS232
#define ERROR -32000 // Error flag
 
#define DOME PIN_B4 // Dome controll port
#define HEATING PIN_B3 // Heating for defrosting
62,8 → 64,8
printf("# s - Single measure.\n\r");
printf("# u - Update firmware. Go to the Boot Loader.\n\r");
printf("#\n\r");
printf("# <sequence> <ambient[1/100 C]> <ambient[1/100 C]> <sky[1/100 C]> ");
printf("<heating[s]> <dome[s]> <check>\n\r\n\r");
printf("# <ver> <sequence> <inside[1/100 C]> <sky[1/100 C]> <sky[1/100 C]> ");
printf("<ambient[1/100 C]> <heating[s]> <dome[s]> <check>\n\r\n\r");
//---WDT
restart_wdt();
}
103,12 → 105,45
return temp;
}
 
// compute CRC
// *sn - pointer to the byte array
// num - length of array
inline int8 TM_check_CRC(unsigned int8 *sn, unsigned int8 num)
{
// CRC table
const int8 TouchCRC[256]= {
0, 94, 188, 226, 97, 63, 221, 131, 194, 156, 126, 32, 163, 253, 31, 65,
157, 195, 33, 127, 252, 162, 64, 30, 95, 1, 227, 189, 62, 96, 130, 220,
35, 125, 159, 193, 66, 28, 254, 160, 225, 191, 93, 3, 128, 222, 60, 98,
190, 224, 2, 92, 223, 129, 99, 61, 124, 34, 192, 158, 29, 67, 161, 255,
70, 24, 250, 164, 39, 121, 155, 197, 132, 218, 56, 102, 229, 187, 89, 7,
219, 133, 103, 57, 186, 228, 6, 88, 25, 71, 165, 251, 120, 38, 196, 154,
101, 59, 217, 135, 4, 90, 184, 230, 167, 249, 27, 69, 198, 152, 122, 36,
248, 166, 68, 26, 153, 199, 37, 123, 58, 100, 134, 216, 91, 5, 231, 185,
140, 210, 48, 110, 237, 179, 81, 15, 78, 16, 242, 172, 47, 113, 147, 205,
17, 79, 173, 243, 112, 46, 204, 146, 211, 141, 111, 49, 178, 236, 14, 80,
175, 241, 19, 77, 206, 144, 114, 44, 109, 51, 209, 143, 12, 82, 176, 238,
50, 108, 142, 208, 83, 13, 239, 177, 240, 174, 76, 18, 145, 207, 45, 115,
202, 148, 118, 40, 171, 245, 23, 73, 8, 86, 180, 234, 105, 55, 213, 139,
87, 9, 235, 181, 54, 104, 138, 212, 149, 203, 41, 119, 244, 170, 72, 22,
233, 183, 85, 11, 136, 214, 52, 106, 43, 117, 151, 201, 74, 20, 246, 168,
116, 42, 200, 150, 21, 75, 169, 247, 182, 232, 10, 84, 215, 137, 107, 53};
 
int8 CRC;
int8 i;
 
CRC=0;
for(i=0;i<num;i++) CRC=TouchCRC[CRC ^ *(sn+i)];
return(CRC);
}
 
 
/*-------------------------------- MAIN --------------------------------------*/
void main()
{
unsigned int16 seq, temp, tempa;
signed int16 ta, to1, to2;
signed int16 ta, to1, to2, tTouch;
int8 tLSB,tMSB; // Temperatures from TouchMemory
int8 safety_counter;
int1 repeat;
 
127,6 → 162,9
 
tempa=ReadTemp(SA, RAM_Tamb); // Dummy read
temp=ReadTemp(SA, RAM_Tobj1);
touch_present(); //Issues a reset of Touch Memory device
touch_write_byte(0xCC);
touch_write_byte(0x44);
 
delay_ms(1000);
//---WDT
213,6 → 251,39
temp=ReadTemp(SA, RAM_Tobj2);
to2=temp*2-27315;
 
touch_present(); //Issues a reset of Touch Memory device
touch_write_byte(0xCC);
touch_write_byte(0x44);
//---WDT
restart_wdt();
delay(MEASURE_DELAY); // Delay to a next measurement
 
{
int8 SN[10];
int8 n;
 
touch_present(); //Issues a reset and returns true if the touch device is there.
touch_write_byte(0xCC);
touch_write_byte(0xBE);
for(n=0;n<9;n++) SN[n]=touch_read_byte();
tLSB=SN[0];
tMSB=SN[1];
if ((SN[8]==TM_check_CRC(SN,8))&&(SN[7]==0x10)) // Check CRC and family code to prevent O's error
{
tTouch=make16(tMSB,tLSB);
}
else
{
tTouch=ERROR;
}
 
for(n=0;n<9;n++) printf("%X ",SN[n]);
//!!! printf("CRC %u %u ",SN[8],TM_check_CRC(SN,8));
//!!! printf("%.4f ",tTouch*6.25);
}
{ // printf
char output[8]; // Output buffer
int8 j; // String pointer
221,32 → 292,39
delay(SEND_DELAY);
putc('$');
delay(SEND_DELAY);
sprintf(output,"M%s ",VER);
sprintf(output,"M%s \0",VER);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"%Lu ", seq);
sprintf(output,"%Lu \0", seq);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"%Ld ", ta);
sprintf(output,"%Ld \0", ta);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"%Ld ", to1);
sprintf(output,"%Ld \0", to1);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"%Ld ", to2);
sprintf(output,"%Ld \0", to2);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"%u ", heat);
if(tTouch==ERROR)
{
sprintf(output,"-27315 \0"); // Error condition
}
else
{
sprintf(output,"%Ld \0",tTouch*6+(tTouch/4)); // 1bit = 0,0625gradC
}
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"%u ", open);
sprintf(output,"%u \0", heat);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"*%X\n\r\0", check);
sprintf(output,"%u \0", open);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"*%X\r\n\0", check);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j++]); }
delay(SEND_DELAY);
}
 
//---WDT
restart_wdt();
delay(MEASURE_DELAY); // Delay to a next measurement
//---WDT
restart_wdt();
}
}
 
 
#include "dbloader.c" // Space reservation for the BootLoader
//#include "dbloader.c" // Space reservation for the BootLoader