-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdip.c
62 lines (54 loc) · 1.14 KB
/
dip.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
#include "dip.h"
#include <mcs51/lint.h>
#include <mcs51/8051.h>
#include "stc15w.h"
/* dip mapping:
1 = P1.2
2 = P1.3
3 = P1.4
4 = P1.5
5 = P1.6
6 = P1.7
7 = P5.4
8 = P5.5
9 = P3.2
10 = P3.3
*/
void dipInit()
{
//we use the quasi-bi-directional mode.
//This is the default thus we dont have to configure the mode.
//turn on the pullups
P1_2 = 1;
P1_3 = 1;
P1_4 = 1;
P1_5 = 1;
P1_6 = 1;
P1_7 = 1;
P5_4 = 1;
P5_5 = 1;
P3_2 = 1;
P3_3 = 1;
}
unsigned short readDmxAddr()
{
//initialize unused bits as 1 (will later be inverted to 0)
unsigned short result = 0xfe00;
result = result | P1_2;
result = result | (P1_3 << 1);
result = result | (P1_4 << 2);
result = result | (P1_5 << 3);
result = result | (P1_6 << 4);
result = result | (P1_7 << 5);
result = result | (P5_4 << 6);
result = result | (P5_5 << 7);
result = result | (P3_2 << 8);
//due to the pullups we read a 1 when the dip is in off-position.
//thus invert every pin
result = ~result;
return result;
}
unsigned char readFunctionDip()
{
return !P3_3;
}