Line 1... |
Line 1... |
1 |
#include "main.h" |
1 |
#include "main.h" |
2 |
#include <math.h> |
2 |
#include <math.h> |
- |
|
3 |
#include <stdlib.h> |
- |
|
4 |
|
3 |
|
5 |
|
4 |
#define INTN_PIN PIN_D7 |
6 |
#define INTN_PIN PIN_D7 |
5 |
#include "GP2.h" |
7 |
#include "GP2.h" |
6 |
|
8 |
|
7 |
#define VERSION "0.2" |
9 |
#define VERSION "0.2" |
8 |
|
10 |
|
9 |
#define ONE_WIRE_PIN PIN_E2 |
11 |
#define ONE_WIRE_PIN PIN_E2 |
10 |
#include "ds1820.c" |
12 |
#include "ds1820.c" |
11 |
|
13 |
|
- |
|
14 |
|
12 |
void main() |
15 |
void get_string(char* s, unsigned int8 max) |
13 |
{ |
16 |
{ |
14 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
- |
|
15 |
setup_adc(ADC_CLOCK_DIV_2); |
- |
|
16 |
setup_spi(SPI_SS_DISABLED); |
17 |
unsigned int8 len; |
17 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
- |
|
18 |
setup_timer_1(T1_DISABLED); |
- |
|
19 |
setup_timer_2(T2_DISABLED,0,1); |
- |
|
20 |
setup_ccp1(CCP_OFF); |
18 |
char c; |
21 |
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard |
- |
|
22 |
|
19 |
|
- |
|
20 |
--max; |
- |
|
21 |
len=0; |
- |
|
22 |
do { |
23 |
TDC_reset(); |
23 |
c=getc(); |
- |
|
24 |
if(c==8) { // Backspace |
- |
|
25 |
if(len>0) { |
- |
|
26 |
len--; |
- |
|
27 |
putc(c); |
- |
|
28 |
putc(' '); |
- |
|
29 |
putc(c); |
- |
|
30 |
} |
- |
|
31 |
} else if ((c>=' ')&&(c<='~')) |
- |
|
32 |
if(len<=max) { |
- |
|
33 |
s[len++]=c; |
- |
|
34 |
putc(c); |
- |
|
35 |
} |
- |
|
36 |
} while(c!=13); |
24 |
delay_ms(50); |
37 |
s[len]=0; |
- |
|
38 |
} |
25 |
|
39 |
|
- |
|
40 |
signed int16 get_int() { |
- |
|
41 |
char s[5]; |
- |
|
42 |
signed int16 i; |
- |
|
43 |
|
- |
|
44 |
get_string(s, 7); |
- |
|
45 |
|
- |
|
46 |
i=atoi(s); |
26 |
while(TRUE) |
47 |
return(i); |
- |
|
48 |
} |
- |
|
49 |
|
- |
|
50 |
void temperature_measurement() /// Temperature masurement by TDC and dallas sensor |
- |
|
51 |
|
27 |
{ |
52 |
{ |
- |
|
53 |
//For temperature measurement TDC unit must be initialised in measurement mode2 this is not destribed in datasheet!! |
- |
|
54 |
TDC_reset(); |
- |
|
55 |
en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT; // eneble all possible interrupt flags |
- |
|
56 |
en_err_val=TDC_ERRVAL_EN; // enable of error value output |
- |
|
57 |
clkhsdiv=TDC_CLKHSDIV_4; // divide clkHS by 4 |
28 |
|
58 |
|
- |
|
59 |
portnum=TDC_TPORTNUM_4; |
- |
|
60 |
Tcycle=TDC_TCYCLE_SHORT; |
- |
|
61 |
fakenum=TDC_TFAKENUM_2; |
- |
|
62 |
selclkT=TDC_TSELCLK_128HS; |
- |
|
63 |
|
29 |
//----------------------------------------------- Nastaveni registru |
64 |
TDC_update_registers(); |
- |
|
65 |
delay_ms(10); |
30 |
|
66 |
|
- |
|
67 |
TDC_init(); |
- |
|
68 |
delay_ms(50); |
- |
|
69 |
|
- |
|
70 |
TDC_start_temp(); |
- |
|
71 |
While(input(INTN_PIN)); // waiting for interrupt flag |
- |
|
72 |
|
- |
|
73 |
printf("$TDC%s TMP %10LU %10LU %10LU %10LU ", VERSION, TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4)); |
- |
|
74 |
printf("%f \r\n",ds1820_read()+273.15); |
- |
|
75 |
|
- |
|
76 |
} |
- |
|
77 |
|
- |
|
78 |
void measurementM2() |
- |
|
79 |
{ |
31 |
TDC_reset(); |
80 |
TDC_reset(); |
32 |
delay_ms(50); |
81 |
delay_ms(50); |
33 |
MRange=TDC_MRANGE2; // sets measurement mode |
82 |
MRange=TDC_MRANGE2; // sets measurement mode |
34 |
hit1=TDC_MRANGE2_HIT1_START; |
83 |
hit1=TDC_MRANGE2_HIT1_START; |
35 |
hitin1=TDC_HITIN1_4; // set nomber of hits on channel 1 |
84 |
hitin1=TDC_HITIN1_4; // set nomber of hits on channel 1 |
Line 59... |
Line 108... |
59 |
//----------------------------------------------- Pocitani |
108 |
//----------------------------------------------- Pocitani |
60 |
|
109 |
|
61 |
printf("$TDC%s M2 ", VERSION); |
110 |
printf("$TDC%s M2 ", VERSION); |
62 |
printf("%3.7f %3.7f %3.7f \r\n", TDC_mrange2_get_time(1), TDC_mrange2_get_time(2), TDC_mrange2_get_time(3)); |
111 |
printf("%3.7f %3.7f %3.7f \r\n", TDC_mrange2_get_time(1), TDC_mrange2_get_time(2), TDC_mrange2_get_time(3)); |
63 |
|
112 |
|
- |
|
113 |
} |
- |
|
114 |
|
- |
|
115 |
|
64 |
TDC_init(); |
116 |
void main() |
- |
|
117 |
{ |
- |
|
118 |
|
- |
|
119 |
char command[20]; |
- |
|
120 |
char tmp[5]; |
- |
|
121 |
|
- |
|
122 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
- |
|
123 |
setup_adc(ADC_CLOCK_DIV_2); |
- |
|
124 |
setup_spi(SPI_SS_DISABLED); |
- |
|
125 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
- |
|
126 |
setup_timer_1(T1_DISABLED); |
- |
|
127 |
setup_timer_2(T2_DISABLED,0,1); |
- |
|
128 |
setup_ccp1(CCP_OFF); |
- |
|
129 |
setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard |
65 |
|
130 |
|
- |
|
131 |
TDC_reset(); |
- |
|
132 |
delay_ms(50); |
66 |
|
133 |
|
- |
|
134 |
while(TRUE) |
- |
|
135 |
{ |
- |
|
136 |
get_string(command, 20); |
- |
|
137 |
|
- |
|
138 |
strcpy(tmp,"TM"); |
67 |
//----------------------------------------------- Nastaveni registru |
139 |
if (stricmp(command, tmp)) temperature_measurement(); |
- |
|
140 |
strcpy(tmp,"M2"); |
- |
|
141 |
if (stricmp(command, tmp)) measurementM2(); |
68 |
|
142 |
|
69 |
/* MRange=TDC_MRANGE1; |
143 |
/* MRange=TDC_MRANGE1; |
70 |
hit1=TDC_MRANGE1_HIT1_NOAC; |
144 |
hit1=TDC_MRANGE1_HIT1_NOAC; |
71 |
hit2=TDC_MRANGE1_HIT2_NOAC; |
145 |
hit2=TDC_MRANGE1_HIT2_NOAC; |
72 |
hitin1=TDC_HITIN1_1; |
146 |
hitin1=TDC_HITIN1_1; |
Line 102... |
Line 176... |
102 |
|
176 |
|
103 |
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)); |
177 |
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)); |
104 |
|
178 |
|
105 |
|
179 |
|
106 |
*/ |
180 |
*/ |
107 |
/// ----------------------------------------------- Temperature masurement |
- |
|
108 |
TDC_reset(); |
- |
|
109 |
delay_ms(50); |
- |
|
110 |
|
- |
|
111 |
//For temperature measurement TDC unit must be initialised in measurement mode2 this is not destribed in datasheet!! |
- |
|
112 |
|
- |
|
113 |
hit1=TDC_MRANGE2_HIT1_START; |
- |
|
114 |
hitin1=TDC_HITIN1_4; // set number of hits on channel 1 |
- |
|
115 |
hitin2=TDC_HITIN2_0; // disable channel 2 (normal state for this mode) |
- |
|
116 |
en_int= TDC_INT_ALU | TDC_INT_ENDHIT | TDC_INT_TIMEOUT; // eneble all possible interrupt flags |
- |
|
117 |
en_err_val=TDC_ERRVAL_EN; // enable of error value output |
- |
|
118 |
clkhsdiv=TDC_CLKHSDIV_4; // divide clkHS by 4 |
- |
|
119 |
|
- |
|
120 |
portnum=TDC_TPORTNUM_4; |
- |
|
121 |
Tcycle=TDC_TCYCLE_SHORT; |
- |
|
122 |
fakenum=TDC_TFAKENUM_2; |
- |
|
123 |
selclkT=TDC_TSELCLK_128HS; |
- |
|
124 |
|
- |
|
125 |
TDC_update_registers(); |
- |
|
126 |
delay_ms(10); |
- |
|
127 |
|
181 |
|
128 |
TDC_init(); |
- |
|
129 |
delay_ms(50); |
- |
|
130 |
|
- |
|
131 |
TDC_start_temp(); |
- |
|
132 |
|
- |
|
133 |
printf("$TDC%s TMP %10LU %10LU %10LU %10LU ", VERSION, TDC_get_measurement(1), TDC_get_measurement(2), TDC_get_measurement(3), TDC_get_measurement(4)); |
- |
|
134 |
printf("%f \r\n",ds1820_read()+273.15); |
- |
|
135 |
} |
182 |
} |
136 |
} |
183 |
} |