4617 |
kakl |
1 |
#include "main.h" |
|
|
2 |
|
|
|
3 |
|
|
|
4 |
#define LED PIN_D7 |
|
|
5 |
|
|
|
6 |
#define RECORDS 100 |
|
|
7 |
|
|
|
8 |
void main() |
|
|
9 |
{ |
|
|
10 |
|
|
|
11 |
int16 time, time_new; |
|
|
12 |
int16 log[RECORDS]; |
|
|
13 |
int16 n; |
|
|
14 |
|
|
|
15 |
setup_adc_ports(AN0_TO_AN7|VSS_VDD); |
|
|
16 |
setup_adc(ADC_CLOCK_DIV_2); |
|
|
17 |
setup_psp(PSP_DISABLED); |
|
|
18 |
setup_spi(SPI_SS_DISABLED); |
|
|
19 |
setup_wdt(WDT_OFF); |
|
|
20 |
setup_timer_0(RTCC_EXT_H_TO_L); |
|
|
21 |
setup_timer_1(T1_DISABLED); |
|
|
22 |
setup_timer_2(T2_DISABLED,0,1); |
|
|
23 |
setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
|
|
24 |
setup_ccp1(CCP_OFF); |
|
|
25 |
setup_comparator(NC_NC_NC_NC); |
|
|
26 |
setup_vref(FALSE); |
|
|
27 |
|
|
|
28 |
output_low(LED); |
|
|
29 |
/* |
|
|
30 |
while(true) |
|
|
31 |
{ |
|
|
32 |
output_low(LED); |
|
|
33 |
delay_ms(1); |
|
|
34 |
output_high(LED); |
|
|
35 |
delay_ms(1); |
|
|
36 |
printf("%u\n\r", 0x55); |
|
|
37 |
} |
|
|
38 |
//*/ |
|
|
39 |
n=0; |
|
|
40 |
while(true) |
|
|
41 |
{ |
|
|
42 |
set_timer0(0); |
|
|
43 |
time = 0; |
|
|
44 |
time_new = 0; |
|
|
45 |
while(time_new == 0) |
|
|
46 |
{ |
|
|
47 |
time_new=get_timer0(); |
|
|
48 |
} |
|
|
49 |
output_high(LED); |
|
|
50 |
|
|
|
51 |
while(time != time_new) |
|
|
52 |
{ |
|
|
53 |
time=time_new; |
|
|
54 |
time_new=get_timer0(); |
|
|
55 |
delay_us(5); |
|
|
56 |
} |
|
|
57 |
|
|
|
58 |
if (time>3){ log[n++]=time;} |
|
|
59 |
if (n==RECORDS) |
|
|
60 |
{ |
|
|
61 |
for (n=0; n<RECORDS; n++) printf("%Lu,", log[n]); |
|
|
62 |
printf("\n\r"); |
|
|
63 |
n = 0; |
|
|
64 |
} |
|
|
65 |
output_low(LED); |
|
|
66 |
} |
|
|
67 |
|
|
|
68 |
} |