| Line 1... |
Line 1... |
| 1 |
#include "main.h" |
1 |
#include "main.h" |
| - |
|
2 |
#include <math.h> |
| - |
|
3 |
|
| - |
|
4 |
#use fast_io (D) |
| 2 |
|
5 |
|
| 3 |
#define VERSION 0.2 |
6 |
#define VERSION 0.2 |
| 4 |
|
7 |
|
| 5 |
#define START PIN_D4 |
8 |
#define START PIN_D4 |
| 6 |
#define STOP1 PIN_D5 |
9 |
#define STOP1 PIN_D5 |
| 7 |
#define STOP2 PIN_D6 |
10 |
#define STOP2 PIN_D7 |
| 8 |
|
11 |
|
| 9 |
#include "GP2.h" |
12 |
#include "GP2.h" |
| 10 |
|
13 |
|
| 11 |
#define ONE_WIRE_PIN PIN_E2 |
14 |
#define ONE_WIRE_PIN PIN_E2 |
| 12 |
#include "ds1820.c" |
15 |
#include "ds1820.c" |
| 13 |
|
16 |
|
| 14 |
void main() |
17 |
void main() |
| 15 |
{ |
18 |
{ |
| 16 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
19 |
/* setup_adc_ports(NO_ANALOGS|VSS_VDD); |
| 17 |
setup_adc(ADC_CLOCK_DIV_2); |
20 |
setup_adc(ADC_CLOCK_DIV_2); |
| 18 |
setup_psp(PSP_DISABLED); |
21 |
setup_psp(PSP_DISABLED); |
| 19 |
setup_spi(SPI_SS_DISABLED); |
22 |
setup_spi(SPI_SS_DISABLED); |
| 20 |
setup_wdt(WDT_OFF); |
23 |
setup_wdt(WDT_OFF); |
| 21 |
setup_timer_0(RTCC_INTERNAL); |
24 |
setup_timer_0(RTCC_INTERNAL); |
| 22 |
setup_timer_1(T1_DISABLED); |
25 |
setup_timer_1(T1_DISABLED); |
| 23 |
setup_timer_2(T2_DISABLED,0,1); |
26 |
setup_timer_2(T2_DISABLED,0,1); |
| 24 |
setup_ccp1(CCP_OFF); |
27 |
setup_ccp1(CCP_OFF); |
| 25 |
setup_comparator(NC_NC_NC_NC); |
28 |
setup_comparator(NC_NC_NC_NC); |
| 26 |
setup_vref(FALSE); |
29 |
setup_vref(FALSE); |
| - |
|
30 |
*/ |
| - |
|
31 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
| - |
|
32 |
setup_adc(ADC_CLOCK_DIV_2); |
| - |
|
33 |
setup_spi(SPI_SS_DISABLED); |
| - |
|
34 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
| - |
|
35 |
setup_timer_1(T1_DISABLED); |
| - |
|
36 |
setup_timer_2(T2_DISABLED,0,1); |
| - |
|
37 |
setup_ccp1(CCP_OFF); |
| - |
|
38 |
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard |
| - |
|
39 |
|
| - |
|
40 |
|
| - |
|
41 |
set_tris_d(0x00); |
| 27 |
|
42 |
|
| 28 |
TDC_reset(); |
43 |
TDC_reset(); |
| 29 |
|
44 |
|
| 30 |
output_low(START); |
45 |
output_low(START); |
| 31 |
output_low(STOP1); |
46 |
output_low(STOP1); |
| Line 89... |
Line 104... |
| 89 |
output_low(STOP1); |
104 |
output_low(STOP1); |
| 90 |
delay_us(1); |
105 |
delay_us(1); |
| 91 |
|
106 |
|
| 92 |
//----------------------------------------------- Pocitani |
107 |
//----------------------------------------------- Pocitani |
| 93 |
|
108 |
|
| 94 |
printf("Time2: %3.7f %3.7f %3.7f ", TDC_mrange2_get_time(1), TDC_mrange2_get_time(2), TDC_mrange2_get_time(3)); |
109 |
printf("Time2: %LX %LX %LX %LX ", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4)); |
| - |
|
110 |
|
| 95 |
|
111 |
|
| 96 |
output_low(TDC_ENABLE); //status register |
112 |
output_low(TDC_ENABLE); //status register |
| 97 |
ret8=0; |
113 |
ret8=0; |
| 98 |
ret8=(0b1011<<4)|4; |
114 |
ret8=(0b1011<<4)|4; |
| 99 |
spi_xfer(TDC_stream,ret8,8); |
115 |
spi_xfer(TDC_stream,ret8,8); |
| 100 |
ret16=spi_xfer(TDC_stream,0,16); |
116 |
ret16=spi_xfer(TDC_stream,0,16); |
| 101 |
output_high(TDC_ENABLE); |
117 |
output_high(TDC_ENABLE); |
| 102 |
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()); |
118 |
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()); |
| 103 |
|
119 |
|
| - |
|
120 |
printf("Time2: %3.7f %3.7f %3.7f \r\n", TDC_mrange2_get_time(1), TDC_mrange2_get_time(2), TDC_mrange2_get_time(3)); |
| - |
|
121 |
|
| - |
|
122 |
|
| 104 |
//----------------------------------------------- Nastaveni registru |
123 |
//----------------------------------------------- Nastaveni registru |
| 105 |
|
124 |
|
| 106 |
MRange=TDC_MRANGE1; |
125 |
MRange=TDC_MRANGE1; |
| 107 |
hit1=TDC_MRANGE1_HIT1_NOAC; |
126 |
hit1=TDC_MRANGE1_HIT1_NOAC; |
| 108 |
hit2=TDC_MRANGE1_HIT2_NOAC; |
127 |
hit2=TDC_MRANGE1_HIT2_NOAC; |
| Line 128... |
Line 147... |
| 128 |
output_low(START); |
147 |
output_low(START); |
| 129 |
output_low(STOP1); |
148 |
output_low(STOP1); |
| 130 |
output_low(STOP2); |
149 |
output_low(STOP2); |
| 131 |
|
150 |
|
| 132 |
output_high(START); // start of time measurement |
151 |
output_high(START); // start of time measurement |
| 133 |
output_low(START); |
- |
|
| 134 |
|
152 |
|
| 135 |
output_high(STOP2); |
153 |
output_high(STOP2); |
| 136 |
output_high(STOP1); |
154 |
output_high(STOP1); |
| 137 |
|
155 |
|
| 138 |
output_low(STOP2); |
- |
|
| 139 |
output_low(STOP1); |
156 |
output_low(STOP1); |
| - |
|
157 |
output_low(STOP2); |
| 140 |
|
158 |
output_low(START); |
| - |
|
159 |
|
| - |
|
160 |
|
| - |
|
161 |
|
| 141 |
//----------------------------------------------- Pocitani |
162 |
//----------------------------------------------- Pocitani |
| 142 |
|
163 |
|
| 143 |
printf("Time1: %LX %LX %LX %LX \r\n", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4)); |
164 |
printf("Time1: %LX %LX %LX %LX ", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4)); |
| 144 |
printf("Time1: %3.7f %3.7f %3.7f ", TDC_mrange1_get_time(1,0,1,1), TDC_mrange1_get_time(2,0,2,1), TDC_mrange1_get_time(1,1,2,1)); |
- |
|
| 145 |
|
165 |
|
| 146 |
output_low(TDC_ENABLE); //status register |
166 |
output_low(TDC_ENABLE); //status register |
| 147 |
ret8=0; |
167 |
ret8=0; |
| 148 |
ret8=(0b1011<<4)|4; |
168 |
ret8=(0b1011<<4)|4; |
| 149 |
spi_xfer(TDC_stream,ret8,8); |
169 |
spi_xfer(TDC_stream,ret8,8); |
| 150 |
ret16=spi_xfer(TDC_stream,0,16); |
170 |
ret16=spi_xfer(TDC_stream,0,16); |
| 151 |
output_high(TDC_ENABLE); |
171 |
output_high(TDC_ENABLE); |
| - |
|
172 |
|
| 152 |
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()); |
173 |
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()); |
| 153 |
|
174 |
|
| - |
|
175 |
printf("Time1: %3.7f %3.7f %3.7f \r\n", TDC_mrange1_get_time(1,0,1,1), TDC_mrange1_get_time(2,0,2,1), TDC_mrange1_get_time(1,1,2,1)); |
| 154 |
|
176 |
|
| 155 |
/// ----------------------------------------------- Temperature masurement |
177 |
/// ----------------------------------------------- Temperature masurement |
| 156 |
|
178 |
|
| 157 |
TDC_start_temp(); |
179 |
TDC_start_temp(); |
| 158 |
output_low(TDC_ENABLE); //status register |
180 |
output_low(TDC_ENABLE); //status register |