程序如下:
#include <reg51.h>
#include <intrins.h>
#define uchar unsigned char
uchar code a[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,};
void delay(uchar ms)
{
uchar i,j;
for(i=ms;i<ms;i++)
for(j=0;j<125;j++);
}
uchar saomiao()
{
uchar gk;
P2=0x0f;
gk=P2;
if(gk==0x0f)
return(0);
else return(1);
}
uchar keyscan()
{
uchar i,j,scancode,n,m,k,w=0,v;
if(saomiao())
{
delay(5);
if(saomiao())
{
scancode=0xf7;
for(i=0;i<4;i++)
{
P2=scancode;
m=P2;n=0x10;
for(j=0;j<4;j++)
{
k=n&m;
if(k==0)
{
v=w+j;
while(saomiao());
return(v);
}
n=_crol_(n,1);
}
scancode=_cror_(scancode,1);
w+=4;
}
}
else return(0xff);
}else return(0xff);
}
void main()
{
while(1)
{
if(saomiao()==0) con
tinue;
P1=a[keyscan()];
delay(10);
}
为什么后三行的按键可以正常运行,而第一行的就不行。。调试时发现当第一行按键按下时程序中k=0x80,不是应该为0吗。。求帮助。
-
proteus电路图
嗯 谢谢,我i说怎么找都找不到错误。。
一周热门 更多>