/Designs/MRAKOMER2/SW/Ondrejov/irmrak.PJT |
---|
1,8 → 1,9 |
[PROJECT] |
Target=irmrak.HEX |
Target=irmrak.hex |
Development_Mode= |
Processor=0x688F |
ToolSuite=CCS |
Processor_Text=PIC16F88 |
[Directories] |
Include=C:\Program Files\PICC\devices\;C:\Program Files\PICC\drivers\; |
10,7 → 11,7 |
LinkerScript= |
[Target Data] |
FileList=C:\PIC\IRmrakO\irmrak.c |
FileList=C:\Dokumenty\MLAB\Designs\MRAKOMER2\SW\Ondrejov\irmrak.c |
BuildTool=C-COMPILER |
OptionString=+FM |
AdditionalOptionString= |
28,16 → 29,16 |
1=irmrak.c |
[Windows] |
0=0000 irmrak.c 0 0 796 451 3 0 |
0=0000 %S 0 0 796 451 3 0 |
[Opened Files] |
1=C:\PIC\IRmrakO\irmrak.c |
2= |
3=C:\Program Files\PICC\devices\16F88.h |
4=C:\Program Files\PICC\drivers\string.h |
5=C:\Program Files\PICC\drivers\stddef.h |
6=C:\Program Files\PICC\drivers\ctype.h |
7=C:\PIC\IRmrakTX\AX25.c |
1=irmrak.c |
2=irmrak.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= |
8= |
[debugperif] |
selected=Analog/Digital Conv |
54,6 → 55,23 |
[debugexpr] |
expr= |
sideeffects=0 |
[defines] |
enabled=0 |
D1= |
V1= |
[fileformats] |
forcecoff=0 |
debug=4 |
error=2 |
object=0 |
list=0 |
scratch=0 |
sta=1 |
tre=1 |
allerrors=1 |
allwarnings=1 |
stayupne=3 |
stayupoe=0 |
[Units] |
Count=1 |
1=C:\PIC\IRmrakO\irmrak.c (main) |
1=irmrak (main) |
/Designs/MRAKOMER2/SW/Ondrejov/motor/irmrak.PJT |
---|
0,0 → 1,44 |
[PROJECT] |
Target=irmrak.HEX |
Development_Mode=2 |
Processor=0x688F |
Processor_Text=PIC16F88 |
ToolSuite=CCS |
[Directories] |
Include= |
Library= |
LinkerScript= |
[Target Data] |
FileList=C:\Dokumenty\MLAB\Designs\MRAKOMER2\SW\Ondrejov\motor\irmrak.c |
BuildTool=C-COMPILER |
OptionString=+FM |
AdditionalOptionString= |
BuildRequired=1 |
[irmrak.c] |
Type=4 |
Path= |
FileList= |
BuildTool= |
OptionString= |
AdditionalOptionString= |
[mru-list] |
1=irmrak.c |
[Windows] |
0=0000 irmrak.c 0 0 796 451 3 0 |
[Opened Files] |
1=irmrak.c |
2=irmrak.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= |
[Units] |
Count=1 |
1=irmrak (main) |
/Designs/MRAKOMER2/SW/Ondrejov/motor/irmrak.c |
---|
0,0 → 1,157 |
//******** Mrakomer2 - stepper motor control ***************** |
#define VERSION "3.0" // Special version for BART |
#define ID "$Id: irmrak.c 420 2006-12-29 21:43:11Z kakl $" |
//************************************************************ |
#include "irmrak.h" |
#include <string.h> |
char VER[4]=VERSION; |
char REV[50]=ID; |
#bit CREN = 0x18.4 // USART registers |
#bit SPEN = 0x18.7 |
#bit OERR = 0x18.1 |
#bit FERR = 0x18.2 |
#define HALL PIN_A4 // Hallova sonda pro zjisteni natoceni dolu |
// vykonovy FET je na RB3 (vystup PWM) |
int port; // stav brany B pro krokove motory |
int j; // pro synchronisaci fazi |
unsigned int8 uhel; // prijaty znak |
unsigned int8 i; // pro cyklus for |
// --- Kroky krokoveho motoru --- |
void krok(int n) |
{ |
while((n--)>0) |
{ |
if (1==(j&1)) {port^=0b11000000;} else {port^=0b00110000;}; |
output_B(port); |
delay_ms(20); // Nutno nastavit podle dynamiky systemu. |
j++; |
} |
} |
// --- Dojet dolu magnetem na cidlo --- |
void dolu() |
{ |
unsigned int8 err; // pocitadlo pro zjisteni zaseknuti otaceni |
err=0; |
while(!input(HALL)) // otoceni trubky dolu az na hall |
{ |
krok(1); |
err++; |
if(40==err) // do 40-ti kroku by se melo podarit otocit dolu |
{ |
output_B(0); // vypnuti motoru |
printf("E"); // Hlasime chybu |
err=0; |
} |
}; |
delay_ms(500); // cas na ustaleni trubky |
output_B(0); // vypnuti motoru |
} |
// --- Najeti na vychozi polohu dole --- |
void nula() |
{ |
port=0b10100000; // vychozi nastaveni fazi pro rizeni motoru |
output_B(port); |
j=0; // smer dolu |
delay_ms(500); |
} |
//------------------------------------------------ |
void main() |
{ |
setup_oscillator(OSC_8MHZ|OSC_INTRC); // 8 MHz interni RC oscilator |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
setup_adc(ADC_OFF); |
setup_spi(FALSE); |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
setup_timer_1(T1_DISABLED); |
setup_ccp1(CCP_OFF); |
setup_comparator(NC_NC_NC_NC); |
setup_vref(FALSE); |
output_B(0); // vypnuti motoru a topeni |
set_tris_B(0b00000111); // faze a topeni jako vystupy |
while(true) |
{ |
nula(); |
dolu(); // otoc trubku do vychozi pozice dolu |
CREN=0; CREN=1; // Reinitialise USART |
while(!kbhit()) |
{ |
if (!input(HALL)) // znovuotoceni trubky dolu, kdyby ji vitr otocil |
{ |
dolu(); |
} |
}; // pokracuj dal, kdyz prisel po RS232 znak |
uhel=getc(); // prijmi znak |
if ('m'==uhel) // standardni mereni ve trech polohach |
{ |
nula(); |
j++; // reverz, nahoru |
krok(18); |
printf("A"); // mereni teploty 45° nad obzorem |
delay_ms(200); |
krok(7); |
printf("B"); // mereni teploty v zenitu |
delay_ms(200); |
krok(7); |
printf("C"); // mereni teploty 45° nad obzorem na druhou stranu |
delay_ms(200); |
j++; // reverz |
dolu(); |
printf("G"); // mereni teploty Zeme (<G>round) |
continue; |
} |
if ('i'==uhel) {printf("I"); continue;} // Predani prikazu pro Info |
if ('h'==uhel) {printf("H"); continue;} // Predani prikazu pro Topeni |
if ('c'==uhel) {printf("C"); continue;} // Predani prikazu pro vypnuti topeni |
if ('x'==uhel) // Zjisteni verze FW |
{ |
printf("Mrakomer - Motor V%s (C) 2006 KAKL\n\r", VER); |
printf("%s\n\r", REV); |
} |
if ((uhel>='0') && (uhel<='@')) // mereni v pozadovanem uhlu [0..;]=(0..11) |
{ |
uhel-='0'; |
}; |
if(uhel>11) continue; // ochrana, abysme neukroutili draty |
nula(); |
j++; // reverz, nahoru |
krok(12); // odkrokuj do roviny |
for(i=0; i<uhel; i++) // dale odkrokuj podle pozadovaneho uhlu |
{ |
krok(2); |
}; |
printf("S"); |
delay_ms(200); |
j++; // reverz |
dolu(); |
printf("G"); // mereni teploty Zeme (<G>round) |
} |
} |
/Designs/MRAKOMER2/SW/Ondrejov/motor/irmrak.h |
---|
0,0 → 1,6 |
#include <16F88.h> |
#device adc=8 |
#fuses NOWDT,INTRC_IO, NOPUT, NOMCLR, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG, NOPROTECT, NOFCMEN, NOIESO, CCPB3 |
#use delay(clock=8000000) |
#use rs232(baud=2400,parity=N,xmit=PIN_A6,rcv=PIN_A7,bits=8) |
/Designs/MRAKOMER2/SW/Ondrejov/motor/irmrak.hex |
---|
0,0 → 1,84 |
:1000000001308A00392900004D39E135EF36653974 |
:10001000A016A0266F3A6F392010D6127310A821AF |
:1000200029103218301BA025C1254C050D005E306B |
:1000300084008313000803192A280230F800F7010E |
:10004000F70B2028F80B1F289730F700F70B26280E |
:10005000800B1D280800A030D8008316860183126B |
:1000600058088600D9010230DC00FA30DE00172083 |
:10007000DC0B352808005D08DD03003A031954281D |
:1000800059080139013C031D4828C030D8064A28C8 |
:100090003030D80683168601831258088600143043 |
:1000A000DE001720D90A3B280800831605138312A7 |
:1000B00005130830F8005C280000F8176D28F813C5 |
:1000C000E00C03180517031C051378176D28781327 |
:1000D000F80B60286B28000005170130F700840139 |
:1000E000840B7028F70B6F280E308400840B762861 |
:1000F0000000F81B5F28781B67280800DC018316C6 |
:1001000005168312051A95280130DD003B20DC0A14 |
:100110005C08283C031D94288316860183128601FF |
:100120004530E0005520DC017F280230DD00FA3048 |
:10013000DE001720DD0B97288316860183128601C7 |
:1001400008000408F800831685178312851BA6286B |
:100150000830F700DC01F717BD28F713BD2803109E |
:10016000851B0314DC0C7717BD287713F70BAF281A |
:10017000780884005C08F800D22801308400003040 |
:10018000F71B5530F800F80BC328840BBF280D303F |
:10019000F71B0330F800F80BCB28F71BAD28771BB3 |
:1001A000B528AF288A11EA29831603178C170C1477 |
:1001B000000000000318032983120C087F39031381 |
:1001C000DD0003170D080313DE0003170F080313E8 |
:1001D000DF005D08E00055205E0803178D00031363 |
:1001E0005F0803178F0083168C170C1400000000A3 |
:1001F00083120313DC0BFD28002983160317032940 |
:1002000022298316031783120C0D0E0D7F39031359 |
:10021000DD0003170D080313DE0003170F08031397 |
:10022000DF005D08E00055205E0803178D00031312 |
:100230005F0803178F008D0A03198F0A0310031339 |
:10024000DC0BD4280800800803193829DD010408D4 |
:10025000DC005D10831B5D140008E00055205C0885 |
:10026000840083135D188317840A0319850A2329E0 |
:100270000800840183131F308305723083168F00BA |
:100280000F0805138312051783161F129F121B08F0 |
:1002900080399B0007309C008312A001A1013330FC |
:1002A000A2002E30A3003030A400A5012430A60007 |
:1002B0004930A7006430A8003A30A9002030AA00D5 |
:1002C0006930AB007230AC006D30AD007230AE0002 |
:1002D0006130AF006B30B0002E30B1006330B2003F |
:1002E0002030B3003430B4003230B5003030B600C6 |
:1002F0002030B7003230B8003030B900BA003630A4 |
:10030000BB002D30BC003130BD003230BE002D307E |
:10031000BF003230C0003930C1002030C20032305E |
:10032000C3003130C4003A30C5003430C600333029 |
:10033000C7003A30C8003130C900CA005A30CB007B |
:100340002030CC006B30CD006130CE006B30CF0060 |
:100350006C30D0002030D1002430D200D301723074 |
:1003600083168F000F081F129F121B0880399B00F5 |
:1003700083121F10940183160108C73908388100C1 |
:100380008312900183168615831297010730831616 |
:100390009C00050885000630F700F70BCD2900000A |
:1003A0001C0883120D1383169D018601831286019A |
:1003B00007308316860083122B207E201812181611 |
:1003C000851FE929831605168312051AE8297E2060 |
:1003D000E029A1287808DA005A086D3C031D132A89 |
:1003E0002B20D90A1230DD003B204130E00055209F |
:1003F000C830DE0017200730DD003B204230E0002F |
:100400005520C830DE0017200730DD003B20433088 |
:10041000E0005520C830DE001720D90A7E20473082 |
:10042000E0005520DC295A08693C031D1B2A49308D |
:10043000E0005520DC295A08683C031D232A483077 |
:10044000E0005520DC295A08633C031D2B2A433069 |
:10045000E0005520DC295A08783C031D512A04305D |
:1004600003178D0000308F00031013300313DC00DE |
:10047000D42022308400831323210E3003178D00F3 |
:1004800000308F00031410300313DC00D42026301A |
:100490008400831323210A30E00055200D30E00052 |
:1004A00055205A082F3C03185B2A5A08403C031C6D |
:1004B0005B2A3030DA025A080B3C031CDC292B2063 |
:1004C000D90A0C30DD003B20DB015A085B0203181F |
:1004D0006E2A0230DD003B20DB0A652A5330E00043 |
:1004E0005520C830DE001720D90A7E204730E000B2 |
:0604F0005520DC29630029 |
:04400E00182FFC3F2C |
:00000001FF |
;PIC16F88 |
;CRC=345C CREATED="20-VIII-10 19:02" |
/Designs/MRAKOMER2/SW/Ondrejov/teplomer/irmrak.h |
---|
0,0 → 1,5 |
#include <16F88.h> |
#device adc=8 |
#fuses NOWDT,INTRC_IO, NOPUT, NOMCLR, NOBROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG, NOPROTECT, NOFCMEN, NOIESO, CCPB3 |
#use delay(clock=8000000) |
/Designs/MRAKOMER2/SW/Ondrejov/teplomer/irmrak4.PJT |
---|
0,0 → 1,45 |
[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\MRAKOMER2\SW\Ondrejov\teplomer\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=smb.c |
3=irmrak4.h |
4=..\..\..\..\..\..\..\Program Files\PICC\devices\16F88.h |
5=..\..\..\..\..\..\..\Program Files\PICC\drivers\string.h |
6=..\..\..\..\..\..\..\Program Files\PICC\drivers\stddef.h |
7=..\..\..\..\..\..\..\Program Files\PICC\drivers\ctype.h |
8= |
[Units] |
Count=1 |
1=irmrak4 (main) |
/Designs/MRAKOMER2/SW/Ondrejov/teplomer/irmrak4.c |
---|
0,0 → 1,148 |
/**** IR Mrakomer - special version for BART ****/ |
#define VERSION "2.2" |
#define ID "$Id: irmrak4.c 1306 2009-01-17 12:25:40Z kakl $" |
#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 30 // Doba po kterou se topi v [s] |
#define HEATING PIN_B3 // Heating for defrosting |
char VER[4]=VERSION; // Buffer for concatenate of a version string |
int8 heat; // Status variables |
void delay(int16 cycles) // Vlastni pauza, zbylo to z ovladani fototranzistoru z MM4 |
{ |
int16 i; |
for(i=0; i<cycles; i++) {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 30s.\n\r"); |
printf("# f - Freezing. Switch Off Heating.\n\r"); |
printf("# i - Print this Information.\n\r"); |
printf("# 0..9 - Single measure at given angle.\n\r"); |
printf("# m - Measure at three space points.\n\r"); |
printf("#\n\r"); |
printf("$<Angle> <Ambient Temperature> <Space Temperature> ..."); |
printf("\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 timer, temp, tempa; |
signed int16 ta, to; |
output_low(HEATING); // Heating off |
delay_ms(500); |
restart_wdt(); |
heat=0; |
timer=0; |
welcome(); |
tempa=ReadTemp(SA, RAM_Tamb); // Dummy read |
temp=ReadTemp(SA, RAM_Tobj1); |
delay_ms(500); |
while(TRUE) // Main Loop |
{ |
char ch; |
//---WDT |
restart_wdt(); |
if(kbhit()) |
{ |
ch=getc(); // Precti znak od radice motoru |
CREN=0; CREN=1; // Reinitialise USART |
tempa=ReadTemp(SA, RAM_Tamb); // Read temperatures from sensor |
temp=ReadTemp(SA, RAM_Tobj1); |
ta=tempa*2-27315; // °K -> °C |
to=temp*2-27315; |
switch (ch) |
{ |
case 'H': |
heat=MAXHEAT; // Need heating |
break; |
case 'F': |
heat=0; // Freeze |
break; |
case 'I': |
welcome(); // Information about version, etc... |
break; |
} |
printf("%c %Ld %Ld ", ch, ta, to); |
if (('A'!=ch)&&('B'!=ch)&&('C'!=ch)&&('S'!=ch)) printf("H %u\r\n", heat); // Vzdycky se konci natocenim na Ground |
} |
delay_ms(1); |
if (timer>0) {timer--;} else {timer=1000;} |
if (heat>0) {if(1000==timer) heat--; output_high(HEATING);} else { output_low(HEATING); } |
} |
} |
/Designs/MRAKOMER2/SW/Ondrejov/teplomer/irmrak4.h |
---|
0,0 → 1,19 |
#include <16F88.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 |
#use delay(clock=8000000) |
#use rs232(baud=2400,parity=N,xmit=PIN_B5,rcv=PIN_B2,bits=8) |
/Designs/MRAKOMER2/SW/Ondrejov/teplomer/irmrak4.hex |
---|
0,0 → 1,182 |
:1000000004308A008D2C00008A068A0623104D39A0 |
:10001000E135EF366539A0127310A8212910321886 |
:10002000B01BA025C1254C050D0023106810201021 |
:10003000A016A029F734F43168104F372024E5309A |
:10004000F434EE3320336F39A019B0392E050D008A |
:10005000231066102010A0162023F232653D693768 |
:100060006717A029F734F43168104F336610C8328F |
:10007000613A693767178A0600012310691020105A |
:10008000A0162028F2346E3A203AE834731049372B |
:10009000E637F236613AE9376E178A060001231017 |
:1000A0003017AE1CA016A029693767366510ED32EF |
:1000B000E13975396510613AA033693B6537A03085 |
:1000C000EE33EC322E050D0023106D102010A0161B |
:1000D000A026E530F33AF232A03074107434F232D4 |
:1000E00065107338E1316510F0376937F4392E0542 |
:1000F0000D00241E41376736651F201EC136E234CD |
:1001000065377410D4326D386539613A7539651FB9 |
:10011000201E5338E1316510D4326D386539613AAB |
:100120007539651F20172E1700018A068A06000000 |
:1001300033308400831300080319AB280230F80021 |
:10014000F701F70BA128F80BA0289730F700F70B61 |
:10015000A728800B9E2808006508E7006408E600D1 |
:100160006708FA006608840083137A1883178008EA |
:100170000319BE28E60A0319E70AB02864086602D4 |
:10018000F7006708FA006508031C650FFA02770894 |
:10019000F8000800831603178C170C1400000000E9 |
:1001A0000318FA2883120C087F390313E50003179C |
:1001B0000D080313E60003170F080313E700650893 |
:1001C0000C1EE0289900660803178D0003136708CA |
:1001D00003178F0083168C170C1400000000831285 |
:1001E0000313E40BF428F72883160317FA281A29B7 |
:1001F0008316031783120C0D0E0D7F390313E500D0 |
:1002000003170D080313E60003170F080313E70095 |
:1002100065080C1E09299900660803178D00031351 |
:10022000670803178F008D0A03198F0A0310031341 |
:10023000E40BCA280800800803193129E5010408E5 |
:10024000E4006510831B651400080C1E2529990025 |
:1002500064088400831365188317840A0319850AC8 |
:100260001B290800831603178C170C1400000000CC |
:1002700083120C087F39031978290313E40003174C |
:100280000D080313E50003170F080313E6006408C5 |
:100290000C1E48299900650803178D000313660892 |
:1002A00003178F0083168C170C14000000008312B4 |
:1002B0000C0D0E0D7F39031978290313E400031781 |
:1002C0000D080313E50003170F080313E600640885 |
:1002D0000C1E68299900650803178D000313660832 |
:1002E00003178F008D0A03198F0A0313322903178E |
:1002F000031308002430B2004930B3006430B40066 |
:100300003A30B5002030B6006930B7007230B8001E |
:100310006D30B9007230BA006130BB006B30BC0088 |
:100320003430BD002E30BE006330BF002030C0002E |
:100330003130C1003330C2003030C3003630C40029 |
:100340002030C5003230C6003030C700C800393018 |
:10035000C9002D30CA003030CB003130CC002D30F8 |
:10036000CD003130CE003730CF002030D0003130DA |
:10037000D1003230D2003A30D3003230D4003530A0 |
:10038000D5003A30D6003430D7003030D8005A305B |
:10039000D9002030DA006B30DB006130DC006B30DC |
:1003A000DD006C30DE002030DF002430E000E101B1 |
:1003B000E5013230E400AC2001307802323E8400A6 |
:1003C00083130008243C031DEF29E5013230E400CB |
:1003D000AC2001307802323E840083138001043067 |
:1003E00003178D0000308F0003100F300313E4005B |
:1003F000CA202230840083131B210C3003178D0088 |
:1004000000308F00031410300313E400CA2023309F |
:100410000C1E082A99003630840083131B210A30F1 |
:100420000C1E102A99000D300C1E142A990023303E |
:100430000C1E182A99000A300C1E1C2A99000D3037 |
:100440000C1E202A9900153003178D0000308F00F4 |
:1004500003133221283003178D0000308F0003135F |
:1004600032213D3003178D0000308F0003133221FD |
:100470004F3003178D0000308F000313322164309A |
:1004800003178D0000308F000313322123300C1E20 |
:10049000472A99000A300C1E4B2A99000D300C1E79 |
:1004A0004F2A9900793003178D0000308F00031315 |
:1004B0003221953003178D0000308F000313322155 |
:1004C00064000800831686140610831206100D308F |
:1004D000F700F70B692A83168610831286100D30F9 |
:1004E000F700F70B712A831606140D30F700F70B8F |
:1004F000772A861483120800831686140D30F700BD |
:10050000F70B802A06140D30F700F70B852A8610AA |
:10051000831286100D30F700F70B8C2A8316061015 |
:10052000831206100D30F700F70B942A0800C2085A |
:10053000031D9F2A8316861083128610A22A831613 |
:1005400086148312A32AA42AA52A831606141A3015 |
:10055000F700F70BA92A0000061083120610B02A34 |
:100560004230F700F70BB22A0000B62A08008316C3 |
:10057000861406141A30F700F70BBC2A0000861404 |
:100580008312861CC62A0130C200C72AC201831604 |
:10059000061083120610CC2A4230F700F70BCE2A41 |
:1005A0000000D22A4208F80008000830BF00BF0847 |
:1005B0000319E72ABE1FDF2A0130C100E02AC1016A |
:1005C0004108C20097220310BE0DBF03D72AB722ED |
:1005D0007808C0004008F80008000830BF00BF08D5 |
:1005E0000319FF2AB722F8080319FA2A0310BE0DCF |
:1005F0003E14FD2A0310BE0D3E10BF03EF2A3D0836 |
:10060000C20097223E08F80008000310B20D6222D3 |
:100610007C223208BE00D5223308BD00BE00D522A0 |
:100620007C223208BE00D522BD01ED227808B6003A |
:10063000BD01ED227808B5003508BC003608BB00C6 |
:100640000130BD00ED227808BA0062223208B900FC |
:100650003308B8003208B700B401BE013430BD0021 |
:100660002F30C500C401C301C201C1010130C00067 |
:100670000730BF002F30C500C6010530C700C801D4 |
:1006800047083D07840083133E1883170008CA00FB |
:100690008030F7004808F8000319522B0310F70CBC |
:1006A000F80B4E2B77084A05031D642BC708031966 |
:1006B000642BC5034808063C031C602BC80A622B48 |
:1006C000C801C703632B402B08304502C600C6088B |
:1006D0000319902B0530C700470F6F2B8D2B01306E |
:1006E00047023F3E84008313801F7C2BC7080319F9 |
:1006F0007C2B0130C9007D2BC9013F3047078400A6 |
:1007000083130310000D80003F30470784008313DC |
:10071000490800078000C7036C2BC6038F2B672B8B |
:10072000C7014708053C031CB32B47083D07F800E9 |
:100730003E08FA000318FA0A7808840083137A182E |
:1007400083170008CC003F3047078400831300085C |
:100750004C06CC007808840083137A1883174C0861 |
:100760008000C70A912B4508083C031C322B3D082A |
:10077000840083133E1883170008F80078083A02B3 |
:100780000319C42BBC01BB013B08F8003C08F9006D |
:100790000800BA010408B9003A10831B3A14B31FC9 |
:1007A000D92BB917391EB90AB209B309B20A03190C |
:1007B000B30A330EF038B500B507E23EB600323E5C |
:1007C000B80033080F39B607B607B807E93EB700D7 |
:1007D000B707B707320E0F39B707B807B70DB80D0F |
:1007E000B809B80D32080F39B807B50D0730B40095 |
:1007F0000A30B807B703031CF92BB707B603031C6D |
:10080000FD2BB607B503031C012CB507B403031C6D |
:10081000052C3430840083130730390539138403E1 |
:100820003905031D1A2C391A840A391A1A2C20305A |
:10083000F700372C840738300402031939170008F1 |
:10084000F700031D2B2C391B2B2C391A3B2CB91903 |
:100850002B2C2030362CB91F332C2D30F70084037D |
:100860003913B913372CB91539123030F707770817 |
:100870000C1E382C9900840A391F1B2C08003508DF |
:10088000F80134020318472C3408F700532CF70101 |
:100890000830B600B40DF70D350877020318F700DD |
:1008A000F80DB60B4A2C080078083208B400643002 |
:1008B000B5003F247708B20078083030031D672C5C |
:1008C000B31C6F2CB3196F2C331A20306A2CB31160 |
:1008D00033123314F80778080C1E6C2C9900320878 |
:1008E000B4000A30B5003F247708B20078083030F1 |
:1008F000031D802CB319852C331C852C331A203012 |
:10090000F80778080C1E822C99003030B2073208A4 |
:100910000C1E882C99008A115F2D840183131F30CF |
:100920008305723083168F000F0833309900A23090 |
:10093000980090308312980083161F129F121B0894 |
:1009400080399B0007309C008312A001A101323046 |
:10095000A2002E30A3003230A400A5018316861118 |
:10096000831286110230B200FA30B3009820B20B25 |
:10097000B42C6400A601A801A7017A21B2010630B7 |
:10098000B30005237908AC007808AB00B20107304A |
:10099000B30005237908AA007808A9000230B20044 |
:1009A000FA30B3009820B20BD02C64008C1E672D57 |
:1009B0008C1ED82C1A08B10018121816B201063075 |
:1009C000B30005237908AC007808AB00B20107300A |
:1009D000B30005237908AA007808A90003102B0D9D |
:1009E000B2002C0DB300B3303202F7003308FA0026 |
:1009F0006A30031C6B30FA027708AD007A08AE004B |
:100A00000310290DB2002A0DB300B3303202F700F3 |
:100A10003308FA006A30031C6B30FA027708AF0023 |
:100A20007A08B0003108483A03191D2D0E3A03190F |
:100A3000202D0F3A0319222D242D1E30A600242D1F |
:100A4000A601242D7A21242D31080C1E252D990074 |
:100A500020300C1E292D9900103084002E08B30080 |
:100A60002D08B200C92320300C1E342D99001030FF |
:100A700084003008B3002F08B200C92320300C1EB8 |
:100A80003F2D99003108413C0319672D3108423C44 |
:100A90000319672D3108433C0319672D3108533C76 |
:100AA0000319672D48300C1E532D990020300C1E61 |
:100AB000572D99002608B2001B30B300542C0D307E |
:100AC0000C1E602D99000A300C1E642D9900013017 |
:100AD000B3009820A708031D702DA8080319752DD1 |
:100AE00027080319A803A703792D0330A800E830CD |
:100AF000A700A6080319892D2708E83C031D842DAB |
:100B00002808033C0319A603831686118312861551 |
:0E0B10008D2D8316861183128611D52C63005D |
:04400E00103FFC3F24 |
:00000001FF |
;PIC16F88 |
;CRC=FAA7 CREATED="21-VIII-10 08:50" |
/Designs/MRAKOMER2/SW/Ondrejov/teplomer/smb.c |
---|
0,0 → 1,261 |
/************ 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_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(1); |
delay_us( LOWLEV ); // Low Level of Clock Pulse |
// mSDA_HIGH(); // Master release SDA line , |
// enable_interrupts(GLOBAL); |
//!!! toggle_dome(); |
delay_us(1); |
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(1); |
delay_us( LOWLEV ); // Low Level of Clock Pulse |
// enable_interrupts(GLOBAL); |
//!!! toggle_dome(); |
delay_us(1); |
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(); |
delay_us(1); |
} |
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(); |
delay_us(1); |
} |
//Exclusive OR between pec and crc |
for(i=0; i<=5; i++) |
{ |
pec[i] ^=crc[i]; |
} |
} while(BitPosition>8); |
return pec[0]; |
} |