-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRF.c
122 lines (92 loc) · 1.85 KB
/
RF.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#define PAYLOAD_SIZE 48
#define PULSE_WIDTH_SMALL 500
long buttons[] = {
859124533L,
861090613L,
892547893L,
1395864373L,
859124563L,
861090643L,
892547923L,
1395864403L,
859125043L,
861091123L,
892548403L,
1395864883L,
859132723L,
861098803L,
892556083L,
1395872563L
};
void sendData(long payload1, long payload2)
{
long mask;
char state;
int ii;
int jj;
long payload;
char bitt;
mask = 1;
state = 1;
ii = 0;
jj = 0;
payload = payload1;
// Send a preamble of 13 ms low pulse
GPIO.B2 = 0;
for (ii = 0; ii < 26; ii++)
{
Delay_us(PULSE_WIDTH_SMALL);
}
// send sync pulse : high for 0.5 ms
GPIO.B2 = 1;
Delay_us(PULSE_WIDTH_SMALL);
GPIO.B2 = 0;
// Now send the digits.
// We send a 1 as a state change for 1.5ms, and a 0 as a state change for 0.5ms
for (jj = 0; jj < PAYLOAD_SIZE; jj++)
{
if (jj == 32)
{
payload = payload2;
mask = 1;
}
bitt = (payload & mask) ? 1 : 0;
mask <<= 1;
state = !state;
GPIO.B2 = state;
Delay_us(PULSE_WIDTH_SMALL);
if (bitt)
{
Delay_us(PULSE_WIDTH_SMALL);
Delay_us(PULSE_WIDTH_SMALL);
}
}
}
void simulate_button(int channel, int button, int on)
{
long payload1;
long payload2;
int ii;
payload1 = buttons[(channel - 1) * 4 + (button - 1)];
payload2 = on? 13107L : 21299L;
ii = 0;
// Send the data 6 times
for (ii = 0; ii < 6; ii++)
{
sendData(payload1, payload2);
}
}
void main() {
TRISIO = 0b00000000; //IO GP2=out
while(1)
{
GPIO.B2 = 1;
Delay_ms(1);
GPIO.B2 = 0;
Delay_ms(1);
simulate_button(1, 1, 1);
Delay_ms(5000);
simulate_button(1, 1, 0);
Delay_ms(5000);
}
}