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