#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar code dular[]={ //0~7列表
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,0};
uchar num,temp;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
P2=0x00;
while(1)
{
P0=0; // 第一列掃描
P3=0x7f;
temp=P3;
temp=temp&0x0f;
while(temp!=0x0f) //去抖
{
delay(5);
temp=P3;
temp=temp&0x0f;
while(temp!=0x0f)
{
temp=P3;
switch(temp)
{
case 0x7e: num=0;
break;
case 0x7d: num=1;
break;
case 0x7b: num=2;
break;
case 0x77: num=3;
break;
}
P0=dular[num]; //問題所在處
}
}
P0=0; //第二列掃描
P3=0xbf;
temp=P3;
temp=temp&0x0f;
while(temp!=0x0f) //去抖
{
delay(5);
temp=P3;
temp=temp&0x0f;
while(temp!=0x0f)
{
temp=P3;
switch(temp)
{
case 0xbe: num=4;
break;
case 0xbd: num=5;
break;
case 0xbb: num=6;
break;
case 0xb7: num=7;
break;
}
P0=dular[num];
}
}
}
}
設計一個4*2的鍵盤,怎么在掃描完第一列后再掃描第二列時沒反應了,必須復位后再掃描第二列才顯示“4,5,6,7”,查資料說沒有跳出第一列掃描程序的while(temp!=0x0f),怎么修改,望各位大蝦編譯成功后告訴小弟,謝謝了
|