本文包含原理图、PCB、源代码、封装库、中英文PDF等资源
您需要 登录 才可以下载或查看,没有账号?注册会员
×
#include<reg51.h>
char led_mod[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x58,0x5e,0x79,0x71};
char key_buf[]={0x11,0x21,0x41,0x81,0x12,0x22,0x42,0x82,0x14,0x24,0x44,0x84,0x18,0x28,0x48,0x88};
char getkey(void);
void delay(unsigned int time)
{
unsigned char j = 0;
for(;time>0;time--)
{
for(j=0;j<125;j++);
}
}
void main(void)
{
char key=0;
P2=0x000;
while(1)
{
key=getkey();
if(key!=-1)
{
P2=led_mod[key];
}
delay(10);
}
}
char getkey(void)
{
char k1=0,k2=0,i=0;
P3=0xf0;
delay(10);
if(P3!=0xf0)
{
k1=P3;
delay(10);
if(P3==k1)
{
P3=0x0f;
delay(10);
k2=P3&k1;
for(i=0;i<16;i++)
{
if(key_buf[i]==k2)
{
return i;
}
}
}
}
return-1;
}
这个程序P3=0x0f;
delay(10);
k2=P3&k1;执行后高位肯定是0啊!为什么key_buf[]的值高位不是0呢??? |