No changes between revisions
/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.PJT
0,0 → 1,46
[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=irmrak4.h
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=dbloader.c
9=
[Units]
Count=1
1=irmrak4 (main)
/Designs/MRAKOMER4/SW/2zone/irmrak4.c
0,0 → 1,252
/**** 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("\n\r\n\r# Mrakomer %s (C) 2007 KAKL\n\r",VER); // Welcome message
printf("#%s\n\r",&REV[4]);
printf("#\n\r");
printf("# h - Switch On Heating for 20s.\n\r");
printf("# c - Need Colder. Switch Off Heating.\n\r");
printf("# o - Open the Dome for 20s.\n\r");
printf("# l - Lock the Dome.\n\r");
printf("# x - Open the Dome and switch On Heating.\n\r");
printf("# i - Print this Information.\n\r");
printf("# r - Repeat measure every second.\n\r");
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");
//---WDT
restart_wdt();
}
 
 
#include "smb.c" // System Management Bus driver
 
 
// 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;
}
 
 
/*-------------------------------- MAIN --------------------------------------*/
void main()
{
unsigned int16 seq, temp, tempa;
signed int16 ta, to1, to2;
int8 safety_counter;
int1 repeat;
 
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;
 
welcome();
 
tempa=ReadTemp(SA, RAM_Tamb); // Dummy read
temp=ReadTemp(SA, RAM_Tobj1);
 
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
break;
 
case 'c':
heat=0; // Need colder
break;
 
case 'o':
open=MAXOPEN; // Open the dome
break;
 
case 'x':
open=MAXOPEN; // Open the dome
heat=MAXHEAT; // Need heating
break;
 
case 'l':
open=0; // Lock the dome
break;
 
case 'i':
if (open==0) welcome(); // Information about version, etc...
break; // Only when dome is closed
 
case 'r':
repeat=TRUE; // Repeated measure mode
break;
 
case 's':
repeat=FALSE; // Single measure mode
break;
 
case 'u':
reset_cpu(); // Update firmware
}
}
// while(kbhit()) getc(); // Flush USART buffer
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);
to1=temp*2-27315;
temp=ReadTemp(SA, RAM_Tobj2);
to2=temp*2-27315;
 
