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  
1967 kaklik 50 TDC_reset();
51 delay_ms(100);
1886 kakl 52  
53 //----------------------------------------------- Nastaveni registru
1965 kaklik 54 hit1=TDC_MRANGE2_HIT1_START;
55 hitin1=TDC_HITIN1_4;
56 hitin2=TDC_HITIN2_0;
57 en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT;
58 en_err_val=TDC_ERRVAL_EN;
1967 kaklik 59 clkhsdiv=TDC_CLKHSDIV_4;
1965 kaklik 60 delval1=0x0;
61 delval2=0x0;
62 delval3=0x0;
63  
64 TDC_update_registers();
1931 kaklik 65  
1967 kaklik 66 while(TRUE)
67 {
68 delay_ms(100);
1886 kakl 69  
70 //----------------------------------------------- Mereni
71  
72 TDC_init();
73  
1759 kakl 74 delay_ms(50);
1886 kakl 75  
76 TDC_start_cycle();
77  
78 delay_ms(200);
79  
80 output_high(STOP2); // Merime jenom jednim kanalem (druhy zrejme musi byt v H)
81  
1759 kakl 82 output_high(START);
1886 kakl 83 output_low(START);
1967 kaklik 84 delay_us(150);
1798 kaklik 85  
1886 kakl 86 output_high(STOP1);
87 output_low(STOP1);
88 delay_us(1);
1759 kakl 89  
1815 kaklik 90 output_high(STOP1);
1886 kakl 91 output_low(STOP1);
1966 kaklik 92 delay_us(10);
1886 kakl 93  
94 output_high(STOP1);
95 output_low(STOP1);
1967 kaklik 96 delay_us(1);
1886 kakl 97  
98 //----------------------------------------------- Pocitani
1964 kaklik 99  
1967 kaklik 100 printf("Time: %3.7f %3.7f %3.7f ", TDC_mrange2_get_time(1), TDC_mrange2_get_time(2), TDC_mrange2_get_time(3));
1886 kakl 101  
1964 kaklik 102 output_low(TDC_ENABLE); //status register
1886 kakl 103 ret8=0;
104 ret8=(0b1011<<4)|4;
105 spi_xfer(TDC_stream,ret8,8);
106 ret16=spi_xfer(TDC_stream,0,16);
107 output_high(TDC_ENABLE);
1967 kaklik 108 printf("[%Lu %Lu %Lu %Lu %Lu %Lu %Lu]\r\n", (1&(ret16)>>12), (1&(ret16)>>11), (1&(ret16)>>10), 1&(ret16)>>9, 7&(ret16)>>6, 7&(ret16)>>3, 7&TDC_get_status());
109  
110 TDC_start_temp();
111 output_low(TDC_ENABLE); //status register
112 ret8=0;
113 ret8=(0b1011<<4)|4;
114 spi_xfer(TDC_stream,ret8,8);
115 ret16=spi_xfer(TDC_stream,0,16);
116 output_high(TDC_ENABLE);
117 printf("Temp: [%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());
118 printf(" %LX %LX %LX %LX \r\n", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4));
119  
1886 kakl 120 }
1744 kakl 121 }