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
| char mask[16] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x5F, 0x7C, 0x58, 0x5E, 0x7B, 0x71};
char prevVal = 20;
void main() {
P0 = 0x00;
P1 = 0x0F;
P2 = 0x00;
P3 = 0x00;
while(1) {
if((P1 & 0x0F) != prevVal) {
Delay_ms(50);
switch(P1 & 0x0F) {
case 0:
P2 = mask[0];
break;
case 1:
P2 = mask[1];
break;
case 2:
P2 = mask[2];
break;
case 3:
P2 = mask[3];
break;
case 4:
P2 = mask[4];
break;
case 5:
P2 = mask[5];
break;
case 6:
P2 = mask[6];
break;
case 7:
P2 = mask[7];
break;
case 8:
P2 = mask[8];
break;
case 9:
P2 = mask[9];
break;
case 10:
P2 = mask[10];
break;
case 11:
P2 = mask[11];
break;
case 12:
P2 = mask[12];
break;
case 13:
P2 = mask[13];
break;
case 14:
P2 = mask[14];
break;
case 15:
P2 = mask[15];
break;
};
prevVal = P1 & 0x0F;
}
}
} |