void scan()
{
INT8U tmp_num;
PORTB=0xfe;
key_num=PORTB;
key_num&=0xf0;
if(key_num!=0xf0)
{
__delay_ms(10);
key_num=PORTB;
key_num&=0xf0;
if(key_num!=0xf0)
{
tmp_num=key_num;
while(tmp_num!=0xf0)
{
tmp_num=PORTB;
tmp_num&=0xf0;
}
key_num|=0x0e;
}
}
PORTB=0xfd;
key_num=PORTB;
key_num&=0xf0;
if(key_num!=0xf0)
{
__delay_ms(10);
key_num=PORTB;
key_num&=0xf0;
if(key_num!=0xf0)
{
tmp_num=key_num;
while(tmp_num!=0xf0)
{
tmp_num=PORTB;
tmp_num&=0xf0;
}
key_num|=0x0d;
}
}
PORTB=0xfb;
key_num=PORTB;
key_num&=0xf0;
if(key_num!=0xf0)
{
__delay_ms(10);
key_num=PORTB;
key_num&=0xf0;
if(key_num!=0xf0)
{
tmp_num=key_num;
while(tmp_num!=0xf0)
{
tmp_num=PORTB;
tmp_num&=0xf0;
}
key_num|=0x0b;
}
}
PORTB=0xf7;
key_num=PORTB;
key_num&=0xf0;
if(key_num!=0xf0)
{
__delay_ms(10);
key_num=PORTB;
key_num&=0xf0;
if(key_num!=0xf0)
{
tmp_num=key_num;
while(tmp_num!=0xf0)
{
tmp_num=PORTB;
tmp_num&=0xf0;
}
key_num|=0x07;
}
}
}
void handle()
{
switch(key_num)
{
case 0xee:count=0;break;
case 0xde:count=1;break;
case 0xbe:count=2;break;
case 0x7e:count=3;break;
case 0xed:count=4;break;
case 0xdd:count=5;break;
case 0xbd:count=6;break;
case 0x7d:count=7;break;
case 0xeb:count=8;break;
case 0xdb:count=9;break;
case 0xbb:count=10;break;
case 0x7b:count=11;break;
case 0xe7:count=12;break;
case 0xd7:count=13;break;
case 0xb7:count=14;break;
case 0x77:count=15;break;
}
}
这是矩阵键盘扫描代码可我在进入sacn()函数后发现程序卡在那里了,一直循环
我用的是PORTB接的键盘 RB0接0 RB1接1 .........
谢谢了
-
这是键盘原理图
那你仿真看一下你的程序出不来,死在哪儿了呢?
一周热门 更多>