大家看看这个程序,可否解释一下
#include <reg51.h>
sbit PinScanKey1=P1^4;
sbit PinScanKey2=P1^5;
sbit PinScanKey3=P1^6;
sbit PinScanKey4=P0^4;
sbit PinScanKey5=P0^3;
#define TRUE 1
#define FALSE 0
#define DELAY_value 5
unsigned char a[8];
unsigned char bdata count;
sbit count0=count^0;
sbit count1=count^1;
sbit count2=count^2;
sbit p2_4=P2^4;
sbit p0_6=P0^6;
sbit p0_5=P0^5;
code unsigned char tb[31]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6,0xee,0x3e,0x9c,0x7a,0x9e,0x8e,0x2e,0x1c,0x72,0x2a,0x3a,0xce,0x7c,0x00,0x10,0x80,0x02,0x82,0x1e,0x12,0x92};
/* ?0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,h,l,j,n,o,p,u,dark,low-,high-,mid-,high=,t,low=,三?``
*/
void delay(short i);
void keyinit(void);
unsigned char keyscan(void);
void coms() interrupt 1
{ TH0=0xf8;
TL0=30;
SBUF=tb[a[count]];
p2_4=count0;
p0_6=count1;
p0_5=count2;
while(TI) {
TI=0; }
if(count <7)count++;
else count=0;
}
void sinit(void)
{SCON=0;
TMOD=1;
TH0=0x80;
TL0=0x20;
TR0=1;
EA=1;
ET0=1;
TI=0;
}
void keyinit(void)
{PinScanKey1=1;
PinScanKey2=1;
PinScanKey3=1;
PinScanKey4=1;
PinScanKey5=1;
}
void delay(short i)
{
int k=0;
k=i*DELAY_value;
while(k--);
}
unsigned char keyscan()
{ if((PinScanKey1==FALSE)&&(PinScanKey2==FALSE))
{delay(DELAY_value);
if((PinScanKey1==FALSE)&&(PinScanKey2==FALSE))
{delay(DELAY_value);
if((PinScanKey1==FALSE)&&(PinScanKey2==FALSE))
return 6;}
}
if((PinScanKey1==FALSE)&&(PinScanKey3==FALSE))
{delay(DELAY_value);
if((PinScanKey1==FALSE)&&(PinScanKey3==FALSE))
{delay(DELAY_value);
if((PinScanKey1==FALSE)&&(PinScanKey3==FALSE))
return 7;}
}
if(PinScanKey1==FALSE)
{delay(DELAY_value);
if(PinScanKey1==FALSE)
{delay(DELAY_value);
if(PinScanKey1==FALSE)
return 1;}
}
if(PinScanKey2==FALSE)
{delay(DELAY_value);
if(PinScanKey2==FALSE)
{delay(DELAY_value);
if(PinScanKey2==FALSE)
return 2;}
}
if(PinScanKey3==FALSE)
{delay(DELAY_value);
if(PinScanKey3==FALSE)
{delay(DELAY_value);
if(PinScanKey3==FALSE)
return 3;}
}
if(PinScanKey4==FALSE)
{delay(DELAY_value);
if(PinScanKey4==FALSE)
{delay(DELAY_value);
if(PinScanKey4==FALSE)
return 4;}
}
if(PinScanKey5==FALSE)
{delay(DELAY_value);
if(PinScanKey5==FALSE)
{delay(DELAY_value);
if(PinScanKey5==FALSE)
return 5;}
}
else return(a[7]);
}
void main(void)
{
sinit();
do
{keyinit();
a[7]=keyscan();
}while(1);
}
这个程序是按键后,从数码管显示出来,比如按了1键,会显示1,按5会显示5,按1和2会显示6,按1和3会显示7,但是有一点,就是在按1到4这四个键时,没有问题,不按键时,数码管继续显示,但是5和6,7的话,松开手后立即就不显示了,请问谁能帮我解释一下。
发表时间:2003年9月3日22:39:54