Problem with comparison.
/Modules/TDC/GP201A/SW/PICinterface/main.c |
---|
0,0 → 1,250 |
#include "main.h" |
#define VERSION 0.2 |
#define START PIN_D4 |
#define STOP1 PIN_D5 |
#define STOP2 PIN_D6 |
#include "GP2.h" |
#define ONE_WIRE_PIN PIN_E2 |
#include "ds1820.c" |
void main() |
{ |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
setup_adc(ADC_CLOCK_DIV_2); |
setup_psp(PSP_DISABLED); |
setup_spi(SPI_SS_DISABLED); |
setup_wdt(WDT_OFF); |
setup_timer_0(RTCC_INTERNAL); |
setup_timer_1(T1_DISABLED); |
setup_timer_2(T2_DISABLED,0,1); |
setup_ccp1(CCP_OFF); |
setup_comparator(NC_NC_NC_NC); |
setup_vref(FALSE); |
TDC_reset(); |
output_low(START); |
output_low(STOP1); |
output_low(STOP2); |
delay_ms(50); |
/* |
1 0 0 0 0 ADR2 ADR1 ADR0 Write into address ADR |
1 0 1 1 0 ADR2 ADR1 ADR0 Read from address ADR |
0 1 1 1 0 0 0 0 Init |
0 1 0 1 0 0 0 0 Power On Reset |
0 0 0 0 0 0 0 1 Start_Cycle |
0 0 0 0 0 0 1 0 Start_Temp |
0 0 0 0 0 0 1 1 Start_Cal_Resonator |
0 0 0 0 0 1 0 0 Start_Cal_TDC |
*/ |
int32 ble,ret32; |
int16 ret16; |
int8 ret8; |
while(TRUE) |
{ |
delay_ms(100); |
TDC_reset(); |
delay_ms(100); |
//----------------------------------------------- Nastaveni registru |
output_low(TDC_ENABLE); |
ble=0; |
ble=(8<<28)|(0<<24); |
ble|=(0<<20)|(0<<16)|(0<<14)|(3<<12)|(1<<10)|(0<<9)|(0<<8)|(0<<7)|(1<<6)|(1<<5)|(0<<4)|(1<<3)|(0<<2)|(0<<1)|0; |
spi_xfer(TDC_stream,ble,32); |
output_high(TDC_ENABLE); |
output_low(TDC_ENABLE); |
ble=0; |
ble=(8<<28)|(1<<24); |
ble|=(2<<20)|(1<<16)|(0<<15)|(1<<14)|(0<<11)|(4<<8)|0; |
spi_xfer(TDC_stream,ble,32); |
output_high(TDC_ENABLE); |
output_low(TDC_ENABLE); |
ble=0; |
ble=(8<<28)|(2<<24); |
ble|=(1<<21)|(1<<20)|(1<<19)|0; |
spi_xfer(TDC_stream,ble,32); |
output_high(TDC_ENABLE); |
output_low(TDC_ENABLE); |
ble=0; |
ble=(8<<28)|(3<<24); |
ble|=(0<<22)|(1<<21)|(1<<20)|(1<<19)|0; |
spi_xfer(TDC_stream,ble,32); |
output_high(TDC_ENABLE); |
output_low(TDC_ENABLE); |
ble=0; |
ble=(8<<28)|(4<<24); |
ble|=(4<<19)|0; |
spi_xfer(TDC_stream,ble,32); |
output_high(TDC_ENABLE); |
output_low(TDC_ENABLE); |
ble=0; |
ble=(8<<28)|(5<<24); |
ble|=(0<<21)|(0<<20)|(0<<19)|(0<<16)|0; |
spi_xfer(TDC_stream,ble,32); |
output_high(TDC_ENABLE); |
//----------------------------------------------- Vypis registru |
output_low(TDC_ENABLE); |
ret8=0; |
ret8=(0b1011<<4)|0; |
spi_xfer(TDC_stream,ret8,8); |
ret32=spi_xfer(TDC_stream,0,32); |
output_high(TDC_ENABLE); |
printf("- %LX ", ret32); |
output_low(TDC_ENABLE); |
ret8=0; |
ret8=(0b1011<<4)|1; |
spi_xfer(TDC_stream,ret8,8); |
ret32=spi_xfer(TDC_stream,0,32); |
output_high(TDC_ENABLE); |
printf("%LX ", ret32); |
output_low(TDC_ENABLE); |
ret8=0; |
ret8=(0b1011<<4)|2; |
spi_xfer(TDC_stream,ret8,8); |
ret32=spi_xfer(TDC_stream,0,32); |
output_high(TDC_ENABLE); |
printf("%LX ", ret32); |
output_low(TDC_ENABLE); |
ret8=0; |
ret8=(0b1011<<4)|3; |
spi_xfer(TDC_stream,ret8,8); |
ret32=spi_xfer(TDC_stream,0,32); |
output_high(TDC_ENABLE); |
printf("%LX ", ret32); |
output_low(TDC_ENABLE); |
ret8=0; |
ret8=(0b1011<<4)|4; |
spi_xfer(TDC_stream,ret8,8); |
ret16=spi_xfer(TDC_stream,0,16); |
output_high(TDC_ENABLE); |
printf("[%Lu %Lu %Lu %Lu %Lu %Lu %Lu] ", (1&(ret16)>>12), (1&(ret16)>>11), (1&(ret16)>>10), 1&(ret16)>>9, 7&(ret16)>>6, 7&(ret16)>>3, 7&ret16); |
output_low(TDC_ENABLE); |
ret8=0; |
ret8=(0b1011<<4)|5; |
spi_xfer(TDC_stream,ret8,8); |
ret8=spi_xfer(TDC_stream,0,8); |
output_high(TDC_ENABLE); |
printf("%X\r\n", ret8); |
//----------------------------------------------- Mereni |
TDC_init(); |
delay_ms(50); |
TDC_start_cycle(); |
delay_ms(200); |
output_high(STOP2); // Merime jenom jednim kanalem (druhy zrejme musi byt v H) |
output_high(START); |
output_low(START); |
delay_us(1); |
output_high(STOP1); |
output_low(STOP1); |
delay_us(1); |
output_high(STOP1); |
output_low(STOP1); |
delay_us(1); |
output_high(STOP1); |
output_low(STOP1); |
delay_us(1); |
//----------------------------------------------- Pocitani |
int32 nn; |
for(nn=3;nn<=5;nn++) |
{ |
delay_ms(500); |
output_low(TDC_ENABLE); |
ret8=0; |
ret8=(0b1011<<4)|0; |
spi_xfer(TDC_stream,ret8,8); |
ret32=spi_xfer(TDC_stream,0,32); |
output_high(TDC_ENABLE); |
printf("* %LX ", ret32); |
output_low(TDC_ENABLE); |
ret8=0; |
ret8=(0b1011<<4)|1; |
spi_xfer(TDC_stream,ret8,8); |
ret32=spi_xfer(TDC_stream,0,32); |
output_high(TDC_ENABLE); |
printf("%LX ", ret32); |
output_low(TDC_ENABLE); |
ret8=0; |
ret8=(0b1011<<4)|2; |
spi_xfer(TDC_stream,ret8,8); |
ret32=spi_xfer(TDC_stream,0,32); |
output_high(TDC_ENABLE); |
printf("%LX ", ret32); |
output_low(TDC_ENABLE); |
ret8=0; |
ret8=(0b1011<<4)|3; |
spi_xfer(TDC_stream,ret8,8); |
ret32=spi_xfer(TDC_stream,0,32); |
output_high(TDC_ENABLE); |
printf("%LX ", ret32); |
output_low(TDC_ENABLE); |
ret8=0; |
ret8=(0b1011<<4)|4; |
spi_xfer(TDC_stream,ret8,8); |
ret16=spi_xfer(TDC_stream,0,16); |
output_high(TDC_ENABLE); |
printf("[%Lu %Lu %Lu %Lu %Lu %Lu %Lu] ", (1&(ret16)>>12), (1&(ret16)>>11), (1&(ret16)>>10), 1&(ret16)>>9, 7&(ret16)>>6, 7&(ret16)>>3, 7&ret16); |
output_low(TDC_ENABLE); |
ret8=0; |
ret8=(0b1011<<4)|5; |
spi_xfer(TDC_stream,ret8,8); |
ret8=spi_xfer(TDC_stream,0,8); |
output_high(TDC_ENABLE); |
printf("%X\r\n", ret8); |
// Next calculation |
output_low(TDC_ENABLE); |
ble=0; |
ble=(8<<28)|(1<<24); |
ble|=(nn<<20)|(1<<16)|(0<<15)|(1<<14)|(0<<11)|(4<<8)|0x00; |
spi_xfer(TDC_stream,ble,32); |
output_high(TDC_ENABLE); |
} |
} |
} |
/Modules/TDC/GP201A/SW/PICinterface/main.hex |
---|
0,0 → 1,202 |
:10000000FBEF00F03450200807E0356E3036313613 |
:1000100032363336352EFAD79382939093948A945E |
:1000200034C035F08A8433AE8A9033BE8A8030364D |
:100030003136323633368A9400360136023603368C |
:1000400081A2009081B20080352EECD7000C9396EF |
:100050008A96336A326A316A500E306E080E346EF8 |
:10006000D1DF93968A86000CEA6A310EE96EEF5072 |
:100070000DE0060E016E006A002EFED7012EFBD7A2 |
:100080007B0E006E002EFED7EF2EF3D7000C939E52 |
:100090008A9E080E016E00D00000018E0ED0019ED7 |
:1000A0004732D8B08A8ED8A08A9E018C06D0019C97 |
:1000B000012EF6D700D000008A8EA70EE96EE92E39 |
:1000C000FED700D001BEEBD701BCF1D7000C31BE8A |
:1000D0000FD00F0E006E303800160A0E005C03E2DF |
:1000E000300E002602D03150002600C047F0CFDF8E |
:1000F0000F0E30160A0E305C02E2300E02D0319E36 |
:100100003150302630C047F0C2DF000CEACF46F055 |
:10011000E9CF45F03F38F009416E4126E20F426ECB |
:10012000320F446E3F500F0B422642264426E90F01 |
:10013000436E432643263E380F0B43264426433660 |
:100140004436441E44363E500F0B44264136070EBB |
:10015000406E0A0E43064426FDE342064326FDE3B5 |
:1001600041064226FDE340064126FDE3EA6A400ED1 |
:10017000E96E070E4514459CE926440EE95CD8B4A7 |
:10018000458CEF50006E08E145BC06D045B813D051 |
:1001900045B602D0200E03D045864598300E002685 |
:1001A000EACF3FF0E9CF3EF000C047F070DF3FC03C |
:1001B000EAFF3EC0E9FFEE5045ACDFD7000C939656 |
:1001C0008A96336A326A316A700E306E080E346E67 |
:1001D00019DF93968A86C7EF03F093968A96336A5F |
:1001E000326A316A010E306E080E346E0BDF939660 |
:1001F0008A86CBEF03F0F86AD09EEA6AE96A939E9A |
:100200008A8E9382939093948A94046A010E056E69 |
:10021000066A076A086E09800992099409860988A6 |
:10022000099A098C099E0A900A92050E0B6E0C6EB3 |
:100230000A940D6A0E6A010E0F6E0A960A98136AE6 |
:10024000126A116A106A0A9A030E146E186A176A03 |
:10025000166A156A1C6A1B6A1A6A196A1D6A0A9C60 |
:100260000A8E1E6A206A1F6AC150C00B0F09C16E38 |
:10027000070EB46EC150C00B0F09C16EC090C09282 |
:10028000C094C09EC2809698C69A949E9380939282 |
:10029000010EC66E000EC76ED190800ED56ECD6A6F |
:1002A000000ECA6E000ECB6E9484BD6AB76AB66A41 |
:1002B000070EB46E9250926E100E006E002EFED796 |
:1002C0000000B450A19CB56AC2DE95988C98959AAE |
:1002D0008C9A959C8C9C320E316EC6DE640E316E0B |
:1002E000C3DEB5DE640E316EBFDE93968A96246A55 |
:1002F000236A226A216A800E246E236A226A216A96 |
:10030000680E2112340E221224C033F023C032F0C2 |
:1003100022C031F021C030F0200E346E73DE93968F |
:100320008A8693968A96246A236A226A216A810EB3 |
:10033000246E236A226A216A440E2212210E23129D |
:1003400024C033F023C032F022C031F021C030F09D |
:10035000200E346E57DE93968A8693968A96246A88 |
:10036000236A226A216A820E246E236A226A216A23 |
:10037000380E231224C033F023C032F022C031F0F3 |
:1003800021C030F0200E346E3DDE93968A8693961F |
:100390008A96246A236A226A216A830E246E236A5B |
:1003A000226A216A380E231224C033F023C032F0AF |
:1003B00022C031F021C030F0200E346E23DE93963F |
:1003C0008A8693968A96246A236A226A216A840E10 |
:1003D000246E236A226A216A238A24C033F023C050 |
:1003E00032F022C031F021C030F0200E346E0ADE2F |
:1003F00093968A8693968A96246A236A226A216A49 |
:10040000850E246E236A226A216A24C033F023C039 |
:1004100032F022C031F021C030F0200E346EF2DD17 |
:1004200093968A8693968A962B6AB00E2B6E336AC1 |
:10043000326A316A2BC030F0080E346EE3DD336A65 |
:10044000326A316A306A200E346EDCDD015003C03E |
:1004500028F002C027F001C026F000C025F09396D6 |
:100460008A862D0E476E13DE200E476E10DE28C0E2 |
:1004700030F0370E316E2BDE27C030F0370E316E84 |
:1004800026DE26C030F0370E316E21DE25C030F07A |
:10049000370E316E1CDE200E476EF9DD93968A967C |
:1004A0002B6AB10E2B6E336A326A316A2BC030F080 |
:1004B000080E346EA7DD336A326A316A306A200E64 |
:1004C000346EA0DD015003C028F002C027F001C047 |
:1004D00026F000C025F093968A8628C030F0370EAB |
:1004E000316EF5DD27C030F0370E316EF0DD26C0FD |
:1004F00030F0370E316EEBDD25C030F0370E316E47 |
:10050000E6DD200E476EC3DD93968A962B6AB20E07 |
:100510002B6E336A326A316A2BC030F0080E346EAB |
:1005200071DD336A326A316A306A200E346E6ADDF8 |
:10053000015003C028F002C027F001C026F000C01F |
:1005400025F093968A8628C030F0370E316EBFDDD5 |
:1005500027C030F0370E316EBADD26C030F0370ECE |
:10056000316EB5DD25C030F0370E316EB0DD200EB6 |
:10057000476E8DDD93968A962B6AB30E2B6E336A87 |
:10058000326A316A2BC030F0080E346E3BDD336ABC |
:10059000326A316A306A200E346E34DD015003C095 |
:1005A00028F002C027F001C026F000C025F0939685 |
:1005B0008A8628C030F0370E316E89DD27C030F0D2 |
:1005C000370E316E84DD26C030F0370E316E7FDDA0 |
:1005D00025C030F0370E316E7ADD200E476E57DDC4 |
:1005E00093968A962B6AB40E2B6E336A326A316AFE |
:1005F0002BC030F0080E346E05DD336A326A316A82 |
:10060000306A100E346EFEDC015001C02AF000C0CA |
:1006100029F093968A862A38026E036A0F0E021614 |
:100620000250010B306E316A036A2A30026E0232C8 |
:1006300002321F0E02160250010B326E336A036A39 |
:100640002A30026E02323F0E02160250010B346E47 |
:10065000356AD890036A2A30026E010B366E376A0B |
:100660002A30036E2930026E033202320332023224 |
:10067000033202320332023203320232030E031615 |
:100680000250070B386E396A2A30036E2930026E29 |
:1006900003320232033202321F0E03160250070BDE |
:1006A0003A6E3B6A2950070B3C6E3D6A5B0E476E03 |
:1006B000EEDC100EE96E31C03FF030C03EF026DDBA |
:1006C000200E476EE4DC100EE96E33C03FF032C0FE |
:1006D0003EF01CDD200E476EDADC100EE96E35C0F0 |
:1006E0003FF034C03EF012DD200E476ED0DC100E1D |
:1006F000E96E37C03FF036C03EF008DD200E476E91 |
:10070000C6DC100EE96E39C03FF038C03EF0FEDCAA |
:10071000200E476EBCDC100EE96E3BC03FF03AC0C5 |
:100720003EF0F4DC200E476EB2DC100EE96E3DC0E8 |
:100730003FF03CC03EF0EADC5D0E476EA8DC200EC8 |
:10074000476EA5DC93968A962B6AB50E2B6E336A9C |
:10075000326A316A2BC030F0080E346E53DC336AD3 |
:10076000326A316A306A080E346E4CDC015000C0C7 |
:100770002BF093968A862BC030F0370E316EA7DCB3 |
:100780000D0E476E84DC0A0E476E81DC18D5320EE2 |
:10079000316E6ADC22D5C80E316E66DC959C8C8C7D |
:1007A00095988C8895988C9800D000D00000959AE8 |
:1007B0008C8A959A8C9A00D000D00000959A8C8AE9 |
:1007C000959A8C9A00D000D00000959A8C8A959AC0 |
:1007D0008C9A00D000D000002F6A2E6A2D6A030E7A |
:1007E0002C6E2F52D8A42ED22E52D8A42BD22D52FA |
:1007F000D8A428D22C500508D8A024D2020E306EDE |
:10080000FA0E316E31DC302EFBD793968A962B6A26 |
:10081000B00E2B6E336A326A316A2BC030F0080E8C |
:10082000346E02EC00F0336A326A316A306A200EAC |
:10083000346E02EC00F0015003C028F002C027F033 |
:1008400001C026F000C025F093968A862A0E476ED6 |
:100850001EDC200E476E1BDC28C030F0370E316ED8 |
:1008600036DC27C030F0370E316E31DC26C030F078 |
:10087000370E316E2CDC25C030F0370E316E27DCA0 |
:10088000200E476E04DC93968A962B6AB10E2B6E6F |
:10089000336A326A316A2BC030F0080E346E02ECD3 |
:1008A00000F0336A326A316A306A200E346E02EC2C |
:1008B00000F0015003C028F002C027F001C026F06C |
:1008C00000C025F093968A8628C030F0370E316E2E |
:1008D00067EC00F027C030F0370E316E67EC00F0A7 |
:1008E00026C030F0370E316E67EC00F025C030F0D6 |
:1008F000370E316E67EC00F0200E476E47EC00F0CB |
:1009000093968A962B6AB20E2B6E336A326A316ADC |
:100910002BC030F0080E346E02EC00F0336A326AFD |
:10092000316A306A200E346E02EC00F0015003C0D0 |
:1009300028F002C027F001C026F000C025F09396F1 |
:100940008A8628C030F0370E316E67EC00F027C081 |
:1009500030F0370E316E67EC00F026C030F0370E05 |
:10096000316E67EC00F025C030F0370E316E67EC69 |
:1009700000F0200E476E47EC00F093968A962B6AA3 |
:10098000B30E2B6E336A326A316A2BC030F0080E18 |
:10099000346E02EC00F0336A326A316A306A200E3B |
:1009A000346E02EC00F0015003C028F002C027F0C2 |
:1009B00001C026F000C025F093968A8628C030F04A |
:1009C000370E316E67EC00F027C030F0370E316E15 |
:1009D00067EC00F026C030F0370E316E67EC00F0A7 |
:1009E00025C030F0370E316E67EC00F0200E476EF8 |
:1009F00047EC00F093968A962B6AB40E2B6E336AFE |
:100A0000326A316A2BC030F0080E346E02EC00F00E |
:100A1000336A326A316A306A100E346E02EC00F0CA |
:100A2000015001C02AF000C029F093968A862A3826 |
:100A3000026E036A0F0E02160250010B306E316A0D |
:100A4000036A2A30026E023202321F0E0216025070 |
:100A5000010B326E336A036A2A30026E02323F0E95 |
:100A600002160250010B346E356AD890036A2A30A0 |
:100A7000026E010B366E376A2A30036E2930026E21 |
:100A800003320232033202320332023203320232C2 |
:100A900003320232030E03160250070B386E396A16 |
:100AA0002A30036E2930026E0332023203320232E0 |
:100AB0001F0E03160250070B3A6E3B6A2950070BB4 |
:100AC0003C6E3D6A5B0E476E47EC00F0100EE96E1F |
:100AD00031C03FF030C03EF086EC00F0200E476E93 |
:100AE00047EC00F0100EE96E33C03FF032C03EF02C |
:100AF00086EC00F0200E476E47EC00F0100EE96E19 |
:100B000035C03FF034C03EF086EC00F0200E476E5A |
:100B100047EC00F0100EE96E37C03FF036C03EF0F3 |
:100B200086EC00F0200E476E47EC00F0100EE96EE8 |
:100B300039C03FF038C03EF086EC00F0200E476E22 |
:100B400047EC00F0100EE96E3BC03FF03AC03EF0BB |
:100B500086EC00F0200E476E47EC00F0100EE96EB8 |
:100B60003DC03FF03CC03EF086EC00F05D0E476EAD |
:100B700047EC00F0200E476E47EC00F093968A9603 |
:100B80002B6AB50E2B6E336A326A316A2BC030F095 |
:100B9000080E346E02EC00F0336A326A316A306A51 |
:100BA000080E346E02EC00F0015000C02BF093965A |
:100BB0008A862BC030F0370E316E67EC00F00D0ED8 |
:100BC000476E47EC00F00A0E476E47EC00F0939634 |
:100BD0008A96246A236A226A216A810E246E236A15 |
:100BE000226A216A316A326A2C34336E2D34346EB3 |
:100BF000333634363336343633363436F00E331635 |
:100C00003380328C328431502112325022123350D0 |
:100C100023123450241224C033F023C032F022C0F7 |
:100C200031F021C030F0200E346E02EC00F09396CB |
:100C30008A86010E2C26D8B02D2AD8B42E2AD8B4F4 |
:0A0C40002F2ACFD56EEF01F003005C |
:020000040030CA |
:0E00000027CC390E0087A1000FC00FE00F4083 |
:00000001FF |
;PIC18F4550 |
;CRC=0A0F CREATED="06-4-11 21:32" |
/Modules/TDC/GP201A/SW/PICinterface/main.pjt |
---|
0,0 → 1,32 |
[PROJECT] |
Target=.\main.hex |
Development_Mode= |
Processor_Text=PIC18F4550 |
ToolSuite=CCS |
Processor=0x4550 |
[.\main] |
Type=4 |
Path= |
FileList= |
BuildTool= |
OptionString= |
AdditionalOptionString= |
[mru-list] |
1=.\main.c |
[Windows] |
0=0000 %S 0 0 796 451 3 0 |
[Opened Files] |
1=main.c |
2=main.h |
3=..\..\..\..\..\..\..\..\..\Program Files (x86)\PICC\devices\18F4550.h |
4=GP2.h |
5=GP2.c |
6=ds1820.c |
7=1wire.c |
8= |
[Target Data] |
OptionString=-p +FH |
FileList=D:\MLAB\Modules\TDC\GP201A\SW\PICinterface\main.c |
[Units] |
Count=1 |
1=main (main) |
/Modules/TDC/GP201A/SW/PICinterface/main.h |
---|
0,0 → 1,41 |
#include <18F4550.h> |
#device adc=8 |
#FUSES NOWDT //No Watch Dog Timer |
#FUSES WDT128 //Watch Dog Timer uses 1:128 Postscale |
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD) |
#FUSES NOPROTECT //Code not protected from reading |
#FUSES NOBROWNOUT //No brownout reset |
#FUSES BORV20 //Brownout reset at 2.0V |
#FUSES NOPUT //No Power Up Timer |
#FUSES NOCPD //No EE protection |
#FUSES STVREN //Stack full/underflow will cause reset |
#FUSES NODEBUG //No Debug mode for ICD |
#FUSES NOLVP //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O |
#FUSES NOWRT //Program memory not write protected |
#FUSES NOWRTD //Data EEPROM not write protected |
#FUSES IESO //Internal External Switch Over mode enabled |
#FUSES FCMEN //Fail-safe clock monitor enabled |
#FUSES PBADEN //PORTB pins are configured as analog input channels on RESET |
#FUSES NOWRTC //configuration not registers write protected |
#FUSES NOWRTB //Boot block not write protected |
#FUSES NOEBTR //Memory not protected from table reads |
#FUSES NOEBTRB //Boot block not protected from table reads |
#FUSES NOCPB //No Boot Block code protection |
#FUSES MCLR //Master Clear pin enabled |
#FUSES LPT1OSC //Timer1 configured for low-power operation |
#FUSES NOXINST //Extended set extension and Indexed Addressing mode disabled (Legacy mode) |
#FUSES PLL12 //Divide By 12(48MHz oscillator input) |
#FUSES CPUDIV1 //System Clock by 1 |
#FUSES USBDIV //USB clock source comes from PLL divide by 2 |
#FUSES VREGEN //USB voltage regulator enabled |
#FUSES ICPRT //ICPRT enabled |
#use delay(clock=20000000) |
#use rs232(baud=9600,parity=N,xmit=PIN_B7,rcv=PIN_B6,bits=8) |
#define TDC_ENABLE PIN_B3 //enable pin for SPI communication with TDC |
#use spi(DI=PIN_B1, DO=PIN_B0, CLK=PIN_B2, stream=TDC_stream, bits=32,baud=9600) // uses software SPI |
/Modules/TDC/GP201A/SW/PICinterface/GP2.h |
---|
0,0 → 1,152 |
//register 0 |
#define TDC_NEG_START_INV 1 |
#define TDC_NEG_START 0 |
#define TDC_NEG_STOP1_INV 1 |
#define TDC_NEG_STOP1 0 |
#define TDC_NEG_STOP2_INV 1 |
#define TDC_NEG_STOP2 0 |
#define TDC_MRANGE1 0 |
#define TDC_MRANGE2 1 |
#define TDC_AUTOCAL_EN 0 |
#define TDC_AUTOCAL_DIS 1 |
#define TDC_CALIBRATE_EN 1 |
#define TDC_CALIBRATE_DIS 0 |
#define TDC_TSELCLK_32KHZ 0 |
#define TDC_TSELCLK_128HS 1 |
#define TDC_TFAKENUM_2 0 |
#define TDC_TFAKENUM_8 1 |
#define TDC_TCYCLE_SHORT 0 |
#define TDC_TCYSLE_LONG 1 |
#define TDC_TPORTNUM_2 0 |
#define TDC_TPORTNUM_4 1 |
#define TDC_CLKHS_OFF 0 |
#define TDC_CLKHS_ON 1 |
#define TDC_CLKHS_640US 2 |
#define TDC_CLKHS_1280US 4 |
#define TDC_CLKHSDIV_1 0 |
#define TDC_CLKHSDIV_2 1 |
#define TDC_CLKHSDIV_4 2 |
#define TDC_CLKHSDIV_8 3 |
#define TDC_CALPERIODS_2 0 |
#define TDC_CALPERIODS_4 1 |
#define TDC_CALPERIODS_8 2 |
#define TDC_CALPERIODS_16 3 |
#define TDC_DIV_FIRE_2 1 |
#define TDC_DIV_FIRE_3 2 |
#define TDC_DIV_FIRE_4 3 |
#define TDC_DIV_FIRE_5 4 |
#define TDC_DIV_FIRE_6 5 |
#define TDC_DIV_FIRE_7 6 |
#define TDC_DIV_FIRE_8 7 |
#define TDC_DIV_FIRE_9 8 |
#define TDC_DIV_FIRE_10 9 |
#define TDC_DIV_FIRE_11 10 |
#define TDC_DIV_FIRE_12 11 |
#define TDC_DIV_FIRE_13 12 |
#define TDC_DIV_FIRE_14 13 |
#define TDC_DIV_FIRE_15 14 |
#define TDC_DIV_FIRE_16 15 |
#define TDC_FIRENUM_0 0 |
#define TDC_FIRENUM_1 1 |
#define TDC_FIRENUM_2 2 |
#define TDC_FIRENUM_3 3 |
#define TDC_FIRENUM_4 4 |
#define TDC_FIRENUM_5 5 |
#define TDC_FIRENUM_6 6 |
#define TDC_FIRENUM_7 7 |
#define TDC_FIRENUM_8 8 |
#define TDC_FIRENUM_9 9 |
#define TDC_FIRENUM_10 10 |
#define TDC_FIRENUM_11 11 |
#define TDC_FIRENUM_12 12 |
#define TDC_FIRENUM_13 13 |
#define TDC_FIRENUM_14 14 |
#define TDC_FIRENUM_15 15 |
//register 1 |
#define TDC_HITIN1_0 0 |
#define TDC_HITIN1_1 1 |
#define TDC_HITIN1_2 2 |
#define TDC_HITIN1_3 3 |
#define TDC_HITIN1_4 4 |
#define TDC_HITIN2_0 0 |
#define TDC_HITIN2_1 1 |
#define TDC_HITIN2_2 2 |
#define TDC_HITIN2_3 3 |
#define TDC_HITIN2_4 4 |
#define TDC_FAST_INIT_EN 1 |
#define TDC_FAST_INIT_DIS 0 |
#define TDC_MRANGE1_HIT1_START 0 |
#define TDC_MRANGE1_HIT1_1CH1 1 |
#define TDC_MRANGE1_HIT1_2CH1 2 |
#define TDC_MRANGE1_HIT1_3CH1 3 |
#define TDC_MRANGE1_HIT1_4CH1 4 |
#define TDC_MRANGE1_HIT1_NOAC 5 |
#define TDC_MRANGE1_HIT1_CAL1CH1 6 |
#define TDC_MRANGE1_HIT1_CAL2CH1 7 |
#define TDC_MRANGE1_HIT1_1CH2 9 |
#define TDC_MRANGE1_HIT1_2CH2 0xA |
#define TDC_MRANGE1_HIT1_3CH2 0xB |
#define TDC_MRANGE1_HIT1_4CH2 0xC |
#define TDC_MRANGE2_HIT1_START 1 |
#define TDC_MRANGE1_HIT2_START 0 |
#define TDC_MRANGE1_HIT2_1CH1 1 |
#define TDC_MRANGE1_HIT2_2CH1 2 |
#define TDC_MRANGE1_HIT2_3CH1 3 |
#define TDC_MRANGE1_HIT2_4CH1 4 |
#define TDC_MRANGE1_HIT2_NOAC 5 |
#define TDC_MRANGE1_HIT2_CAL1CH1 6 |
#define TDC_MRANGE1_HIT2_CAL2CH1 7 |
#define TDC_MRANGE1_HIT2_1CH2 9 |
#define TDC_MRANGE1_HIT2_2CH2 0xA |
#define TDC_MRANGE1_HIT2_3CH2 0xB |
#define TDC_MRANGE1_HIT2_4CH2 0xC |
#define TDC_MRANGE2_HIT2_1CH1 2 |
#define TDC_MRANGE2_HIT2_2CH1 3 |
#define TDC_MRANGE2_HIT2_3CH1 4 |
//register 2 |
#define TDC_INT_TIMEOUT 4 |
#define TDC_INT_ENDHIT 2 |
#define TDC_INT_ALU 1 |
#define TDC_CH1EDGE_RIS 0 |
#define TDC_CH1EDGE_FAL 1 |
#define TDC_CH2EDGE_RIS 0 |
#define TDC_CH2EDGE_FAL 1 |
//register 3 |
#define TDC_TIM0MR2_256CLKHS 0 |
#define TDC_TIM0MR2_1024CLKHS 1 |
#define TDC_TIM0MR2_4096CLKHS 2 |
#define TDC_TIM0MR2_16384CLKHS 3 |
#define TDC_ERRVAL_EN 1 |
#define TDC_ERRVAL_DIS 0 |
//register 5 |
#define TDC_REPEAT_FIRE_0 0 |
#define TDC_REPEAT_FIRE_1 1 |
#define TDC_REPEAT_FIRE_2 2 |
#define TDC_REPEAT_FIRE_3 3 |
#define TDC_REPEAT_FIRE_4 4 |
#define TDC_REPEAT_FIRE_5 5 |
#define TDC_REPEAT_FIRE_6 6 |
#define TDC_REPEAT_FIRE_7 7 |
#define TDC_PHASENOISE_EN 0 |
#define TDC_PHASENOISE_DIS 1 |
#define TDC_STARTNOISE_EN 1 |
#define TDC_STARTNOISE_DIS 0 |
#include "GP2.c" |
/Modules/TDC/GP201A/SW/PICinterface/GP2.c |
---|
0,0 → 1,198 |
//struct { |
unsigned int8 firenum=TDC_FIRENUM_0; |
unsigned int8 div_fire=TDC_DIV_FIRE_2; |
unsigned int8 calresnum=TDC_CALPERIODS_2; |
unsigned int8 clkhsdiv=TDC_CLKHSDIV_1; |
unsigned int8 start_clkhs=TDC_CLKHS_ON; |
unsigned int1 portnum=TDC_TPORTNUM_4; |
unsigned int1 Tcycle=TDC_TCYCLE_SHORT; |
unsigned int1 fakenum=TDC_TFAKENUM_2; |
unsigned int1 selclkT=TDC_TSELCLK_128HS; |
unsigned int1 calibrate=TDC_CALIBRATE_EN; |
unsigned int1 disautocal=TDC_AUTOCAL_EN; |
unsigned int1 MRange=TDC_MRANGE2; |
unsigned int1 neg_stop2=TDC_NEG_STOP2; |
unsigned int1 neg_stop1=TDC_NEG_STOP1; |
unsigned int1 neg_start=TDC_NEG_START; |
//}reg0; |
//struct { |
unsigned int hit2=TDC_MRANGE1_HIT2_NOAC; |
unsigned int hit1=TDC_MRANGE1_HIT1_NOAC; |
unsigned int1 fast_init=TDC_FAST_INIT_DIS; |
unsigned int hitin2=TDC_HITIN2_0; |
unsigned int hitin1=TDC_HITIN1_0; |
//}reg1; |
//struct { |
unsigned int en_int=TDC_INT_ALU; |
unsigned int1 rfedge2=TDC_CH2EDGE_RIS; |
unsigned int1 rfedge1=TDC_CH1EDGE_RIS; |
unsigned int32 delval1=0; |
//}reg2; |
//struct { |
unsigned int1 en_err_val=TDC_ERRVAL_DIS; |
unsigned int tim0_mr2=TDC_TIM0MR2_16384CLKHS; |
unsigned int32 delval2=0; |
//}reg3; |
//reg4 |
unsigned int32 delval3=0; |
//reg5 |
unsigned int conf_fire=0; |
unsigned int1 en_startnoise=TDC_STARTNOISE_DIS; |
unsigned int1 dis_phasenoise=TDC_PHASENOISE_DIS; |
unsigned int repeat_fire=TDC_REPEAT_FIRE_0; |
unsigned int16 phase_fire=0; |
//}TDC_registers; |
void TDC_init() |
{ |
output_low(TDC_ENABLE); |
spi_xfer(TDC_stream,0x70,8); |
output_high(TDC_ENABLE); |
} |
void TDC_reset() |
{ |
output_low(TDC_ENABLE); |
spi_xfer(TDC_stream,0x50,8); |
output_high(TDC_ENABLE); |
} |
void TDC_start_cycle() |
{ |
output_low(TDC_ENABLE); |
spi_xfer(TDC_stream,0x01,8); |
output_high(TDC_ENABLE); |
} |
void TDC_start_temp() |
{ |
output_low(TDC_ENABLE); |
spi_xfer(TDC_stream,0x02,8); |
output_high(TDC_ENABLE); |
} |
void TDC_start_cal_resonator() |
{ |
output_low(TDC_ENABLE); |
spi_xfer(TDC_stream,0x03,8); |
output_high(TDC_ENABLE); |
} |
void TDC_start_cal() |
{ |
output_low(TDC_ENABLE); |
spi_xfer(TDC_stream,0x04,8); |
output_high(TDC_ENABLE); |
} |
unsigned int32 TDC_get_measurement(int num) |
{ |
unsigned int32 ret; |
output_low(TDC_ENABLE); |
spi_xfer(TDC_stream,0xB0 + num - 1); |
ret=spi_xfer(TDC_stream,0,32); |
output_high(TDC_ENABLE); |
return ret; |
} |
unsigned int16 TDC_get_status() |
{ |
unsigned int16 ret; |
output_low(TDC_ENABLE); |
spi_xfer(TDC_stream,0xB4,8); |
ret=spi_xfer(TDC_stream,0,16); |
output_high(TDC_ENABLE); |
return ret; |
} |
unsigned int8 TDC_get_reg1() |
{ |
unsigned int8 ret; |
output_low(TDC_ENABLE); |
spi_xfer(TDC_stream,0xB5,8); |
ret=spi_xfer(TDC_stream,0,8); |
output_high(TDC_ENABLE); |
return ret; |
} |
void TDC_update_registers() |
{ |
//update reg0 |
output_low(TDC_ENABLE); |
spi_xfer(TDC_stream,0x80,8); |
spi_xfer(TDC_stream,firenum,4); |
spi_xfer(TDC_stream,div_fire,4); |
spi_xfer(TDC_stream,calresnum,2); |
spi_xfer(TDC_stream,clkhsdiv,2); |
spi_xfer(TDC_stream,start_clkhs,2); |
spi_xfer(TDC_stream,portnum,1); |
spi_xfer(TDC_stream,Tcycle,1); |
spi_xfer(TDC_stream,fakenum,1); |
spi_xfer(TDC_stream,selclkT,1); |
spi_xfer(TDC_stream,calibrate,1); |
spi_xfer(TDC_stream,disautocal,1); |
spi_xfer(TDC_stream,MRange,1); |
spi_xfer(TDC_stream,neg_stop2,1); |
spi_xfer(TDC_stream,neg_stop1,1); |
spi_xfer(TDC_stream,neg_start,1); |
output_high(TDC_ENABLE); |
// update reg1 |
output_low(TDC_ENABLE); |
spi_xfer(TDC_stream,0x81,8); |
spi_xfer(TDC_stream,hit2,4); |
spi_xfer(TDC_stream,hit1,4); |
spi_xfer(TDC_stream,fast_init,1); |
spi_xfer(TDC_stream,1,1); |
spi_xfer(TDC_stream,hitin2,3); |
spi_xfer(TDC_stream,hitin1,3); |
spi_xfer(TDC_stream,0,8); |
output_high(TDC_ENABLE); |
// update reg2 |
output_low(TDC_ENABLE); |
spi_xfer(TDC_stream,0x82); |
spi_xfer(TDC_stream,en_int,3); |
spi_xfer(TDC_stream,rfedge2,1); |
spi_xfer(TDC_stream,rfedge1,1); |
spi_xfer(TDC_stream,delval1,19); |
output_high(TDC_ENABLE); |
// update reg3 |
output_low(TDC_ENABLE); |
spi_xfer(TDC_stream,0x83); |
spi_xfer(TDC_stream,0,2); |
spi_xfer(TDC_stream,en_err_val,1); |
spi_xfer(TDC_stream,tim0_mr2,2); |
spi_xfer(TDC_stream,delval2,19); |
output_high(TDC_ENABLE); |
// update reg4 |
output_low(TDC_ENABLE); |
spi_xfer(TDC_stream,0x84); |
spi_xfer(TDC_stream,0b00100,5); |
spi_xfer(TDC_stream,delval3,19); |
output_high(TDC_ENABLE); |
// update reg5 |
output_low(TDC_ENABLE); |
spi_xfer(TDC_stream,0x85); |
spi_xfer(TDC_stream,conf_fire,3); |
spi_xfer(TDC_stream,en_startnoise,1); |
spi_xfer(TDC_stream,dis_phasenoise,1); |
spi_xfer(TDC_stream,repeat_fire,3); |
spi_xfer(TDC_stream,phase_fire,16); |
output_high(TDC_ENABLE); |
} |
/Modules/TDC/GP201A/SW/PICinterface/1wire.c |
---|
0,0 → 1,43 |
void onewire_reset() |
{ |
output_low(ONE_WIRE_PIN); |
delay_us(500); |
output_float(ONE_WIRE_PIN); |
delay_us(500); |
output_float(ONE_WIRE_PIN); |
} |
void onewire_write(int data) |
{ |
int count; |
for (count=0; count<8; ++count) |
{ |
output_low(ONE_WIRE_PIN); |
delay_us( 2 ); |
output_bit(ONE_WIRE_PIN, shift_right(&data,1,1)); |
delay_us( 60 ); |
output_float(ONE_WIRE_PIN); |
delay_us( 2 ); |
} |
} |
int onewire_read() |
{ |
int count, data; |
for (count=0; count<8; ++count) |
{ |
output_low(ONE_WIRE_PIN); |
delay_us( 2 ); |
output_float(ONE_WIRE_PIN); |
delay_us( 8 ); |
shift_right(&data,1,input(ONE_WIRE_PIN)); |
delay_us( 120 ); |
} |
return( data ); |
} |
/Modules/TDC/GP201A/SW/PICinterface/ds1820.c |
---|
0,0 → 1,25 |
#include "1wire.c" |
float ds1820_read() |
{ |
int8 busy=0, temp1, temp2; |
signed int16 temp3; |
float result; |
onewire_reset(); |
onewire_write(0xCC); |
onewire_write(0x44); |
while (busy == 0) busy = onewire_read(); |
onewire_reset(); |
onewire_write(0xCC); |
onewire_write(0xBE); |
temp1 = onewire_read(); |
temp2 = onewire_read(); |
temp3 = make16(temp2, temp1); |
result = (float) temp3 / 16.0; //calculation pro DS18B20 with 0.1 deg C |
return(result); |
} |