编了个C语言的键盘程序有点问题,请指点下!
[复制链接]
做了个机械手,想用键盘来控制抓,放物品,现在他显示字符时有点错,高手能帮我在keil里跑下,把我的这个错改下吗?谢谢了!原程序如下:(P2.0--P2.7 是段选,P1.0--P1.5是位选,P0.0--P0.3是列选,P0.4--P0.7是行选)
#include #define uchar unsigned char
#define uint unsigned int
code char tab[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x80};
void delay (void){
uchar i;
for(i=254;i>0;i--);
}
uchar keyscan(void){
uchar sccode, recode;
P3=0xf0;
if((P3&0xf0)!=0xf0)
{
delay();
if ((P3&0xf0)!=0xf0)
{
sccode=0xfe; //键盘逐行扫描
while((sccode&0x10)!=0)
{
P3=sccode;
if ((P3&0xf0)!=0xf0)
{
recode=(P3 & 0xf0); //被按键的行玛
sccode=sccode&0x0f;
return((sccode)+(recode));
}
else sccode=(sccode<<1)|0x01; //修改扫描玛
}
}
}
void display (uchar keydisp) 这句要改 {
uchar keytab[18]= {0x7e,0x7d,0x7b,0x77,0xbd,0xbb,0xb7,0xdb,0xd7,0xbe,0xde,0xee,0xed,0xeb,0xe7;}
uchar m;
for(m=0;m<16; m++)
{
if (keytab[m]==keydisp) //查键码表,m为键值
{
P2=0xfe;
P0=tam[m]; //键值显示
}
}
}
void main()
{
uchar key;
P2=0xfe; P0=0x40
P3=0xff;
if(P3==0xff)
{
while(1)
{
key=keyscan();
display(key);
}
}
}