{ // 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 ",VER);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"%Lu ", seq);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"%Ld ", ta);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"%Ld ", to1);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"%Ld ", to2);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"%u ", heat);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"%u ", open);
j=0; while(output[j]!=0) { delay(SEND_DELAY); putc(output[j]); check^=output[j++]; }
sprintf(output,"*%X\n\r\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
Property changes:
Added: svn:keywords
+Id
\ No newline at end of property
/Designs/MRAKOMER4/SW/2zone/irmrak4.h
0,0 → 1,19
#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)
 
/Designs/MRAKOMER4/SW/2zone/irmrak4.hex
0,0 → 1,287
:0C00000008308A000028000020280800BA
:100040008A068A0623104D39E135EF366539A0124C
:100050007310A82129103218B01BA025C1254C050A
:100060000D00231068102D10D33B693A6334A0278C
:100070006E10C832613A69376710E637721032186D
:1000800073178A060000231063102D10CE326532DC
:10009000A0216F36E4327217A029F734F4316810CA
:1000A0004F336610C832613A693767178A06000114
:1000B00023106F102D104F386537203AE832202278
:1000C000EF366510E6377210321873178A06000192
:1000D00023106C102D10CC37E335203AE832202263
:1000E000EF3665178A060001231078102D104F385F
:1000F0006537203AE8322022EF3665106137641008
:10010000F33B693A6334A0276E10C832613A69370D
:1001100067178A060001231069102D1050396937BE
:1001200074107434E939A0246E336F39ED30F4342F
:100130006F372E050D00231072102D10D232F032C1
:10014000613AA036E530F33AF232A032F632F23CB0
:10015000A039E5316F3764178A0600012310731048
:100160002D10D334EE33EC32A036E530F33AF232D0
:100170002E050D00231075102D105538E430F43283
:1001800020336939ED3B61396517A0236F10F437CF
:10019000203AE8322021EF377410CC3761326539CC
:1001A0002E050D002310BC39E538F532EE31651F00
:1001B000201EE136E2346537F42DB11731183010C6
:1001C000C32E3E10BC306D31E9326E3ADB18AF18E9
:1001D0003018A0215D1F201EF335F92DB1173118FD
:1001E0003010C32E3E1000013C34E530F434EE33C1
:1001F000DB395D1F201EE437ED32DB395D1F201E29
:100200006334E5316B1F8A068A060000443084009F
:1002100083130008031919290230F800F701F70BBE
:100220000F29F80B0E299730F700F70B1529800BD3
:100230000C2908007608FC007508FB007C08FA0011
:100240007B08840083137A188317800803192C29EC
:10025000FB0A0319FC0A1E2975087B02F7007C08BB
:10026000FA007608031C760FFA027708F8000800F7
:10027000831603178C170C140000000003185A296A
:1002800083120C087F39FB000D08FC000F08FD00ED
:100290007B0803130C1E4A2999007C0803178D0064
:1002A0007D088F0083168C170C1400000000F50BDE
:1002B0005A29772983120C0D0E0D7F39FB000D088A
:1002C000FC000F08FD007B0803130C1E6529990034
:1002D0007C0803178D007D088F008D0A03198F0A93
:1002E0000310F50B7429762903133829831683121A
:1002F00003130800800803199029F6010408F5008B
:100300007610831B761400080C1E8429990075084A
:100310008400831376188317840A0319850A7A29BF
:100320000800831603178C170C14000000008312BA
:100330000C087F390319CB29FB000D08FC000F08BE
:10034000FD007B0803130C1EA32999007C080317EA
:100350008D007D088F0083168C170C1400000000A0
:1003600083120C0D0E0D7F390319CB29FB000D08EC
:10037000FC000F08FD007B0803130C1EBD2999002B
:100380007C0803178D007D088F008D0A03198F0AE2
:10039000031391290317031308002430C3004930C5
:1003A000C4006430C5003A30C6002030C700693050
:1003B000C8007230C9006D30CA007230CB006130A5
:1003C000CC006B30CD003430CE002E30CF00633007
:1003D000D0002030D1003130D2003330D300303063
:1003E000D4003630D5002030D6003230D70030303F
:1003F000D800D9003930DA002D30DB003030DC0095
:100400003130DD002D30DE003130DF003730E000EC
:100410002030E1003130E2003230E3003A30E400D5
:100420003230E5003530E6003A30E7003430E8009D
:100430003030E9005A30EA002030EB006B30EC003D
:100440006130ED006B30EE006C30EF002030F000DA
:100450002430F100F201F6014330F5001A21013099
:100460007802433E840083130008243C031D422A83
:10047000F6014330F5001A2101307802433E840032
:1004800083138001203003178D0000308F0003108C
:100490000F30F500031338212230840083137A21B2
:1004A000283003178D0000308F0003141030F50042
:1004B0000313382123300C1E5B2A99004730840037
:1004C00083137A210A300C1E632A99000D300C1E0A
:1004D000672A990023300C1E6B2A99000A300C1EE3
:1004E0006F2A99000D300C1E732A990031300317C2
:1004F0008D0000308F0003139121433003178D00CE
:1005000000308F0003139121583003178D00003005
:100510008F0003139121683003178D0000308F0086
:1005200003139121743003178D0000308F000313E3
:1005300091218B3003178D0000308F000313912120
:100540009B3003178D0000308F0003139121AE30D4
:1005500003178D0000308F0003139121BA30031769
:100560008D0000308F000313912123300C1EB62A1A
:1005700099000A300C1EBA2A99000D300C1EBE2AB2
:100580009900D23003178D0000308F0003139121A2
:10059000F43003178D0000308F00031391216400A5
:1005A0000800831686140610831206100D30F7001B
:1005B000F70BD82A83168610831286100D30F700A9
:1005C000F70BE02A831606140D30F700F70BE62A26
:1005D000861483120800831686140D30F700F70B7B
:1005E000EF2A06140D30F700F70BF42A8610831259
:1005F00086100D30F700F70BFB2A831606108312C6
:1006000006100D30F700F70B032B0800D308031D6D
:100610000E2B8316861083128610112B83168614D8
:100620008312122B132B142B831606141A30F70087
:10063000F70B182B0000061083120610A7080319E9
:10064000272B831606121030831286062B2B831657
:100650000612831206164230F700F70B2D2B00000E
:10066000A7080319392B8316061210308312860649
:100670003D2B831606128312061608008316861475
:1006800006141A30F700F70B432B00008614831270
:10069000861C4D2B0130D3004E2BD3018316061040
:1006A00083120610A70803195B2B8316061210305D
:1006B000831286065F2B83160612831206164230BB
:1006C000F700F70B612B0000A70803196D2B8316A9
:1006D0000612103083128606712B831606128312BF
:1006E00006165308F80008000830D000D008031997
:1006F000862BCF1F7E2B0130D2007F2BD2015208D8
:10070000D30006230310CF0DD003762B3E237808A9
:10071000D1005108F80008000830D000D0080319B3
:100720009E2B3E23F8080319992B0310CF0D4F146D
:100730009C2B0310CF0D4F10D0038E2B4E08D300EF
:1007400006234F08F80008000310C30DD122EB2246
:100750004308CF0074234408CE00CF007423EB225B
:100760004308CF007423CE018C237808C700CE0144
:100770008C237808C6004608CD004708CC0001301D
:10078000CE008C237808CB00D1224308CA0044084D
:10079000C9004308C800C501CF014530CE002F3045
:1007A000D600D501D401D301D2010130D1000730E8
:1007B000D0002F30D600D7010530D800D901580815
:1007C0004E07840083134F1883170008DB00803026
:1007D000F7005908F8000319F12B0310F70CF80B78
:1007E000ED2B77085B05031D0F2CD80803190F2C80
:1007F000D6035908063C031CFF2BD90A012CD9014A
:10080000D803A70803190A2C831606121030831286
:1008100086060E2C8316061283120616DF2B08306E
:100820005602D700D7080319472C0530D800580FB7
:100830001A2C382C01305802503E84008313801F3C
:10084000272CD8080319272C0130DA00282CDA01CC
:1008500050305807840083130310000D800050307F
:100860005807840083135A0800078000D803172C08
:10087000D703A7080319422C8316061210308312DF
:100880008606462C8316061283120616122CD801F1
:100890005808053C031C6A2C58084E07F8004F08FE
:1008A000FA000318FA0A7808840083137A18831769
:1008B0000008DD00503058078400831300085D06EF
:1008C000DD007808840083137A1883175D088000A0
:1008D000D80A482C5608083C031CD12B4E0884002B
:1008E00083134F1883170008F80078084B02031988
:1008F0007B2CCD01CC014C08F8004D08F900080014
:10090000C601C50146084402031CA22C031D8C2C01
:10091000430845020318A22CA7080319952C831637
:100920000612103083128606992C83160612831243
:1009300006164230F700F70B9B2C0000C50A03197E
:10094000C60A822C080028088400831329188317FC
:100950004C088000840A8001A80A0319A90A08002B
:1009600080080319C52CC4010408C3004410831B6C
:1009700044140008CC00A3244308840083134418C3
:100980008317840A0319850AB02C8A152529CB01FF
:100990000408CA004B10831B4B14440EF038C600E9
:1009A000C607E23EC700323EC90044080F39C707F8
:1009B000C707C907E93EC800C807C807430E0F3973
:1009C000C807C907C80DC90DC909C90D43080F39A2
:1009D000C907C60D0730C5000A30C907C803031C84
:1009E000ED2CC807C703031CF12CC707C603031C63
:1009F000F52CC607C503031CF92C4530840083136E
:100A000007304A054A1384074930040203194A177C
:100A10000008F700031D142D4A1B142D4A1A262D19
:100A2000CA19142D2030172DCA154A123030F70775
:100A3000C4010408C3004410831B44147708CC008D
:100A4000A32443088400831344188317840A4A1F8D
:100A5000042D8A155629CB010408CA004B10831BAC
:100A60004B14C41F3B2DCA174A1ECA0AC309C40926
:100A7000C30A0319C40A440EF038C600C607E23E92
:100A8000C700323EC90044080F39C707C707C90766
:100A9000E93EC800C807C807430E0F39C807C90791
:100AA000C80DC90DC909C90D43080F39C907C60DBD
:100AB0000730C5000A30C907C803031C5B2DC807EF
:100AC000C703031C5F2DC707C603031C632DC6079E
:100AD000C503031C672D45308400831307304A0586
:100AE0004A1384034A05031D7C2D4A1A840A4A1AB4
:100AF0007C2D2030F700992D84074930040203191A
:100B00004A170008F700031D8D2D4A1B8D2D4A1A28
:100B1000A72DCA198D2D2030982DCA1F952D2D3047
:100B2000F70084034A13CA13992DCA154A123030AC
:100B3000F707C4010408C3004410831B441477085A
:100B4000CC00A32443088400831344188317840A29
:100B50004A1F7D2D08004608F80145020318B32DF1
:100B60004508F700BF2DF7010830C700C50DF70D88
:100B7000460877020318F700F80DC70BB62D0800DA
:100B800078084308C5006430C600AB257708C30069
:100B900078083030031DD32DC41CDA2DC419DA2D8A
:100BA000441A2030D62DC41144124414F807780892
:100BB000CC00A3244308C5000A30C600AB25770843
:100BC000C30078083030031DEB2DC419EF2D441CF1
:100BD000EF2D441A2030F8077808CC00A3243030D9
:100BE000C3074308CC00A3240800C41B072E0F3002
:100BF000F700430EF7050A3077020318022E303053
:100C0000F707042E4408F7077708CC00A3240F3019
:100C1000C3050A30430203180F2E3030112EC413BF
:0E0C20004408C3074308CC00A3248A157B2A8E
:10100000840183131F308305723083168F000F080D
:1010100033309900A23098009030831298008316E4
:101020001F129F121B0880399B0007309C008312FF
:10103000A001A1013430A2002E30A3003130A40061
:10104000A501A801A90183160612831206168316AC
:101050008611831286110430C300FA30C4008A114D
:1010600006218A15C30B2D286400AB01AA01A60135
:10107000A70137148A11CD218A15C3010630C40097
:101080008A11A4238A157908AF007808AE00C3013D
:101090000730C4008A11A4238A157908AD007808A6
:1010A000AC000430C300FA30C4008A1106218A154E
:1010B000C30B532864005A30B6003608593C031855
:1010C000B60AC4016430C3008A1180248A15360828
:1010D000593C03187F28A608031DA603A708031D73
:1010E000A703A6080319792883168611831286158B
:1010F0007D288316861183128611B60164008C1A2E
:101100008328371C5D2864006B30B8008C1E8C2847
:101110008C1E88281A08B80063303802EA3E03188B
:10112000AE28163EB12A1430A600AE28A601AE287D
:101130001430A700AE281430A700A600AE28A701DF
:10114000AE28A708031DA7288A11CD218A15AE282D
:101150003714AE283710AE288A0100281812181646
:10116000AA0A0319AB0AC3010630C4008A11A423DA
:101170008A157908AF007808AE0003102E0DC30061
:101180002F0DC400B3304302F7004408FA006A3060
:10119000031C6B30FA027708B0007A08B100C30173
:1011A0000730C4008A11A4238A157908AD00780895
:1011B000AC0003102C0DC3002D0DC400B33043024E
:1011C000F7004408FA006A30031C6B30FA02770813
:1011D000B2007A08B300C3010830C4008A11A42306
:1011E0008A157908AD007808AC0003102C0DC300F7
:1011F0002D0DC400B3304302F7004408FA006A30F2
:10120000031C6B30FA027708B4007A08B500C201FB
:10121000C4013230C3008A1180248A1524300C1E88
:101220000F299900C4013230C3008A1180248A1525
:10123000A9013930A8004D30CC008A11A3248A15A9
:101240002230840083138A11B02C8A152030CC0000
:101250008A11A3248A15C101393041078400831300
:10126000800803194B29C4013230C3008A1180243D
:101270008A1539304107840083130008C3004308EE
:101280000C1E402999004108C10A393E840083138D
:101290000008C2062C29A9013930A80010308400AA
:1012A0002B08C4002A08C3008A11C72C8A152030D5
:1012B000CC008A11A3248A15C1013930410784006A
:1012C0008313800803197C29C4013230C3008A11BA
:1012D00080248A1539304107840083130008C30035
:1012E00043080C1E712999004108C10A393E840047
:1012F00083130008C2065D29A9013930A800103007
:1013000084003108C4003008C3008A112B258A15D7
:101310002030CC008A11A3248A15C101393041073D
:101320008400831380080319AD29C4013230C3003F
:101330008A1180248A1539304107840083130008FC
:10134000C30043080C1EA22999004108C10A393E76
:10135000840083130008C2068E29A9013930A80031
:10136000103084003308C4003208C3008A112B25D2
:101370008A152030CC008A11A3248A15C101393086
:1013800041078400831380080319DE29C401323029
:10139000C3008A1180248A153930410784008313E1
:1013A0000008C30043080C1ED32999004108C10A54
:1013B000393E840083130008C206BF29A9013930D1
:1013C000A800103084003508C4003408C3008A1116
:1013D0002B258A152030CC008A11A3248A15C1013F
:1013E0003930410784008313800803190F2AC40190
:1013F0003230C3008A1180248A15393041078400B5
:1014000083130008C30043080C1E042A99004108F6
:10141000C10A393E840083130008C206F029A901DD
:101420003930A8002608C3001B30C4008A11C0252B
:101430008A152030CC008A11A3248A15C1013930C5
:10144000410784008313800803193E2AC401323007
:10145000C3008A1180248A15393041078400831320
:101460000008C30043080C1E332A99004108C10A32
:10147000393E840083130008C2061F2AA9013930AF
:10148000A8002708C3001B30C4008A11C0258A1594
:101490002030CC008A11A3248A15C10139304107BC
:1014A00084008313800803196D2AC4013230C300FD
:1014B0008A1180248A15393041078400831300087B
:1014C000C30043080C1E622A99004108C10A393E34
:1014D000840083130008C2064E2AA9013930A800EF
:1014E0002A30CC008A11A3248A154208C300373061
:1014F000C4008A11F52D8A150A30CC008A11A32464
:101500008A150D30CC008A11A3248A15C101393007
:1015100041078400831380080319A02AC4013230D4
:10152000C3008A1180248A154108C10A393E84000B
:1015300083130008C30043080C1E9C2A9900872AC5
:10154000C4013230C3008A1180248A156400173028
:10155000C4007030C3008A1180248A1564005B289F
:1015600063000A108A140A1182079628AE28AE2852
:10157000AE28AE289328A128AE28AE289F28AE28F2
:10158000AE289828AE28AE28A828AA28AE28AC28CD
:06159000AE28AE289B28E6
:061980008A0100280800A6
:04400E00143FFC3F20
:00000001FF
;PIC16F88
;CRC=6FFD CREATED="25-VIII-10 20:37"
/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];
}
/Designs/MRAKOMER4/SW/setcidla/main.h
1,19 → 1,19
#include <16F88.h>
#include <16F877A.h>
#device adc=8
 
