-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path键盘扫描2.c
131 lines (130 loc) · 1.72 KB
/
键盘扫描2.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
123
124
125
126
127
128
129
130
131
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar temp;
sbit d0=P1^0;
void delay(uchar z)
{
uchar x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
uchar keyscan()
{
uchar num,flag=0;
while(1)
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
switch(temp)
{
case 0xee:num=0;break;
case 0xde:num=1;break;
case 0xbe:num=2;break;
case 0x7e:num=3;break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
flag=1;
}
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
switch(temp)
{
case 0xed:num=0;break;
case 0xdd:num=1;break;
case 0xbd:num=2;break;
case 0x7d:num=3;break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
flag=1;
}
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
switch(temp)
{
case 0xeb:num=0;break;
case 0xdb:num=1;break;
case 0xbb:num=2;break;
case 0x7b:num=3;break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
flag=1;
}
}
}
P3=0xf7;
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
if(temp!=0xf0)
{
switch(temp)
{
case 0xe7:num=0;break;
case 0xd7:num=1;break;
case 0xb7:num=2;break;
case 0x77:num=3;break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
flag=1;
}
}
}
if(flag==1)
{
flag=0;
return num;
}
}
}
void main()
{
while(1)
{
d0=keyscan();
}
}