-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
79 lines (71 loc) · 1.49 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/******* pic_lightbarrier *******************************************************************
* *
* Autor: Nicolas Jeker *
* Datum: 28.10.2013 *
* *
* Kurzbeschreibung: Light barrier wth optional Display and (optional) external IR-LEDs, *
* -Receivers and Relay. *
* *
********************************************************************************************/
#include "config/board_config.h"
char burst, received = 0;
int antiburst, flag = 0;
/**
* Interrupt Service Routine (High Priority)
*/
void interrupt isr()
{
if (TMR0IF && TMR0IE)
{
TMR0IF = 0; // reset interrupt flag
TMR0 = TMR0_PRELOAD; // generates 38 kHz burst
if (burst)
{
IR2 = !IR2;
}
antiburst++; // counter
// after 10 pulses
if (burst && (antiburst == 20))
{
IR2 = 0; // just to be sure
antiburst = 0; // reset counter
burst = 0; // disable burst mode
received = !IR_R2;
}
// it's time for the next burst
if (!burst && (antiburst == 1000))
{
antiburst = 0; // reset counter
burst = 1; // enable next burst
}
return; // get me out of here!
}
}
/**
* Main Subroutine
*/
int main()
{
init();
LED0_R = 0; // Power-LED (inverted!)
while (1)
{
// pseudo-loopdelay
for (int i = 0; i < 10000; ++i)
{
__delay_us(1);
if (received)
{
flag++;
}
}
if (flag >= 10)
{
LED1_B = 1;
} else {
LED1_B = 0;
}
flag = 0;
}
return 0;
}