#FUSES NOWDT //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
#FUSES NOWDT //No Watch Dog Timer
#FUSES HS //High speed Osc (> 4mhz)
#FUSES NOPUT //No Power Up Timer
#FUSES NOPROTECT //Code not protected from reading
#FUSES NODEBUG //No Debug mode for ICD
#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
 
#use delay(clock=4000000)
#use rs232(baud=2400,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8)//,FORCE_SW)
#use i2c(MASTER,SLOW,sda=PIN_B1,scl=PIN_B4,SMBUS)
#use delay(clock=20000000) // 14318180)
//#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8) // Pro USART
#use rs232(baud=9600,parity=N,bits=8,xmit=PIN_B7,rcv=PIN_B6) // Pro PICkit2
 
#use i2c(Master,Fast,sda=PIN_C4,scl=PIN_C3,SMBUS)
 
/Designs/MRAKOMER4/SW/setcidla/main.pjt
1,7 → 1,7
[PROJECT]
Target=main.hex
Development_Mode=
Processor_Text=PIC16F877
Processor_Text=PIC16F88
ToolSuite=CCS
Processor=0x688F
[main]
16,7 → 16,7
[Windows]
0=0000 %S 0 0 796 451 3 0
[Opened Files]
1=C:\Dokumenty\MLAB\Designs\MRAKOMER4\SW\setcidla\main.c
1=main.c
2=
3=
[Target Data]
24,4 → 24,4
FileList=C:\Dokumenty\MLAB\Designs\MRAKOMER4\SW\setcidla\main.c
[Units]
Count=1
1=C:\Dokumenty\MLAB\Designs\MRAKOMER4\SW\setcidla\main.c (main)
1=main (main)