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的话,松开手后立即就不显示了,请问谁能帮我解释一下。
以下是引用guantingwei在2003-9-4 20:35:29的发言: 编码键盘? |
以下是引用月如镜在2003-9-4 23:40:41的发言: 请问如何在一个程序里调用2个定时中断,一显示,一键盘。[quote]以下是引用guantingwei在2003-9-4 20:35:29的发言: 编码键盘? [/quote] 不知,这样的程序该怎么初始化。 |
以下是引用月如镜在2003-9-6 0:32:51的发言: 对,一个是显示中断,一个是键盘中断,电路已设计好,请问:该怎样对系统进行初始化。 |