51单片机。4*4矩阵键盘程序,帮我看下if((key1+1)&&(key+1))这条语句是什么意思和在程序的作用
#include<reg51.h>#defineucharunsignedcharuchartemp;intkey1,key,disbuf;//此表为LED的字模0123...
#include<reg51.h>
#define uchar unsigned char
uchar temp;
int key1,key,disbuf;
// 此表为 LED 的字模 0 1 2 3 4 5 6 7 8 9 a b cd e f
unsigned char code LED7Code[] = {~0x3F,~0x06,~0x5B,~0x4F,~0x66,~0x6D,~0x7D,~0x07,~0x7F,~0x6F,~0x77,~0x7C,~0x39,~0x5E,~0x79,~0x71};
void delay(uchar z)
{
uchar i,j;
for(i=0;i<120;i++)
for(j=0;j<z;j++);
}
void scan() //要是按键了,扫描键盘编码值
{
P0=0xF0;
delay(1);
temp=P0;
switch(temp)
{
case 0xe0: key1=0; break;
case 0xd0: key1=1; break;
case 0xb0: key1=2; break;
case 0x70: key1=3; break;
}
P0=0x0f;
delay(1);
temp=P0;
switch(temp)
{
case 0x0E: key=key1+0; break;
case 0x0D: key=key1+4; break;
case 0x0B: key=key1+8; break;
case 0x07: key=key1+12;break;
default : key=-1;
}
if((key1+1)&&(key+1))
disbuf=key;
}
void ejjc() //判断是否按键
{
P0=0xF0;
if(P0!=0xF0)
scan();
}
void main()
{
while(1)
{
ejjc();
P3=LED7Code[disbuf];
delay(200);
}
} 展开
#define uchar unsigned char
uchar temp;
int key1,key,disbuf;
// 此表为 LED 的字模 0 1 2 3 4 5 6 7 8 9 a b cd e f
unsigned char code LED7Code[] = {~0x3F,~0x06,~0x5B,~0x4F,~0x66,~0x6D,~0x7D,~0x07,~0x7F,~0x6F,~0x77,~0x7C,~0x39,~0x5E,~0x79,~0x71};
void delay(uchar z)
{
uchar i,j;
for(i=0;i<120;i++)
for(j=0;j<z;j++);
}
void scan() //要是按键了,扫描键盘编码值
{
P0=0xF0;
delay(1);
temp=P0;
switch(temp)
{
case 0xe0: key1=0; break;
case 0xd0: key1=1; break;
case 0xb0: key1=2; break;
case 0x70: key1=3; break;
}
P0=0x0f;
delay(1);
temp=P0;
switch(temp)
{
case 0x0E: key=key1+0; break;
case 0x0D: key=key1+4; break;
case 0x0B: key=key1+8; break;
case 0x07: key=key1+12;break;
default : key=-1;
}
if((key1+1)&&(key+1))
disbuf=key;
}
void ejjc() //判断是否按键
{
P0=0xF0;
if(P0!=0xF0)
scan();
}
void main()
{
while(1)
{
ejjc();
P3=LED7Code[disbuf];
delay(200);
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询