1 |
#include "main.h" |
1 |
#include "main.h" |
2 |
|
2 |
|
3 |
|
3 |
|
4 |
#define LED PIN_B2 |
4 |
#define LED PIN_B2 |
5 |
#define TRAFO1 PIN_B1 |
5 |
#define TRAFO1 PIN_B1 |
6 |
#define TRAFO2 PIN_A2 |
6 |
#define TRAFO2 PIN_A2 |
7 |
#define ALERT PIN_B5 |
7 |
#define ALERT PIN_B5 |
8 |
#define OPTRON PIN_A0 |
8 |
#define OPTRON PIN_A0 |
9 |
|
9 |
|
10 |
|
10 |
|
11 |
void main() |
11 |
void main() |
12 |
{ |
12 |
{ |
13 |
output_high(ALERT); |
13 |
output_high(ALERT); |
14 |
|
14 |
|
15 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
15 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
16 |
setup_adc(ADC_CLOCK_DIV_2); |
16 |
setup_adc(ADC_CLOCK_DIV_2); |
17 |
setup_spi(SPI_SS_DISABLED); |
17 |
setup_spi(SPI_SS_DISABLED); |
18 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
18 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
19 |
// setup_wdt(WDT_1152MS|WDT_DIV_16); |
19 |
// setup_wdt(WDT_1152MS|WDT_DIV_16); |
20 |
setup_wdt(WDT_288MS); |
20 |
setup_wdt(WDT_288MS); |
21 |
setup_timer_1(T1_DISABLED); |
21 |
setup_timer_1(T1_DISABLED); |
22 |
setup_timer_2(T2_DISABLED,0,1); |
22 |
setup_timer_2(T2_DISABLED,0,1); |
23 |
setup_ccp1(CCP_OFF); |
23 |
setup_ccp1(CCP_OFF); |
24 |
setup_comparator(NC_NC_NC_NC); |
24 |
setup_comparator(NC_NC_NC_NC); |
25 |
setup_vref(FALSE); |
25 |
setup_vref(FALSE); |
26 |
setup_oscillator(OSC_1MHZ|OSC_TIMER1); |
26 |
setup_oscillator(OSC_1MHZ|OSC_TIMER1); |
27 |
|
27 |
|
28 |
restart_wdt(); |
28 |
restart_wdt(); |
29 |
|
29 |
|
30 |
while(true) |
30 |
while(true) |
31 |
{ |
31 |
{ |
32 |
int8 n; |
32 |
int8 n; |
33 |
|
33 |
|
34 |
for(n=0;n<165;n++) // 20ms |
34 |
for(n=0;n<165;n++) // 20ms |
35 |
{ |
35 |
{ |
36 |
output_low(TRAFO1); |
36 |
output_low(TRAFO1); |
37 |
output_high(TRAFO2); |
37 |
output_high(TRAFO2); |
38 |
delay_us(28); // 121us |
38 |
delay_us(28); // 121us |
39 |
output_high(TRAFO1); |
39 |
output_high(TRAFO1); |
40 |
output_low(TRAFO2); |
40 |
output_low(TRAFO2); |
41 |
} |
41 |
} |
42 |
restart_wdt(); |
42 |
restart_wdt(); |
43 |
output_high(TRAFO1); |
43 |
output_high(TRAFO1); |
44 |
output_high(TRAFO2); |
44 |
output_high(TRAFO2); |
45 |
output_toggle(LED); |
45 |
output_toggle(LED); |
46 |
delay_ms(100); |
46 |
delay_ms(100); |
47 |
restart_wdt(); |
47 |
restart_wdt(); |
48 |
|
48 |
|
49 |
int16 i; |
49 |
int16 i; |
50 |
|
50 |
|
51 |
for(i=0;i<3000;i++) |
51 |
for(i=0;i<1300;i++) |
52 |
{ |
52 |
{ |
53 |
delay_ms(1); |
53 |
delay_ms(1); |
54 |
restart_wdt(); |
54 |
restart_wdt(); |
55 |
if(input(OPTRON)==0) |
55 |
if(input(OPTRON)==0) |
56 |
{ |
56 |
{ |
57 |
output_low(ALERT); |
57 |
output_low(ALERT); |
58 |
while(TRUE) restart_wdt(); |
58 |
while(TRUE) restart_wdt(); |
59 |
} |
59 |
} |
60 |
} |
60 |
} |
61 |
} |
61 |
} |
62 |
} |
62 |
} |
63 |
|
63 |
|