1744 |
kakl |
1 |
#include "main.h" |
|
|
2 |
|
1757 |
kakl |
3 |
#define VERSION 0.1 |
|
|
4 |
|
1759 |
kakl |
5 |
#define START PIN_D4 |
|
|
6 |
#define STOP1 PIN_D5 |
|
|
7 |
#define STOP2 PIN_D6 |
1774 |
kaklik |
8 |
#include "GP2.h" |
1759 |
kakl |
9 |
|
1774 |
kaklik |
10 |
#define ONE_WIRE_PIN PIN_E2 |
|
|
11 |
#include "ds1820.c" |
|
|
12 |
|
1744 |
kakl |
13 |
void main() |
|
|
14 |
{ |
1774 |
kaklik |
15 |
float temperature; |
|
|
16 |
|
1744 |
kakl |
17 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
|
|
18 |
setup_adc(ADC_CLOCK_DIV_2); |
|
|
19 |
setup_psp(PSP_DISABLED); |
|
|
20 |
setup_spi(SPI_SS_DISABLED); |
|
|
21 |
setup_wdt(WDT_OFF); |
|
|
22 |
setup_timer_0(RTCC_INTERNAL); |
|
|
23 |
setup_timer_1(T1_DISABLED); |
|
|
24 |
setup_timer_2(T2_DISABLED,0,1); |
|
|
25 |
setup_ccp1(CCP_OFF); |
|
|
26 |
setup_comparator(NC_NC_NC_NC); |
|
|
27 |
setup_vref(FALSE); |
|
|
28 |
|
1745 |
kakl |
29 |
TDC_reset(); |
1744 |
kakl |
30 |
|
1775 |
kaklik |
31 |
MRange=TDC_MRANGE1; |
1758 |
kakl |
32 |
hitin1=TDC_HITIN1_2; |
1775 |
kaklik |
33 |
hitin2=TDC_HITIN2_2; |
|
|
34 |
hit1=TDC_MRANGE1_HIT1_START; |
|
|
35 |
hit2=TDC_MRANGE1_HIT2_2CH1; |
|
|
36 |
en_int= (TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT); |
1759 |
kakl |
37 |
en_err_val=TDC_ERRVAL_EN; |
|
|
38 |
delval1=0x0; |
|
|
39 |
delval2=0x0; |
|
|
40 |
delval3=0x0; |
1775 |
kaklik |
41 |
calibrate=TDC_CALIBRATE_EN; |
|
|
42 |
disautocal=TDC_AUTOCAL_EN; |
|
|
43 |
|
|
|
44 |
firenum=TDC_FIRENUM_2; |
|
|
45 |
div_fire=TDC_DIV_FIRE_3; |
1758 |
kakl |
46 |
|
|
|
47 |
TDC_update_registers(); |
|
|
48 |
|
1759 |
kakl |
49 |
output_low(START); |
|
|
50 |
output_low(STOP1); |
|
|
51 |
output_low(STOP2); |
1775 |
kaklik |
52 |
|
|
|
53 |
TDC_start_cal_resonator(); |
|
|
54 |
delay_ms(50); |
|
|
55 |
printf("calibrate: %LX, %LX, %LX, %LX \r\n", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4)); |
1759 |
kakl |
56 |
TDC_start_cal(); |
|
|
57 |
delay_ms(50); |
|
|
58 |
|
1744 |
kakl |
59 |
while(true) |
|
|
60 |
{ |
1774 |
kaklik |
61 |
temperature = ds1820_read(); |
1759 |
kakl |
62 |
|
1758 |
kakl |
63 |
TDC_init(); |
1759 |
kakl |
64 |
delay_ms(50); |
1774 |
kaklik |
65 |
printf("Temp: %f \r\n", temperature); |
|
|
66 |
delay_ms(50); |
|
|
67 |
printf("status: %LX \r\n", TDC_get_status()); |
1775 |
kaklik |
68 |
|
1759 |
kakl |
69 |
TDC_start_cycle(); |
1775 |
kaklik |
70 |
|
1759 |
kakl |
71 |
delay_us(10); |
|
|
72 |
output_high(START); |
1775 |
kaklik |
73 |
// delay_us(1); |
1759 |
kakl |
74 |
output_low(START); |
|
|
75 |
|
1775 |
kaklik |
76 |
// delay_us(1); |
1759 |
kakl |
77 |
|
|
|
78 |
output_high(STOP1); |
1775 |
kaklik |
79 |
// delay_us(10); |
1759 |
kakl |
80 |
output_low(STOP1); |
1775 |
kaklik |
81 |
// delay_us(500); |
|
|
82 |
// output_high(STOP1); |
|
|
83 |
// delay_us(10); |
|
|
84 |
// output_low(STOP1); |
|
|
85 |
// delay_us(500); |
|
|
86 |
// output_high(STOP1); |
|
|
87 |
// delay_us(10); |
|
|
88 |
// output_low(STOP1); |
1759 |
kakl |
89 |
|
1775 |
kaklik |
90 |
output_high(STOP2); |
|
|
91 |
// delay_us(10); |
|
|
92 |
output_low(STOP2); |
|
|
93 |
// delay_us(500); |
|
|
94 |
output_high(STOP2); |
|
|
95 |
// delay_us(10); |
|
|
96 |
output_low(STOP2); |
|
|
97 |
// delay_us(500); |
|
|
98 |
output_high(STOP2); |
|
|
99 |
// delay_us(10); |
|
|
100 |
output_low(STOP2); |
|
|
101 |
|
|
|
102 |
output_low(START); |
|
|
103 |
|
|
|
104 |
delay_ms(10); |
1774 |
kaklik |
105 |
printf("status: %LX \r\n", TDC_get_status()); |
1759 |
kakl |
106 |
delay_ms(50); |
1774 |
kaklik |
107 |
printf("measured: %LX, %LX, %LX, %LX \r\n", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4)); |
1744 |
kakl |
108 |
delay_ms(500); |
1759 |
kakl |
109 |
|
1744 |
kakl |
110 |
}; |
|
|
111 |
} |