No changes between revisions
/Designs/MRAKOMER4/SW/2zone/irmrak4.c |
---|
0,0 → 1,332 |
/**** IR Mrakomer 4 ****/ |
#define VERSION "4.1" |
#define ID "$Id$" |
#include "irmrak4.h" |
#bit CREN = 0x18.4 // USART registers |
#bit SPEN = 0x18.7 |
#bit OERR = 0x18.1 |
#bit FERR = 0x18.2 |
#include <string.h> |
#CASE // Case sensitive compiler |
#define MAXHEAT 20 // Number of cycles for heating |
#define MAXOPEN 20 // Number of cycles for dome open |
#define MEASURE_DELAY 6000 // Delay to a next measurement |
#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 DOME PIN_B4 // Dome controll port |
#define HEATING PIN_B3 // Heating for defrosting |
char VER[4]=VERSION; // Buffer for concatenate of a version string |
int8 heat; // Status variables |
int8 open; |
inline void toggle_dome(void) // Wire exercise |
{ |
if (open>0) |
{output_toggle(DOME);} // Toggle = Open Dome |
else |
{output_high(DOME);} // Do not toggle = Close Dome |
} |
void delay(int16 cycles) // Wire exercise with delay |
{ |
int16 i; |
for(i=0; i<cycles; i++) {toggle_dome(); delay_us(100);} |
} |
void welcome(void) // Welcome message |
{ |
char REV[50]=ID; // Buffer for concatenate of a version string |
if (REV[strlen(REV)-1]=='$') REV[strlen(REV)-1]=0; |
printf("\r\n\r\n# Mrakomer %s (C) 2007 UST\n\r",VER); // Welcome message |
printf("#%s\r\n",&REV[4]); |
// printf("#\r\n"); |
printf("# commands: h, c, o, l, x, i, r, a, s, u\r\n"); |
// printf("# h_eat, c_old, o_pen, l_ock, x_open, "); |
// printf("i_nfo, r_epeat, a_uto, s_single, u_pdate\r\n"); |
// printf("#\r\n"); |
printf("# ver seq in[1/100 C] sky[1/100 C] sky[1/100 C] "); |
printf("out[1/100 C] heat[s] dome[s] check\r\n\r\n"); |
//---WDT |
restart_wdt(); |
} |
#include "smb.c" // System Management Bus driver |
#include "TOUCH.C" |
// Read sensor's RAM |
// Returns temperature in °K |
int16 ReadTemp(int8 addr, int8 select) |
{ |
unsigned char arr[6]; // Buffer for the sent bytes |
int8 crc; // Readed CRC |
int16 temp; // Readed temperature |
addr<<=1; |
SMB_STOP_bit(); //If slave send NACK stop comunication |
SMB_START_bit(); //Start condition |
SMB_TX_byte(addr); |
SMB_TX_byte(RAM_Access|select); |
SMB_START_bit(); //Repeated Start condition |
SMB_TX_byte(addr); |
arr[2]=SMB_RX_byte(ACK); //Read low data,master must send ACK |
arr[1]=SMB_RX_byte(ACK); //Read high data,master must send ACK |
temp=make16(arr[1],arr[2]); |
crc=SMB_RX_byte(NACK); //Read PEC byte, master must send NACK |
SMB_STOP_bit(); //Stop condition |
arr[5]=addr; |
arr[4]=RAM_Access|select; |
arr[3]=addr; |
arr[0]=0; |
if (crc != PEC_calculation(arr)) temp=0; // Calculate and check CRC |
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, tTouch; |
int8 tLSB,tMSB; // Temperatures from TouchMemory |
int8 safety_counter; |
int1 repeat; // Status flags |
int1 automatic; |
output_high(DOME); // Close Dome |
output_low(HEATING); // Heating off |
delay_ms(1000); |
restart_wdt(); |
seq=0; // Variables initiation |
heat=0; |
open=0; |
repeat=TRUE; |
automatic=FALSE; |
welcome(); |
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 |
restart_wdt(); |
while(TRUE) // Main Loop |
{ |
safety_counter=SAFETY_COUNT; // Heating and Dome Count Down |
do |
{ |
if (safety_counter<SAFETY_COUNT) safety_counter++; |
delay(RESPONSE_DELAY); |
if (safety_counter>=SAFETY_COUNT) |
{ |
if (heat>0) heat--; |
if (open>0) open--; |
if (heat>0) { output_high(HEATING); } else { output_low(HEATING); } |
safety_counter=0; |
//---WDT |
restart_wdt(); |
} |
} while (!kbhit()&&!repeat); |
//---WDT |
restart_wdt(); |
{ // Retrieve command |
char ch='k'; |
if(kbhit()) ch=getc(); |
switch (ch) |
{ |
case 'h': |
heat=MAXHEAT; // Need heating |
automatic=FALSE; |
break; |
case 'c': |
heat=0; // Need colder |
automatic=FALSE; |
break; |
case 'o': |
open=MAXOPEN; // Open the dome |
automatic=FALSE; |
break; |
case 'x': |
open=MAXOPEN; // Open the dome |
heat=MAXHEAT; // Need heating |
automatic=FALSE; |
break; |
case 'l': |
open=0; // Lock the dome |
automatic=FALSE; |
break; |
case 'i': |
if (open==0) welcome(); // Information about version, etc... |
break; // Only when dome is closed |
case 'r': |
repeat=TRUE; // Repeated measure mode |
automatic=FALSE; |
break; |
case 's': |
repeat=FALSE; // Single measure mode |
automatic=FALSE; |
break; |
case 'a': |
repeat=TRUE; // Automatic mode |
automatic=TRUE; |
break; |
case 'u': |
reset_cpu(); // Update firmware |
} |
} |
CREN=0; CREN=1; // Reinitialise USART |
seq++; // Increment the number of measurement |
tempa=ReadTemp(SA, RAM_Tamb); // Read temperatures from sensor |
ta=tempa*2-27315; // °K -> °C |
temp=ReadTemp(SA, RAM_Tobj1); |
if (temp>0x48E1) {to1=-27315;} else {to1=temp*2-27315;} |
temp=ReadTemp(SA, RAM_Tobj2); |
if (temp>0x48E1) {to2=-27315;} else {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); |
tTouch=tTouch*6+tTouch/4; // 1bit = 0,0625gradC recalculate to 1/100gradC |
} |
else |
{ |
tTouch=-27315; |
} |
} |
if(automatic) // Solve automatic mode |
{ |
if(ta<1800) heat=MAXHEAT; // Need heating |
if((abs(to1-to2)<100)&&(tTouch>to1)&&(abs(tTouch/2-to1)>600)) |
open=MAXOPEN; // Open the dome |
} |
{ // printf |
char output[8]; // Output buffer |
int8 j; // String pointer |
int8 check=0; // Checksum is calculated between '$' and '*' |
delay(SEND_DELAY); |
putc('$'); |
delay(SEND_DELAY); |
sprintf(output,"M%s \0",VER); |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
sprintf(output,"%Lu \0", seq); |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
sprintf(output,"%Ld \0", ta); |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
sprintf(output,"%Ld \0", to1); |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
sprintf(output,"%Ld \0", to2); |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
sprintf(output,"%Ld \0",tTouch); |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
sprintf(output,"%u \0", heat); |
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; } |
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(); |
} |
} |
#include "dbloader.c" // Space reservation for the BootLoader |
Property changes: |
Added: svn:keywords |
+Id |
\ No newline at end of property |
/Designs/MRAKOMER4/SW/2zone/irmrak4.hex |
---|
0,0 → 1,407 |
:0C00000008308A00822800002028080038 |
:100040000A108A100A11273E03188A0A8200003417 |
:100050005E34BC34E23461343F34DD348334C23442 |
:100060009C347E342034A334FD341F3441349D3419 |
:10007000C33421347F34FC34A23440341E345F3422 |
:100080000134E334BD343E3460348234DC34233410 |
:100090007D349F34C13442341C34FE34A034E13406 |
:1000A000BF345D3403348034DE343C346234BE34D7 |
:1000B000E03402345C34DF34813463343D347C34E6 |
:1000C0002234C0349E341D344334A134FF344634CA |
:1000D0001834FA34A434273479349B34C534843446 |
:1000E000DA3438346634E534BB3459340734DB341D |
:1000F000853467343934BA34E43406345834193426 |
:100100004734A534FB3478342634C4349A34653407 |
:100110003B34D934873404345A34B834E634A73401 |
:10012000F9341B344534C63498347A342434F834E2 |
:10013000A63444341A349934C73425347B343A34E1 |
:1001400064348634D8345B340534E734B9348C34C1 |
:10015000D23430346E34ED34B33451340F344E3441 |
:100160001034F234AC342F3471349334CD34113430 |
:100170004F34AD34F33470342E34CC349234D33421 |
:100180008D346F343134B234EC340E345034AF34F7 |
:10019000F13413344D34CE34903472342C346D3405 |
:1001A0003334D1348F340C345234B034EE343234EE |
:1001B0006C348E34D03453340D34EF34B134F034E5 |
:1001C000AE344C3412349134CF342D347334CA34B9 |
:1001D000943476342834AB34F53417344934083445 |
:1001E0005634B434EA3469343734D5348B34573424 |
:1001F0000934EB34B534363468348A34D434953425 |
:10020000CB3429347734F434AA3448341634E934FE |
:10021000B73455340B348834D63434346A342B3400 |
:1002200075349734C9344A341434F634A8347434E9 |
:100230002A34C834963415344B34A934F734B634E0 |
:10024000E8340A345434D73489346B3435340D05EA |
:100250000D0523104D39E135EF366539A0127310C5 |
:10026000A82129103218B01BA02A532A8A060000A0 |
:100270002310E337ED366137E4393A106816A031C0 |
:100280002C106F1620362C107816A0342C107216F5 |
:10029000A0302C107316A03A0D0500002310F63282 |
:1002A0007210F33271106937DB18AF183018A021C3 |
:1002B0005D10F335F92DB11731183010C32EA03968 |
:1002C000EB3CDB18AF183018A0215D100001EF3AAD |
:1002D000F42DB11731183010C32E2034E530F42D31 |
:1002E000F32E2032EF36E52DF32EA031E832E33540 |
:1002F0000D050D0500005330840083130008031919 |
:100300008E290230F800F701F70B8429F80B8329B6 |
:100310009730F700F70B8A29800B81290800831694 |
:100320005308D5005208D4005508FA005408840038 |
:1003300083137A18831780080319A229D40A031992 |
:10034000D50A942952085402F7005508FA005308B8 |
:10035000031C530FFA027708F80083120800831673 |
:1003600003178C170C14000000000318E6298312F1 |
:100370000C087F3983160313D300831203170D086B |
:1003800083160313D400831203170F088316031375 |
:10039000D500530883120C1ECB29990083165408EC |
:1003A000831203178D008316031355088312031756 |
:1003B0008F0083168C170C14000000000313D20B5F |
:1003C000E229E4290317E629112A031783120C0DE9 |
:1003D0000E0D7F3983160313D300831203170D0804 |
:1003E00083160313D400831203170F088316031315 |
:1003F000D500530883120C1EFB299900831654085C |
:10040000831203178D0083160313550883120317F5 |
:100410008F008D0A03198F0A031083160313D20B62 |
:10042000B0298312080080080319302A8316D301EB |
:100430000408D2005310831B5314000883120C1EAF |
:100440001F2A9900831652088400831353188317B8 |
:10045000840A031D2E2A8312850A83168312132A07 |
:100460000800831603178C170C1400000000831279 |
:100470000C087F3903198B2A83160313D2008312C9 |
:1004800003170D0883160313D300831203170F08F5 |
:1004900083160313D400520883120C1E4D2A9900B0 |
:1004A00083165308831203178D0083160313540811 |
:1004B000831203178F0083168C170C1400000000A2 |
:1004C00083120C0D0E0D7F3903198B2A831603132B |
:1004D000D200831203170D0883160313D30083126F |
:1004E00003170F0883160313D400520883120C1E3F |
:1004F000772A990083165308831203178D008316F9 |
:1005000003135408831203178F008D0A03198F0AEF |
:100510000313312A03170313080024308316A000A5 |
:100520004930A1006430A2003A30A3002030A4007A |
:100530006930A5007230A6006D30A7007230A800A7 |
:100540006130A9006B30AA003430AB002E30AC0013 |
:100550006330AD002030AE003130AF003730B00036 |
:100560003130B1003030B2002030B3003230B4004E |
:100570003030B5003130B6003030B7002D30B80023 |
:100580003130B9003230BA002D30BB003030BC0001 |
:100590003730BD002030BE003030BF003730C000E3 |
:1005A0003A30C1003130C2003730C3003A30C400A5 |
:1005B0003330C5003630C6005A30C7002030C8007E |
:1005C0006B30C9006130CA006B30CB006C30CC009E |
:1005D0002030CD002430CE00CF01D301A030D20096 |
:1005E00083128F2101307802A03E8400831300081B |
:1005F000243C031D072B8316D301A030D2008312A5 |
:100600008F2101307802A03E8400831380012730BF |
:1006100003178D0001308F0003100F308316031372 |
:10062000D2008312AF2122308400831313222F3093 |
:1006300003178D0001308F0003140F30831603134E |
:10064000D2008312AF2123300C1E242B9900A4303A |
:100650008400831313220D300C1E2C2B99000A30BA |
:100660000C1E302B9900383003178D0001308F009D |
:10067000031331224E3003178D0001308F00031316 |
:100680003122673003178D0001308F0003133122B0 |
:1006900064000800831686140610831206100D30BD |
:1006A000F700F70B512B83168610831286100D303E |
:1006B000F700F70B592B831606140D30F700F70BD4 |
:1006C0005F2B861483120800831686140D30F70002 |
:1006D000F70B682B06140D30F700F70B6D2B861007 |
:1006E000831286100D30F700F70B742B831606105B |
:1006F000831206100D30F700F70B7C2B0800E20880 |
:10070000031D872B83168610831286108A2B83166F |
:10071000861483128B2B8C2B8D2B831606141A3088 |
:10072000F700F70B912B0000061083120610A708A4 |
:100730000319A02B83160612103083128606A42BF1 |
:1007400083160612831206164230F700F70BA62B0B |
:100750000000A7080319B22B83160612103083126B |
:100760008606B62B83160612831206160800831619 |
:10077000861406141A30F700F70BBC2B0000861401 |
:100780008312861CC62B0130E200C72BE2018316C0 |
:10079000061083120610A7080319D42B831606121D |
:1007A000103083128606D82B831606128312061683 |
:1007B0004230F700F70BDA2B0000A7080319E62BED |
:1007C00083160612103083128606EA2B8316061251 |
:1007D000831206166208F80008000830DF00DF0800 |
:1007E0000319FF2BDE1FF72B0130E100F82BE1018D |
:1007F0006108E2007F230310DE0DDF03EF2BB72338 |
:100800007808E0006008F80008000830DF00DF0822 |
:100810000319172CB723F8080319122C0310DE0D47 |
:100820005E14152C0310DE0D5E10DF03072C5D082F |
:10083000E2007F235E08F80008000310D20D4A236F |
:1008400064235208DE00ED235308DD00DE00ED23B3 |
:1008500064235208DE00ED23DD0105247808D6006C |
:10086000DD0105247808D5005508DC005608DB00BA |
:100870000130DD0005247808DA004A235208D90047 |
:100880005308D8005208D700D401DE015430DD00EF |
:100890002F30E500E401E301E201E1010130E00075 |
:1008A0000730DF002F30E500E6010530E700E80102 |
:1008B00067085D07840083135E1883170008EA0049 |
:1008C0008030F7006808F80003196A2C0310F70C51 |
:1008D000F80B662C77086A05031D882CE7080319B6 |
:1008E000882CE5036808063C031C782CE80A7A2C5F |
:1008F000E801E703A7080319832C831606121030BA |
:1009000083128606872C8316061283120616582C2D |
:1009100008306502E600E6080319C02C0530E70040 |
:10092000670F932CB12C013067025F3E8400831364 |
:10093000801FA02CE7080319A02C0130E900A12C8E |
:10094000E9015F306707840083130310000D800006 |
:100950005F30670784008313690800078000E7039E |
:10096000902CE603A7080319BB2C8316061210303F |
:1009700083128606BF2C83160612831206168B2C52 |
:10098000E7016708053C031CE32C67085D07F800D6 |
:100990005E08FA000318FA0A7808840083137A18AC |
:1009A00083170008EC005F3067078400831300089A |
:1009B0006C06EC007808840083137A1883176C089F |
:1009C0008000E70AC12C6508083C031C4A2C5D081E |
:1009D000840083135E1883170008F80078085A0211 |
:1009E0000319F42CDC01DB015B08F8005C08F9005A |
:1009F000080083168613861383128613A70803192B |
:100A0000072D831606121030831286060B2D8316CF |
:100A10000612831206164230F700F70B0D2D000068 |
:100A2000A7080319192D83160612103083128606A3 |
:100A30001D2D83160612831206164230F700F70B9F |
:100A40001F2D0000A70803192B2D83160612103046 |
:100A5000831286062F2D8316061283120616423045 |
:100A6000F700F70B312D0000A70803193D2D831661 |
:100A70000612103083128606412D83160612831249 |
:100A800006164230F700F70B432D0000A7080319A4 |
:100A90004F2D83160612103083128606532D8316AF |
:100AA0000612831206164230F700F70B552D000090 |
:100AB000A7080319612D83160612103083128606CB |
:100AC000652D8316061283120616831686170330C9 |
:100AD000F700F70B692D8312861B712D0030F8008B |
:100AE000CC2D2B30F700F70B732DA70803197E2DA3 |
:100AF00083160612103083128606822D8316061284 |
:100B0000831206165210861F5214A70803198E2D41 |
:100B100083160612103083128606922D8316061253 |
:100B2000831206164230F700F70B942D0000A70839 |
:100B30000319A02D83160612103083128606A42DE9 |
:100B400083160612831206164230F700F70BA62D05 |
:100B50000000A7080319B22D831606121030831265 |
:100B60008606B62D83160612831206161330F7007A |
:100B7000F70BB82DBB2DA7080319C42D8316061239 |
:100B8000103083128606C82D8316061283120616AD |
:100B9000003052180130F80008000130D30053082B |
:100BA000083C031C2B2E0310D20C0030031801301C |
:100BB000D4005408D5008316861386138312861337 |
:100BC0000630F700F70BE22D0000D5080319F82DC9 |
:100BD000831686138613831286170630F700F70BE9 |
:100BE000EF2D0000861BF72D0030F800232E072E76 |
:100BF000831686138613831286130630F700F70BCD |
:100C0000FF2D0000861F072E0030F800232E213014 |
:100C1000F700F70B092E83168613861383128617A7 |
:100C2000A7080319192E83160612103083128606A0 |
:100C30001D2E83160612831206162130F700F70BBD |
:100C40001F2E0130F800F808031D292E0030F8008F |
:100C50002D2ED30ACF2D0130F8000800D501D40184 |
:100C600055085302031C502E031D3A2E52085402FD |
:100C70000318502EA7080319432E831606121030AE |
:100C800083128606472E83160612831206164230FA |
:100C9000F700F70B492E0000D40A0319D50A302EAD |
:100CA00008000130D4005408083C031C892E831628 |
:100CB00086138613831286130930F700F70B5E2E16 |
:100CC000831686170330F700F70B642E8312561035 |
:100CD000861B56144230F700F70B6C2E0000A70855 |
:100CE0000319782E831606121030831286067C2E86 |
:100CF0008316061283120616003056180130F800CB |
:100D0000F808031D852E0310862E0314D50CD40A73 |
:100D1000532E5508F8008A15F029530855068039D6 |
:100D2000D700D31F982ED209D309D20A0319D30AA8 |
:100D3000D51F9F2ED409D509D40A0319D50A10301E |
:100D4000D600F701FA01D30CD20C031CAD2E5408C7 |
:100D5000F7070318FA0A5508FA07FA0CF70CF90C0A |
:100D6000F80CD60BA32ED71FBA2EF809F909F80AEA |
:100D70000319F90A8A15352A550857068039D9000A |
:100D8000D51FC72ED409D509D40A0319D50AD71FF0 |
:100D9000CE2ED609D709D60A0319D70AF801F901C8 |
:100DA000F701FA015708031DD82E56080319F22E31 |
:100DB0001030D8000310D40DD50DF70DFA0D5708DB |
:100DC0007A02031DE52E56087702031CEE2E560804 |
:100DD000F702031CFA035708FA020314F80DF90D81 |
:100DE000D80BDA2ED91FF92EF809F909F80A0319D8 |
:100DF000F90A0800280884008313291883175B0860 |
:100E00008000840A8001A80A0319A90A0800800842 |
:100E100003191C2FD3010408D2005310831B531451 |
:100E20000008DB00FA265208840083135318831746 |
:100E3000840A0319850A072F8A15E82ADA010408AB |
:100E4000D9005A10831B5A14530EF038D500D50719 |
:100E5000E23ED600323ED80053080F39D607D607F7 |
:100E6000D807E93ED700D707D707520E0F39D70763 |
:100E7000D807D70DD80DD809D80D52080F39D80783 |
:100E8000D50D0730D4000A30D807D703031C442FF0 |
:100E9000D707D603031C482FD607D503031C4C2FB6 |
:100EA000D507D403031C502F54308400831307301C |
:100EB00059055913840758300402031959170008BB |
:100EC000F700031D6B2F591B6B2F591A7D2FD91952 |
:100ED0006B2F20306E2FD91559123030F707D30100 |
:100EE0000408D2005310831B53147708DB00FA2642 |
:100EF00052088400831353188317840A591F5B2FE9 |
:100F00008A15192B5508F801540203188A2F540822 |
:100F1000F700962FF7010830D600D40DF70D5508CD |
:100F200077020318F700F80DD60B8D2F080078080C |
:100F30005208D4006430D50082277708D2007808A0 |
:100F40003030031DAA2FD31CB12FD319B12F531A40 |
:100F50002030AD2FD31153125314F8077808DB005B |
:100F6000FA265208D4000A30D50082277708D2002A |
:100F700078083030031DC22FD319C62F531CC62F3B |
:100F8000531A2030F8077808DB00FA263030D207F1 |
:100F90005208DB00FA260800D31BDE2F0F30F700C3 |
:100FA000520EF7050A3077020318D92F3030F707B1 |
:100FB000DB2F5308F7077708DB00FA260F30D2053E |
:100FC0000A3052020318E62F3030E82FD3135308AB |
:0C0FD000D2075208DB00FA268A15672CB5 |
:10100000DA010408D9005A10831B5A14D31F102880 |
:10101000D917591ED90AD209D309D20A0319D30AFA |
:10102000530EF038D500D507E23ED600323ED80048 |
:1010300053080F39D607D607D807E93ED700D70798 |
:10104000D707520E0F39D707D807D70DD80DD809B3 |
:10105000D80D52080F39D807D50D0730D4000A3003 |
:10106000D807D703031C3028D707D603031C34281E |
:10107000D607D503031C3828D507D403031C3C2806 |
:1010800054308400831307305905591384035905DC |
:10109000031D5128591A840A591A51282030F70083 |
:1010A0006E28840758300402031959170008F70006 |
:1010B000031D6228591B6228591A7E28D9196228F3 |
:1010C00020306D28D91F6A282D30F700840359136A |
:1010D000D9136E28D91559123030F707D3010408F7 |
:1010E000D2005310831B53147708DB008A11FA26B1 |
:1010F0008A1552088400831353188317840A591FD2 |
:1011000052280800840183131F3083057230831630 |
:101110008F000F0833309900A2309800903083126E |
:10112000980083161F129F121B0880399B000730FE |
:101130009C008312A001A1013430A2002E30A30034 |
:101140003130A400A501A801A9018316061283125B |
:10115000061683168611831286110430D200FA30E7 |
:10116000D3008A117B218A15D20BAF286400AB0112 |
:10117000AA01A601A7013B14BB108A118D228A1572 |
:10118000D2010630D3008A111D248A157908AF00D8 |
:101190007808AE00D2010730D3008A111D248A15C9 |
:1011A0007908AD007808AC008A11F9248A15CC3092 |
:1011B000D2008A11CD258A154430D2008A11CD255E |
:1011C0008A150430D200FA30D3008A117B218A15A7 |
:1011D000D20BE32864005A30BA003A08593C03188D |
:1011E000BA0AD3016430D2008A112E268A153A0831 |
:1011F000593C03180F29A608031DA603A708031DC1 |
:10120000A703A608031909298316861183128615D8 |
:101210000D298316861183128611BA0164008C1A77 |
:1012200013293B1CED2864006B30BC008C1E1C296C |
:101230008C1E18291A08BC0061303C02E83E0318D5 |
:101240004829183E952C1430A600BB104829A60149 |
:10125000BB1048291430A700BB1048291430A70040 |
:10126000A600BB104829A701BB104829A708031DE9 |
:101270003C298A118D228A1548293B14BB10482924 |
:101280003B10BB1048293B14BB1448298A01002895 |
:1012900018121816AA0A0319AB0AD2010630D30095 |
:1012A0008A111D248A157908AF007808AE00031052 |
:1012B0002E0DD2002F0DD300B3305202F700530889 |
:1012C000FA006A30031C6B30FA027708B0007A0823 |
:1012D000B100D2010730D3008A111D248A15790884 |
:1012E000AD007808AC002D08473C03188329FF3A6D |
:1012F000031D7E292C08E13C031883299530B30097 |
:101300004D30B200952903102C0DD2002D0DD300C5 |
:10131000B3305202F7005308FA006A30031C6B30F6 |
:10132000FA027708B2007A08B300D2010830D3007D |
:101330008A111D248A157908AD007808AC002D08A3 |
:10134000473C0318AF29FF3A031DAA292C08E13CAA |
:101350000318AF299530B5004D30B400C1290310F2 |
:101360002C0DD2002D0DD300B3305202F7005308DC |
:10137000FA006A30031C6B30FA027708B4007A086E |
:10138000B5008A11F9248A15CC30D2008A11CD25F6 |
:101390008A154430D2008A11CD258A156400173091 |
:1013A000D3007030D2008A112E268A158A11F924B2 |
:1013B0008A15CC30D2008A11CD258A15BE30D200D4 |
:1013C0008A11CD258A15C7014708083C031CFA2954 |
:1013D0003D304707D200D3010318D30A8A11512E9A |
:1013E0008A155208840083135318831778088000E5 |
:1013F000C70AE4293D08B8003E08B900D3013D30D2 |
:10140000D2000830D400D501D60154085602031882 |
:101410001E2A56085207F8005308FA000318FA0A61 |
:101420007808840083137A188317000855068A11F8 |
:1014300020208A15F800D500D60A052A5508F8009C |
:1014400078084502031D4E2A4408103C031D4E2A0D |
:101450003908B7003808B6003708D3003608D2007C |
:10146000D5010630D4008A118D2E8A157908D30053 |
:101470007808D2003708D5003608D400D7010430E8 |
:10148000D6008A11BC268A1578085207B600530880 |
:10149000B70079080318790FB707522A9530B700BB |
:1014A0004D30B600BB1CCA2AB11B602A3108073C6C |
:1014B000031C622A031D602A3008073C031C622AB1 |
:1014C0001430A60034083202D2003308D3003508A5 |
:1014D000031C350FD3025308FA005208D31F792A90 |
:1014E0005208003CF700FA015308031C530FFA029C |
:1014F0007708D2007A08D300D31B852AD308031DAE |
:10150000CA2A5208633C031CCA2AB31F8A2AB71F7F |
:10151000962A8C2AB71BCA2A33083702031CCA2A08 |
:10152000031D962A360832020318CA2A3708D50046 |
:101530003608D400D7010230D6008A11BC268A159D |
:101540007908D3007808D2003208D2023308031C8D |
:10155000330FD3025308FA005208D31FB82A520897 |
:10156000003CF700FA015308031C530FFA027708F6 |
:10157000D2007A08D300D31BCA2A5308013C0318AF |
:10158000CA2AFF3A031DC82A5208583C0318CA2A1F |
:101590001430A700D101D3013230D2008A112E2697 |
:1015A0008A1524300C1ED22A9900D3013230D20081 |
:1015B0008A112E268A15A9014830A8004D30DB007B |
:1015C0008A11FA268A152230840083138A11072F84 |
:1015D0008A152030DB008A11FA268A15D00148309E |
:1015E000500784008313800803190E2BD301323077 |
:1015F000D2008A112E268A154830500784008313A2 |
:101600000008D20052080C1E032B99005008D00A83 |
:10161000483E840083130008D106EF2AA901483010 |
:10162000A800103084002B08D3002A08D2008A11A9 |
:101630001E2F8A152030DB008A11FA268A15D00168 |
:101640004830500784008313800803193F2BD301CF |
:101650003230D2008A112E268A1548305007840075 |
:1016600083130008D20052080C1E342B9900500836 |
:10167000D00A483E840083130008D106202BA9011C |
:101680004830A800103084003108D3003008D20060 |
:1016900000202030DB008A11FA268A15D00148305C |
:1016A000500784008313800803196E2BD301323056 |
:1016B000D2008A112E268A154830500784008313E1 |
:1016C0000008D20052080C1E632B99005008D00A63 |
:1016D000483E840083130008D1064F2BA9014830EF |
:1016E000A800103084003308D3003208D200002054 |
:1016F0002030DB008A11FA268A15D00148305007C5 |
:1017000084008313800803199D2BD3013230D2004B |
:101710008A112E268A15483050078400831300084A |
:10172000D20052080C1E922B99005008D00A483E55 |
:10173000840083130008D1067E2BA9014830A8003D |
:10174000103084003508D3003408D2000020203047 |
:10175000DB008A11FA268A15D00148305007840030 |
:10176000831380080319CC2BD3013230D2008A11A5 |
:101770002E268A1548305007840083130008D200B3 |
:1017800052080C1EC12B99005008D00A483E840014 |
:1017900083130008D106AD2BA9014830A8001030F2 |
:1017A00084003708D3003608D20000202030DB0048 |
:1017B0008A11FA268A15D001483050078400831315 |
:1017C00080080319FB2BD3013230D2008A112E2658 |
:1017D0008A1548305007840083130008D20052084D |
:1017E0000C1EF02B99005008D00A483E8400831349 |
:1017F0000008D106DC2BA9014830A8002608D20039 |
:101800001B30D3008A1197278A152030DB008A11FC |
:10181000FA268A15D00148305007840083138008C7 |
:1018200003192A2CD3013230D2008A112E268A15B0 |
:1018300048305007840083130008D20052080C1E61 |
:101840001F2C99005008D00A483E840083130008DA |
:10185000D1060B2CA9014830A8002708D2001B3064 |
:10186000D3008A1197278A152030DB008A11FA26C7 |
:101870008A15D0014830500784008313800803196B |
:10188000592CD3013230D2008A112E268A154830C5 |
:101890005007840083130008D20052080C1E4E2CFF |
:1018A00099005008D00A483E840083130008D106EE |
:1018B0003A2CA9014830A8002A30DB008A11FA2608 |
:1018C0008A155108D2003730D3008A11CC2F8A15DF |
:1018D0000D30DB008A11FA268A150A30DB008A11E6 |
:1018E000FA268A15D00148305007840083138008F7 |
:1018F00003198C2CD3013230D2008A112E268A157E |
:101900005008D00A483E840083130008D2005208D1 |
:101910000C1E882C9900732CD3013230D2008A110E |
:101920002E268A156400EB2863000A108A100A1517 |
:10193000820743294829272948294829482948292D |
:1019400023293629482948293329482948292A2979 |
:10195000482948293D294029482946294829482914 |
:021960002E292E |
:061980008A0100280800A6 |
:04400E00143FFC3F20 |
:00000001FF |
;PIC16F88 |
;CRC=AFB4 CREATED="09-12-10 22:59" |
/Designs/MRAKOMER4/SW/2zone/irmrak4.PJT |
---|
0,0 → 1,47 |
[PROJECT] |
Target=irmrak4.HEX |
Development_Mode=2 |
Processor=0x688F |
Processor_Text=PIC16F88 |
ToolSuite=CCS |
[Directories] |
Include= |
Library= |
LinkerScript= |
[Target Data] |
FileList=C:\Dokumenty\MLAB\Designs\MRAKOMER4\SW\2zone\irmrak4.c |
BuildTool=C-COMPILER |
OptionString=+FM |
AdditionalOptionString= |
BuildRequired=1 |
[irmrak4.c] |
Type=4 |
Path= |
FileList= |
BuildTool= |
OptionString= |
AdditionalOptionString= |
[mru-list] |
1=irmrak4.c |
[Windows] |
0=0000 irmrak4.c 0 0 796 451 3 0 |
[Opened Files] |
1=irmrak4.c |
2= |
3=..\..\..\..\..\..\..\..\Program Files\PICC\Devices\16F88.h |
4=..\..\..\..\..\..\..\..\Program Files\PICC\Drivers\string.h |
5=..\..\..\..\..\..\..\..\Program Files\PICC\Drivers\stddef.h |
6=..\..\..\..\..\..\..\..\Program Files\PICC\Drivers\ctype.h |
7=smb.c |
8=TOUCH.C |
9=dbloader.c |
10= |
[Units] |
Count=1 |
1=irmrak4 (main) |
/Designs/MRAKOMER4/SW/2zone/TOUCH.C |
---|
0,0 → 1,258 |
/////////////////////////////////////////////////////////////////////////// |
//// Dallas Touch Driver //// |
//// //// |
//// //// |
//// data = touch_read_bit() Reads one bit from a touch device //// |
//// //// |
//// data = touch_read_BYTE() Reads one byte from a touch device. //// |
//// //// |
//// ok = touch_write_bit(data) Writes one bit to a touch device //// |
//// and returns true if all went ok. //// |
//// A false indicates a collision with //// |
//// another device. //// |
//// //// |
//// ok = touch_write_byte(data) Writes one byte to a touch device //// |
//// and returns true if all went ok. //// |
//// A false indicates a collision with //// |
//// another device. //// |
//// //// |
//// present = touch_present() Issues a reset and returns true //// |
//// if the touch device is there. //// |
//// //// |
//// reset_pulse() Issues a reset and waits for a //// |
//// present pulse. //// |
//// //// |
/////////////////////////////////////////////////////////////////////////// |
//// (C) Copyright 1996,2010 Custom Computer Services //// |
//// This source code may only be used by licensed users of the CCS C //// |
//// compiler. This source code may only be distributed to other //// |
//// licensed users of the CCS C compiler. No other use, reproduction //// |
//// or distribution is permitted without written permission. //// |
//// Derivative programs created using this software in object code //// |
//// form are not restricted in any way. //// |
/////////////////////////////////////////////////////////////////////////// |
#ifndef TOUCH_C |
#define TOUCH_C |
#ifndef TOUCH_PIN |
#define TOUCH_PIN PIN_B0 |
#endif |
#define TOUCH_PIN_LOW() output_drive(TOUCH_PIN); output_low(TOUCH_PIN) |
#define TOUCH_PIN_HIGH() output_drive(TOUCH_PIN); output_high(TOUCH_PIN) |
#define TOUCH_PIN_FLOAT() output_float(TOUCH_PIN) |
#define TOUCH_PIN_READ() input_state(TOUCH_PIN) |
///////////////////////////// |
//// //// |
//// Function Prototypes //// |
//// //// |
///////////////////////////// |
/* |
int1 touch_read_bit() |
This will read back a bit from the DS1993 |
PARAMS: none |
RETURNS: A bit from the DS1993 |
*/ |
int1 touch_read_bit(); |
/* |
BYTE touch_read_byte() |
This will read back a byte from the DS1993 |
PARAMS: none |
RETURNS: A byte from the DS1993 |
*/ |
BYTE touch_read_byte(); |
/* |
BOOLEAN touch_write_bit(int1 data) |
This will write a bit to the DS1993 |
PARAMS: The bit to write |
RETURNS: True if completed successfully, false if otherwise |
*/ |
BOOLEAN touch_write_bit(int1 data); |
/* |
BOOLEAN touch_write_byte(BYTE data) |
This will write a byte to the DS1993 |
PARAMS: The byte to write |
RETURNS: True if completed successfully, false if otherwise |
*/ |
BOOLEAN touch_write_byte(BYTE data); |
/* |
BOOLEAN touch_present() |
This will evaluate whether or not there is a touch present on the DS1993 |
PARAMS: none |
RETURNS: True if a touch is present, false if otherwise |
*/ |
BOOLEAN touch_present(); |
/* |
void reset_pulse() |
This will send the DS1993 a reset pulse |
PARAMS: none |
RETURNS: none |
*/ |
void reset_pulse(); |
////////////////////////////////// |
//// //// |
//// Function Implementations //// |
//// //// |
////////////////////////////////// |
/* |
int1 touch_read_bit() |
This will read back a bit from the DS1993 |
PARAMS: none |
RETURNS: A bit from the DS1993 |
*/ |
int1 touch_read_bit() |
{ |
int1 data; |
TOUCH_PIN_LOW(); |
delay_us(14); |
TOUCH_PIN_FLOAT(); |
delay_us(5); |
data = TOUCH_PIN_READ(); |
delay_us(100); |
toggle_dome(); |
return data; |
} |
/* |
BYTE touch_read_byte() |
This will read back a byte from the DS1993 |
PARAMS: none |
RETURNS: A byte from the DS1993 |
*/ |
BYTE touch_read_byte() |
{ |
BYTE i,data; |
for(i=1; i <= 8; ++i) |
shift_right(&data, 1, touch_read_bit()); |
return data; |
} |
/* |
BOOLEAN touch_write_bit(int1 data) |
This will write a bit to the DS1993 |
PARAMS: The bit to write |
RETURNS: True if completed successfully, false if otherwise |
*/ |
BOOLEAN touch_write_bit(int1 data) |
{ |
TOUCH_PIN_LOW(); |
delay_us(10); |
if(data) |
{ |
TOUCH_PIN_HIGH(); |
delay_us(10); |
if(!TOUCH_PIN_READ()) |
return FALSE; |
} |
else |
{ |
TOUCH_PIN_LOW(); |
delay_us(10); |
if(TOUCH_PIN_READ()) |
return FALSE; |
} |
delay_us(50); |
TOUCH_PIN_HIGH(); |
toggle_dome(); |
delay_us(50); |
return TRUE; |
} |
/* |
BOOLEAN touch_write_byte(BYTE data) |
This will write a byte to the DS1993 |
PARAMS: The byte to write |
RETURNS: True if completed successfully, false if otherwise |
*/ |
BOOLEAN touch_write_byte(BYTE data) |
{ |
BYTE i; |
for(i=1; i<=8; ++i) |
if(!touch_write_bit(shift_right(&data, 1, 0))) |
return FALSE; |
return TRUE; |
} |
/* |
BOOLEAN touch_present() |
This will evaluate whether or not there is a touch present on the DS1993 |
PARAMS: none |
RETURNS: True if a touch is present, false if otherwise |
*/ |
BOOLEAN touch_present() |
{ |
BOOLEAN present; |
TOUCH_PIN_LOW(); |
toggle_dome(); |
delay_us(100); |
toggle_dome(); |
delay_us(100); |
toggle_dome(); |
delay_us(100); |
toggle_dome(); |
delay_us(100); |
toggle_dome(); |
delay_us(100); |
toggle_dome(); |
TOUCH_PIN_FLOAT(); |
delay_us(5); |
if(!TOUCH_PIN_READ()) |
return FALSE; |
delay_us(65); |
toggle_dome(); |
present = !TOUCH_PIN_READ(); |
toggle_dome(); // Puvodne pauza 240us |
delay_us(100); |
toggle_dome(); |
delay_us(100); |
toggle_dome(); |
delay_us(30); |
toggle_dome(); |
return present; |
} |
/* |
void reset_pulse() |
This will send the DS1993 a reset pulse |
PARAMS: none |
RETURNS: none |
*/ |
void reset_pulse() |
{ |
TOUCH_PIN_LOW(); |
toggle_dome(); |
delay_us(100); |
toggle_dome(); |
delay_us(100); |
toggle_dome(); |
delay_us(100); |
toggle_dome(); |
delay_us(100); |
toggle_dome(); |
delay_us(100); |
toggle_dome(); |
TOUCH_PIN_FLOAT(); |
delay_us(5); |
while(!touch_present()); |
} |
#endif |
/Designs/MRAKOMER4/SW/2zone/dbloader.c |
---|
0,0 → 1,22 |
/*------------------- DUMMY BOOT LOADER --------------------------------------------*/ |
#define FLASH_BLOCK_SIZE 32 |
#define LOADER_RESERVED getenv("PROGRAM_MEMORY")-26*FLASH_BLOCK_SIZE |
#define BUFFER_LEN_LOD 46 |
#if FLASH_BLOCK_SIZE != getenv("FLASH_ERASE_SIZE")/2 |
#error Wrong length of the Flash Block Size. getenv("FLASH_ERASE_SIZE")/getenv("FLASH_WRITE_SIZE") |
#endif |
#BUILD(INTERRUPT=FLASH_BLOCK_SIZE) // Redirect Interrupt routine above first flash block |
#ORG 4,5 |
void JumpToTheInterrupt() // Jump to the Interrupt Handler |
{ #asm GOTO FLASH_BLOCK_SIZE #endasm } |
#ORG 6,FLASH_BLOCK_SIZE-1 {} // First Flash block is reserved |
#ORG LOADER_RESERVED,getenv("PROGRAM_MEMORY")-1 auto=0 |
#SEPARATE |
void dummy_main() // Main on the fix position |
{ |
reset_cpu(); |
} |
/Designs/MRAKOMER4/SW/2zone/irmrak4.h |
---|
0,0 → 1,21 |
#include <16F88.h> |
#device adc=8 |
#FUSES WDT //Watch Dog Timer |
#FUSES INTRC_IO //Internal RC Osc, no CLKOUT |
#FUSES PUT //Power Up Timer |
#FUSES NOMCLR //Master Clear pin used for I/O |
#FUSES NOBROWNOUT //No brownout reset |
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O |
#FUSES NOCPD //No EE protection |
#FUSES NOWRT //Program memory not write protected |
#FUSES NODEBUG //No Debug mode for ICD |
#FUSES NOPROTECT //Code not protected from reading |
#FUSES NOFCMEN //Fail-safe clock monitor disabled |
#FUSES NOIESO //Internal External Switch Over mode disabled |
#use delay(clock=8000000) |
#use rs232(baud=2400,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8) |
#define TOUCH_PIN PIN_B7 |
/Designs/MRAKOMER4/SW/2zone/smb.c |
---|
0,0 → 1,253 |
/************ SMB driver ************/ |
#define SA 0x00 // Slave Address (0 for single slave / 0x5A<<1 default) |
#define RAM_Access 0x00 // RAM access command |
#define RAM_Tobj1 0x07 // To1 address in the RAM |
#define RAM_Tobj2 0x08 // To2 address in the RAM |
#define RAM_Tamb 0x06 // Ta address in the RAM |
// High and Low level of clock |
#define HIGHLEV 40 // max. 50us |
#define LOWLEV 100 // max. 30ms |
#define TBUF 20 |
// SMBus control signals |
#define SCL PIN_B0 |
#define SDA PIN_B1 |
#define mSDA_HIGH() output_float(SDA); // SDA float |
#define mSDA_LOW() output_low(SDA); // SDA low |
#define mSCL_HIGH() output_float(SCL); // SCL float |
#define mSCL_LOW() output_low(SCL); // SCL low |
#define ACK 0 |
#define NACK 1 |
//********************************************************************************************** |
// START CONDITION ON SMBus |
//********************************************************************************************** |
//Name: START_bit |
//Function: Generate START condition on SMBus |
//Parameters: No |
//Return: No |
//Comments: Refer to "System Managment BUS(SMBus) specification Version 2.0" |
// or AN"SMBus communication with MLX90614" on the website www.melexis.com |
//********************************************************************************************** |
void SMB_START_bit(void) |
{ |
// disable_interrupts(GLOBAL); |
mSDA_HIGH(); // Set SDA line |
delay_us( TBUF ); // Wait a few microseconds |
mSCL_HIGH(); // Set SCL line |
delay_us( TBUF ); // Generate bus free time between Stop |
// and Start condition (Tbuf=4.7us min) |
mSDA_LOW(); // Clear SDA line |
delay_us( TBUF ); // Hold time after (Repeated) Start Condition. |
// After this period, the first clock is generated. |
// (Thd:sta=4.0us min) |
mSCL_LOW(); // Clear SCL line |
// enable_interrupts(GLOBAL); |
delay_us( TBUF ); // Wait a few microseconds |
} |
//********************************************************************************************* |
// STOP CONDITION ON SMBus |
//********************************************************************************************* |
//Name: STOPbit |
//Function: Generate STOP condition on SMBus |
//Parameters: No |
//Return: No |
//Comments: Refer to "System Managment BUS(SMBus) specification Version 2.0" |
// or AN"SMBus communication with MLX90614" on the website www.melexis.com |
//********************************************************************************************* |
void SMB_STOP_bit(void) |
{ |
// disable_interrupts(GLOBAL); |
mSDA_HIGH(); |
mSCL_LOW(); // Clear SCL line |
delay_us( TBUF ); // Wait a few microseconds |
mSDA_LOW(); // Clear SDA line |
delay_us( TBUF ); // Wait a few microseconds |
mSCL_HIGH(); // Set SCL line |
delay_us( TBUF ); // Stop condition setup time(Tsu:sto=4.0us min) |
mSDA_HIGH(); // Set SDA line |
// enable_interrupts(GLOBAL); |
} |
void SMB_send_bit(unsigned char bit_out) |
{ |
// disable_interrupts(GLOBAL); |
if(bit_out==0) {mSDA_LOW();} |
else {mSDA_HIGH();} |
delay_us(3); |
mSCL_HIGH(); // Set SCL line |
delay_us( HIGHLEV ); // High Level of Clock Pulse |
mSCL_LOW(); // Clear SCL line |
toggle_dome(); |
delay_us( LOWLEV ); // Low Level of Clock Pulse |
// mSDA_HIGH(); // Master release SDA line , |
// enable_interrupts(GLOBAL); |
toggle_dome(); |
return; |
} |
unsigned char SMB_Receive_bit(void) |
{ |
unsigned char Ack_bit; |
// disable_interrupts(GLOBAL); |
mSDA_HIGH(); //_SDA_IO=1; // SDA-input |
mSCL_HIGH(); // Set SCL line |
delay_us( HIGHLEV ); // High Level of Clock Pulse |
if(input(SDA)) Ack_bit=1; // \ Read acknowledgment bit, save it in Ack_bit |
else Ack_bit=0; // / |
mSCL_LOW(); // Clear SCL line |
toggle_dome(); |
delay_us( LOWLEV ); // Low Level of Clock Pulse |
// enable_interrupts(GLOBAL); |
toggle_dome(); |
return Ack_bit; |
} |
//********************************************************************************************* |
// TRANSMIT DATA ON SMBus |
//********************************************************************************************* |
//Name: TX_byte |
//Function: Send a byte on SMBus |
//Parameters: TX_buffer ( the byte which will be send on the SMBus ) |
//Return: Ack_bit ( acknowledgment bit ) |
//Comments: Sends MSbit first |
//********************************************************************************************* |
unsigned char SMB_TX_byte(unsigned char Tx_buffer) |
{ |
unsigned char Bit_counter; |
unsigned char Ack_bit; |
unsigned char bit_out; |
for(Bit_counter=8; Bit_counter; Bit_counter--) |
{ |
if(Tx_buffer&0x80) bit_out=1; // If the current bit of Tx_buffer is 1 set bit_out |
else bit_out=0; // else clear bit_out |
SMB_send_bit(bit_out); // Send the current bit on SDA |
Tx_buffer<<=1; // Get next bit for checking |
} |
Ack_bit=SMB_Receive_bit(); // Get acknowledgment bit |
return Ack_bit; |
} |
//********************************************************************************************* |
// RECEIVE DATA ON SMBus |
//********************************************************************************************* |
//Name: RX_byte |
//Function: Receive a byte on SMBus |
//Parameters: ack_nack (ackowlegment bit) |
//Return: RX_buffer(Received byte) |
//Comments: MSbit is received first |
//********************************************************************************************* |
unsigned char SMB_RX_byte(unsigned char ack_nack) |
{ |
unsigned char RX_buffer; |
unsigned char Bit_Counter; |
for(Bit_Counter=8; Bit_Counter; Bit_Counter--) |
{ |
if(SMB_Receive_bit()) // Get a bit from the SDA line |
{ |
RX_buffer <<= 1; // If the bit is HIGH save 1 in RX_buffer |
RX_buffer |=0b00000001; |
} |
else |
{ |
RX_buffer <<= 1; // If the bit is LOW save 0 in RX_buffer |
RX_buffer &=0b11111110; |
} |
} |
SMB_send_bit(ack_nack); // Sends acknowledgment bit |
return RX_buffer; |
} |
unsigned char PEC_calculation(unsigned char pec[]) // CRC calculation |
{ |
unsigned char crc[6]; |
unsigned char BitPosition=47; |
unsigned char shift; |
unsigned char i; |
unsigned char j; |
unsigned char temp; |
do |
{ |
crc[5]=0; /* Load CRC value 0x000000000107 */ |
crc[4]=0; |
crc[3]=0; |
crc[2]=0; |
crc[1]=0x01; |
crc[0]=0x07; |
BitPosition=47; /* Set maximum bit position at 47 */ |
shift=0; |
//Find first 1 in the transmited message |
i=5; /* Set highest index */ |
j=0; |
while((pec[i]&(0x80>>j))==0 && i>0) |
{ |
BitPosition--; |
if(j<7) |
{ |
j++; |
} |
else |
{ |
j=0x00; |
i--; |
} |
toggle_dome(); |
} |
shift=BitPosition-8; /*Get shift value for crc value*/ |
//Shift crc value |
while(shift) |
{ |
for(i=5; i<0xFF; i--) |
{ |
if((crc[i-1]&0x80) && (i>0)) |
{ |
temp=1; |
} |
else |
{ |
temp=0; |
} |
crc[i]<<=1; |
crc[i]+=temp; |
} |
shift--; |
toggle_dome(); |
} |
//Exclusive OR between pec and crc |
for(i=0; i<=5; i++) |
{ |
pec[i] ^=crc[i]; |
} |
} while(BitPosition>8); |
return pec[0]; |
} |