Rev 2181 Rev 2183
1 #include "main.h" 1 #include "main.h"
2   2  
3 #use fast_io (D) 3 #use fast_io (D)
4   4  
5 #define START PIN_D4 5 #define START PIN_D4
6 #define STOP1 PIN_D5 6 #define STOP1 PIN_D5
7 #define STOP2 PIN_D7 7 #define STOP2 PIN_D7
8   8  
9 #define FIRE_DETECT PIN_D6 9 #define FIRE_DETECT PIN_D6
10   10  
11 #define MODE_SELECT PIN_A4 //switch measurement (pulse generator) modes 11 #define MODE_SELECT PIN_A4 //switch measurement (pulse generator) modes
12   12  
13 void main() 13 void main()
14 { 14 {
15   15  
16 setup_adc_ports(NO_ANALOGS|VSS_VDD); 16 setup_adc_ports(NO_ANALOGS|VSS_VDD);
17 setup_adc(ADC_CLOCK_DIV_2); 17 setup_adc(ADC_CLOCK_DIV_2);
18 setup_psp(PSP_DISABLED); 18 setup_psp(PSP_DISABLED);
19 setup_spi(SPI_SS_DISABLED); 19 setup_spi(SPI_SS_DISABLED);
20 setup_wdt(WDT_OFF); 20 setup_wdt(WDT_OFF);
21 setup_timer_0(RTCC_INTERNAL); 21 setup_timer_0(RTCC_INTERNAL);
22 setup_timer_1(T1_DISABLED); 22 setup_timer_1(T1_DISABLED);
23 setup_timer_2(T2_DISABLED,0,1); 23 setup_timer_2(T2_DISABLED,0,1);
24 setup_timer_3(T3_DISABLED|T3_DIV_BY_1); 24 setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
25 setup_ccp1(CCP_OFF); 25 setup_ccp1(CCP_OFF);
26 setup_comparator(NC_NC_NC_NC); 26 setup_comparator(NC_NC_NC_NC);
27 setup_vref(FALSE); 27 setup_vref(FALSE);
28   28  
29 SET_TRIS_D( 0b00000100 ); 29 SET_TRIS_D( 0b00000100 );
30   30  
31 while(true) 31 while(true)
32 { 32 {
33 delay_ms(50); 33 delay_ms(50);
34 output_low(START); 34 output_low(START);
35 output_low(STOP1); 35 output_low(STOP1);
36 output_low(STOP2); 36 output_low(STOP2);
37   37  
38 // Mode 1 38 // Mode 1
39 if(input(MODE_SELECT)) 39 if(input(MODE_SELECT))
40 { 40 {
41 while(!input(FIRE_DETECT)); 41 while(!input(FIRE_DETECT));
42 output_high(START); // start of time measurement 42 output_high(START); // start of time measurement
43   43  
44 output_high(STOP2); 44 output_high(STOP2);
45 output_high(STOP1); 45 output_high(STOP1);
46 46
47 output_low(START); 47 output_low(START);
48 output_low(STOP2); 48 output_low(STOP2);
49 output_low(STOP1); 49 output_low(STOP1);
50   50  
51 output_high(STOP2); 51 output_high(STOP2);
52 output_high(STOP1); 52 output_high(STOP1);
53 53
54 output_low(STOP2); 54 output_low(STOP2);
55 output_low(STOP1); 55 output_low(STOP1);
56   56  
57 } 57 }
58 // mode 2 58 // mode 2
59 59
60   60  
61 if(!input(MODE_SELECT)) 61 if(!input(MODE_SELECT))
62 { 62 {
63 output_high(STOP2); // Merime jenom jednim kanalem (druhy musi byt v H) -  
64 while(!input(FIRE_DETECT)); 63 while(!input(FIRE_DETECT));
65   64  
66 output_high(START); 65 output_high(START);
67 output_low(START); 66 output_low(START);
68 delay_us(150); 67 delay_us(150);
69 68
70 output_high(STOP1); 69 output_high(STOP1);
71 output_low(STOP1); 70 output_low(STOP1);
72 delay_us(1); 71 delay_us(1);
73 72
74 output_high(STOP1); 73 output_high(STOP1);
75 output_low(STOP1); 74 output_low(STOP1);
76 delay_us(10); 75 delay_us(10);
77 76
78 output_high(STOP1); 77 output_high(STOP1);
79 output_low(STOP1); 78 output_low(STOP1);
80 } 79 }
81 } 80 }
82 } 81 }