小弟求教高手,有个程序弄不明白了
为什么下面的程序如果不加temp=k;而直接return(k);现象是只有按住键不松才会显示相应的数字,而加上temp=k;和return(k);就会在按键松开后仍然显示相应数字,实在是搞不明白了,麻烦大家了。#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[] ={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7f,0x39,0x3f,0x79,0x71,0x76};
uchar code led[] = {0,1,2,3,4,5,6,7,8,9,10};
uchar temp,num,num1 ;
void delay(uint z);
uchar keyscan();
void main()
{
P2=led;
P0=table;
while(1)
{
num1=keyscan();
P0=table;
}
}
void delay(uint z)
{
uchar x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
uchar keyscan()
{
uchar key,key1,key2,k,temp;
P1=0XFE;
P1=0XF0;
k=0xff;
if((P1&0XF0)!=0XF0)
{
delay(5);
if((P1&0XF0)!=0XF0)
key1=P1&0XF0;
P1=0X0F;
if((P1&0X0F)!=0X0F)
{
delay(5);
if((P1&0X0F)!=0X0F)
{
key2=P1&0X0F;
key=key1|key2;
if(key!=0xff)
{
switch(key)
{
case 0xee: k=0;break;
case 0xed: k=1;break;
case 0xeb: k=2;break;
case 0xe7: k=3; break;
case 0xde: k=4;break;
case 0xdd: k=5;break;
case 0xdb: k=6;break;
case 0xd7: k=7; break;
case 0xbe: k=8;break;
case 0xbd: k=9;break;
case 0xbb: k=10;break;
case 0xb7: k=11; break;
case 0x7e: k=12;break;
case 0x7d: k=13;break;
case 0x7b: k=14;break;
case 0x77: k=15; break;
}
temp=k;
}
}
}
}
return(temp);
} 是return(temp);打错了,呵呵回复【楼主位】zhulinshenchu
-----------------------------------------------------------------------
页:
[1]