是你的程序还有其它问题,这在你的程序基础上完善后的仿真。
#include<reg52.h>
#define KEY P1
unsigned char j;
unsigned char i;
unsigned char code table[]={
0x01,0x02,0x03,0x04,
0x05,0x06,0x07,0x08,
0x09,0x0a,0x0b,0x0c,
0x0d,0x0e,0x0f,0x10};
void delay(unsigned int x)
{
unsigned char i;
while(x--)
{
for(i=123;i>0;i--);
}
}
void key_scan(void)
{
char row;//DD
char list;//áD
char val;
unsigned char keyvalue[] = {0x77,0x7b,0x7d,0x7e,0xb7,0xbb,0xbd,0xbe,0xd7,0xdb,0xdd,0xde,0xe7,0xeb,0xed,0xee,};
KEY = 0xf0;
if(KEY != 0xf0)
{
delay(20);
if(KEY != 0xf0)
{
row = KEY&0xf0;
KEY = 0x0f;
list= KEY&0x0f;
val = row|list;
for(i = 0; i < 16; i++)
{
if(val == keyvalue)
{
j=table;
while(KEY != 0x0f);//松手检测
break;
}
}
}
}
}
void main()
{
while(1)
{
key_scan();
P3=j;
}
}
|