|
你這個(gè)暫時(shí)看不出問題,我附上我之前參加藍(lán)橋杯時(shí)候的矩陣鍵盤代碼#include "ALL.H"
#include "REG52.H"
/*矩陣鍵盤編號(hào)
1 2 3 4 P3_0
5 6 7 8 P3_1
9 10 11 12 P3_2
13 14 15 16 P3_3
P4_4 P4_2 P3_5 P3_4
*/
unsigned char Matric_Scan(){
unsigned char Num=0;
P3_0=0;
P3_1=P3_2=P3_3=1;
P4_4=P4_2=P3_5=P3_4=1;
if(P4_4==0){
Num=1;
}
else if(P4_2==0){
Num=2;
}
else if(P3_5==0){
Num=3;
}
else if(P3_4==0){
Num=4;
}
P3_1=0;
P3_0=P3_2=P3_3=1;
P4_4=P4_2=P3_5=P3_4=1;
if(P4_4==0){
Num=5;
}
else if(P4_2==0){
Num=6;
}
else if(P3_5==0){
Num=7;
}
else if(P3_4==0){
Num=8;
}
P3_2=0;
P3_0=P3_1=P3_3=1;
P4_4=P4_2=P3_5=P3_4=1;
if(P4_4==0){
Num=9;
}
else if(P4_2==0){
Num=10;
}
else if(P3_5==0){
Num=11;
}
else if(P3_4==0){
Num=12;
}
P3_3=0;
P3_0=P3_1=P3_2=1;
P4_4=P4_2=P3_5=P3_4=1;
if(P4_4==0){
Num=13;
}
else if(P4_2==0){
Num=14;
}
else if(P3_5==0){
Num=15;
}
else if(P3_4==0){
Num=16;
}
return Num;
}
void Matric_Show_Num(){
if(Matric_Scan()==1){
Display(1,1);
}
else if(Matric_Scan()==2){
Display(1,2);
}
else if(Matric_Scan()==3){
Display(1,3);
}
else if(Matric_Scan()==4){
Display(1,4);
}
else if(Matric_Scan()==5){
Display(1,5);
}
else if(Matric_Scan()==6){
Display(1,6);
}
else if(Matric_Scan()==7){
Display(1,7);
}
else if(Matric_Scan()==8){
Display(1,8);
}
else if(Matric_Scan()==9){
Display(1,9);
}
else if(Matric_Scan()==10){
Display(1,10);
}
else if(Matric_Scan()==11){
Display(1,11);
}
else if(Matric_Scan()==12){
Display(1,12);
}
else if(Matric_Scan()==13){
Display(1,13);
}
else if(Matric_Scan()==14){
Display(1,14);
}
else if(Matric_Scan()==15){
Display(1,15);
}
else if(Matric_Scan()==16){
Display(1,16);
}
}
應(yīng)該會(huì)有幫助 |
|