1 |
#include "main.h" |
1 |
#include "main.h" |
2 |
|
2 |
|
3 |
#include "GP2.h" |
- |
|
4 |
|
- |
|
5 |
#define VERSION 0.1 |
3 |
#define VERSION 0.1 |
6 |
|
4 |
|
7 |
#define START PIN_D4 |
5 |
#define START PIN_D4 |
8 |
#define STOP1 PIN_D5 |
6 |
#define STOP1 PIN_D5 |
9 |
#define STOP2 PIN_D6 |
7 |
#define STOP2 PIN_D6 |
- |
|
8 |
#include "GP2.h" |
- |
|
9 |
|
- |
|
10 |
#define ONE_WIRE_PIN PIN_E2 |
- |
|
11 |
#include "ds1820.c" |
10 |
|
12 |
|
11 |
void main() |
13 |
void main() |
12 |
{ |
14 |
{ |
- |
|
15 |
float temperature; |
- |
|
16 |
|
13 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
17 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
14 |
setup_adc(ADC_CLOCK_DIV_2); |
18 |
setup_adc(ADC_CLOCK_DIV_2); |
15 |
setup_psp(PSP_DISABLED); |
19 |
setup_psp(PSP_DISABLED); |
16 |
setup_spi(SPI_SS_DISABLED); |
20 |
setup_spi(SPI_SS_DISABLED); |
17 |
setup_wdt(WDT_OFF); |
21 |
setup_wdt(WDT_OFF); |
18 |
setup_timer_0(RTCC_INTERNAL); |
22 |
setup_timer_0(RTCC_INTERNAL); |
19 |
setup_timer_1(T1_DISABLED); |
23 |
setup_timer_1(T1_DISABLED); |
20 |
setup_timer_2(T2_DISABLED,0,1); |
24 |
setup_timer_2(T2_DISABLED,0,1); |
21 |
setup_ccp1(CCP_OFF); |
25 |
setup_ccp1(CCP_OFF); |
22 |
setup_comparator(NC_NC_NC_NC); |
26 |
setup_comparator(NC_NC_NC_NC); |
23 |
setup_vref(FALSE); |
27 |
setup_vref(FALSE); |
24 |
|
28 |
|
25 |
TDC_reset(); |
29 |
TDC_reset(); |
26 |
|
30 |
|
27 |
hit1=TDC_MRANGE2_HIT1_START; |
31 |
hit1=TDC_MRANGE2_HIT1_START; |
28 |
hit2=TDC_MRANGE2_HIT2_2CH1; |
32 |
hit2=TDC_MRANGE2_HIT2_2CH1; |
29 |
hitin1=TDC_HITIN1_2; |
33 |
hitin1=TDC_HITIN1_2; |
30 |
hitin2=TDC_HITIN1_0; |
34 |
hitin2=TDC_HITIN1_0; |
31 |
en_int= 0xFF; //TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT; |
35 |
en_int= 0xFF; //TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT; |
32 |
en_err_val=TDC_ERRVAL_EN; |
36 |
en_err_val=TDC_ERRVAL_EN; |
33 |
delval1=0x0; |
37 |
delval1=0x0; |
34 |
delval2=0x0; |
38 |
delval2=0x0; |
35 |
delval3=0x0; |
39 |
delval3=0x0; |
36 |
|
40 |
|
37 |
TDC_update_registers(); |
41 |
TDC_update_registers(); |
38 |
|
42 |
|
39 |
output_low(START); |
43 |
output_low(START); |
40 |
output_low(STOP1); |
44 |
output_low(STOP1); |
41 |
output_low(STOP2); |
45 |
output_low(STOP2); |
42 |
|
46 |
|
43 |
TDC_start_cal(); |
47 |
TDC_start_cal(); |
44 |
delay_ms(50); |
48 |
delay_ms(50); |
45 |
|
49 |
|
46 |
while(true) |
50 |
while(true) |
47 |
{ |
51 |
{ |
- |
|
52 |
temperature = ds1820_read(); |
48 |
|
53 |
|
49 |
/* delay_ms(500); |
- |
|
50 |
hit2=0x00; |
- |
|
51 |
hit1=0x00; |
- |
|
52 |
TDC_update_registers(); |
- |
|
53 |
printf("reg1: %X \n", TDC_get_reg1()); |
- |
|
54 |
|
- |
|
55 |
TDC_reset(); |
- |
|
56 |
delay_ms(50); |
- |
|
57 |
printf("reg1: %X \n", TDC_get_reg1()); |
- |
|
58 |
*/ |
- |
|
59 |
TDC_init(); |
54 |
TDC_init(); |
60 |
delay_ms(50); |
55 |
delay_ms(50); |
- |
|
56 |
printf("Temp: %f \r\n", temperature); |
- |
|
57 |
delay_ms(50); |
61 |
printf("status: %LX \n", TDC_get_status()); |
58 |
printf("status: %LX \r\n", TDC_get_status()); |
62 |
delay_us(10); |
59 |
delay_us(10); |
63 |
TDC_start_cycle(); |
60 |
TDC_start_cycle(); |
64 |
delay_us(10); |
61 |
delay_us(10); |
65 |
output_high(START); |
62 |
output_high(START); |
66 |
delay_us(1); |
63 |
delay_us(1); |
67 |
output_low(START); |
64 |
output_low(START); |
68 |
|
65 |
|
69 |
delay_us(500); |
66 |
delay_us(500); |
70 |
|
67 |
|
71 |
output_high(STOP1); |
68 |
output_high(STOP1); |
72 |
delay_us(10); |
69 |
delay_us(10); |
73 |
output_low(STOP1); |
70 |
output_low(STOP1); |
74 |
delay_us(500); |
71 |
delay_us(500); |
75 |
output_high(STOP1); |
72 |
output_high(STOP1); |
76 |
delay_us(10); |
73 |
delay_us(10); |
77 |
output_low(STOP1); |
74 |
output_low(STOP1); |
78 |
delay_us(500); |
75 |
delay_us(500); |
79 |
output_high(STOP1); |
76 |
output_high(STOP1); |
80 |
delay_us(10); |
77 |
delay_us(10); |
81 |
output_low(STOP1); |
78 |
output_low(STOP1); |
82 |
|
79 |
|
83 |
delay_ms(100); |
80 |
delay_ms(100); |
84 |
printf("status: %LX \n", TDC_get_status()); |
81 |
printf("status: %LX \r\n", TDC_get_status()); |
85 |
delay_ms(50); |
82 |
delay_ms(50); |
86 |
printf("measured: %LX, %LX, %LX, %LX \n", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4)); |
83 |
printf("measured: %LX, %LX, %LX, %LX \r\n", TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4)); |
87 |
delay_ms(500); |
84 |
delay_ms(500); |
88 |
|
85 |
|
89 |
}; |
86 |
}; |
90 |
} |
87 |
} |