/***********键盘扫描*************/
void key_getch()
{
uchar X,Y,Z;
PORTB=0X0F;
if(PORTB!=0X0F)
{
Dly_ms(10);//延时10ms,消除抖动
if(PORTB!=0X0F)
{
X=PORTB;
PORTB=0XF0;
Y=PORTB;
Z=X|Y;
switch(Z)
{
case 0x77:k=0;break;
case 0xb7:k=1;break;
case 0xd7:k=2;break;
case 0xe7:k=3;break;
case 0x7b:k=4;break;
case 0xbb:k=5;break;
case 0xdb:k=6;break;
case 0xeb:k=7;break;
case 0x7d:k=8;break;
case 0xbd:k=9;break;
case 0xdd:
state=1;break;
case 0xed:
chn_disp (12,0x80,tab1);
chn_disp (2,0x8E,tab2);
break;
case 0x7e:
state=0;
kk=0;
clrram ();
break;
case 0xbe:
state=2;
break;
case 0xde:k='E';break;
case 0xee:k='F';break;
default: break;
}
试试这个
是4*4键盘的
程序能编译
没有报错误
#define KEY_MASK 0xf0
#define KEYIO PORTA
void DelayKey(int cnt)
{
int i,j;
for(i=0;i<cnt;i++)
{
j=0x1300;
while(j--);
}
}
void KeyInt(void)
{
DDRA=~KEY_MASK;
}
unsigned char KeyScan()
{
unsigned char key,ch;
KEYIO=0xf0;
key=KEYIO;
if(key!=KEY_MASK)
{
DelayKey(10);
DDRA=KEY_MASK;
KEYIO=0x0f;
ch=KEYIO;
while(KEYIO & 0x0f !=0xf0);
key|=ch;
switch(key)
{
case 0xee:key=0x00;break;
case 0xde:key=0x01;break;
case 0xbe:key=0x02;break;
case 0x7e:key=0x03;break;
case 0xed:key=0x04;break;
case 0xdd:key=0x05;break;
case 0xbd:key=0x06;break;
case 0x7d:key=0x07;break;
case 0xeb:key=0x08;break;
case 0xdb:key=0x09;break;
case 0xbb:key=0x0a;break;
case 0x7b:key=0x0b;break;
case 0xe7:key=0x0c;break;
case 0xd7:key=0x0d;break;
case 0xb7:key=0x0e;break;
case 0x77:key=0x0f;break;
}
return key;
}
key=KEY_MASK;
return KEY_MASK;
}