Rev Author Line No. Line
1744 kakl 1 #include "main.h"
2  
1886 kakl 3 #define VERSION 0.2
1757 kakl 4  
1759 kakl 5 #define START PIN_D4
6 #define STOP1 PIN_D5
7 #define STOP2 PIN_D6
1886 kakl 8  
1774 kaklik 9 #include "GP2.h"
1759 kakl 10  
1774 kaklik 11 #define ONE_WIRE_PIN PIN_E2
12 #include "ds1820.c"
13  
1744 kakl 14 void main()
15 {
16 setup_adc_ports(NO_ANALOGS|VSS_VDD);
17 setup_adc(ADC_CLOCK_DIV_2);
18 setup_psp(PSP_DISABLED);
19 setup_spi(SPI_SS_DISABLED);
20 setup_wdt(WDT_OFF);
21 setup_timer_0(RTCC_INTERNAL);
22 setup_timer_1(T1_DISABLED);
23 setup_timer_2(T2_DISABLED,0,1);
24 setup_ccp1(CCP_OFF);
25 setup_comparator(NC_NC_NC_NC);
26 setup_vref(FALSE);
27  
1745 kakl 28 TDC_reset();
1886 kakl 29  
1759 kakl 30 output_low(START);
31 output_low(STOP1);
32 output_low(STOP2);
1815 kaklik 33  
34 delay_ms(50);
35  
1886 kakl 36 /*
37 1 0 0 0 0 ADR2 ADR1 ADR0 Write into address ADR
38 1 0 1 1 0 ADR2 ADR1 ADR0 Read from address ADR
39  
40  
41  
42  
43  
44  
45 */
1815 kaklik 46  
1886 kakl 47 int16 ret16;
48 int8 ret8;
1815 kaklik 49  
1931 kaklik 50  
1886 kakl 51 while(TRUE)
1744 kakl 52 {
1931 kaklik 53 delay_ms(100);
1886 kakl 54 TDC_reset();
55 delay_ms(100);
56  
57 //----------------------------------------------- Nastaveni registru
1965 kaklik 58 hit1=TDC_MRANGE2_HIT1_START;
59 hitin1=TDC_HITIN1_4;
60 hitin2=TDC_HITIN2_0;
61 en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT;
62 en_err_val=TDC_ERRVAL_EN;
63 delval1=0x0;
64 delval2=0x0;
65 delval3=0x0;
66  
67 TDC_update_registers();
1931 kaklik 68  
1886 kakl 69 //----------------------------------------------- Vypis registru
1964 kaklik 70  
1966 kaklik 71 printf("- %LX %LX %LX %LX ", TDC_get_measurement(0), TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3));
1886 kakl 72  
73 output_low(TDC_ENABLE);
74 ret8=0;
75 ret8=(0b1011<<4)|4;
76 spi_xfer(TDC_stream,ret8,8);
77 ret16=spi_xfer(TDC_stream,0,16);
78 output_high(TDC_ENABLE);
79 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);
80  
1964 kaklik 81 printf("%X\r\n",TDC_get_reg1());
1886 kakl 82  
83 //----------------------------------------------- Mereni
84  
85 TDC_init();
86  
1759 kakl 87 delay_ms(50);
1886 kakl 88  
89 TDC_start_cycle();
90  
91 delay_ms(200);
92  
93 output_high(STOP2); // Merime jenom jednim kanalem (druhy zrejme musi byt v H)
94  
1759 kakl 95 output_high(START);
1886 kakl 96 output_low(START);
1966 kaklik 97 delay_us(15);
1798 kaklik 98  
1886 kakl 99 output_high(STOP1);
100 output_low(STOP1);
101 delay_us(1);
1759 kakl 102  
1886 kakl 103  
1815 kaklik 104 output_high(STOP1);
1886 kakl 105 output_low(STOP1);
1966 kaklik 106 delay_us(10);
1886 kakl 107  
108 output_high(STOP1);
109 output_low(STOP1);
110 delay_us(1);
111  
112  
113  
114 //----------------------------------------------- Pocitani
1964 kaklik 115  
1966 kaklik 116 printf(" %3.7f %3.7f %3.7f ", TDC_mrange2_get_time(1), TDC_mrange2_get_time(2), TDC_mrange2_get_time(3));
1886 kakl 117  
1964 kaklik 118 output_low(TDC_ENABLE); //status register
1886 kakl 119 ret8=0;
120 ret8=(0b1011<<4)|4;
121 spi_xfer(TDC_stream,ret8,8);
122 ret16=spi_xfer(TDC_stream,0,16);
123 output_high(TDC_ENABLE);
1966 kaklik 124 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&TDC_get_status());
1964 kaklik 125  
126 printf("%X\r\n",TDC_get_reg1());
1886 kakl 127  
128 }
1744 kakl 129 }