#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar code shumaguan[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar code table[] = {0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
uchar key = 0;
void delays(int ms)
{
int i;
int j;
for(i = 0;i<ms;i++)
for(j = 0; j<124;j++);
}
void matrixkeyscan()
{
uchar temp;
P0 = 0xfe;
temp = P0;
temp = temp & 0xf0;
if(temp != 0xf0)
{
delays(10);
temp = P0;
temp = temp & 0xf0;
if(temp != 0xf0)
{
temp = P0;
switch(temp)
{
case 0xee:
key = 0;
break;
case 0xde:
key = 1;
break;
case 0xbe:
key = 2;
break;
case 0x7e:
key = 3;
break;
}
while(temp != 0xf0)
{
temp = P0 ;
temp = temp & 0xf0;
}
//display() ;
}
}
P0 = 0xfd;
temp = P0;
temp = temp & 0xf0;
if(temp != 0xf0)
{
delays(10);
temp = P0;
temp = temp & 0xf0;
if(temp != 0xf0)
{
temp = P0;
switch(temp)
{
case 0xed:
key = 4;
break;
case 0xdd:
key = 5;
break;
case 0xbd:
key = 6;
break;
case 0x7d:
key = 7;
break;
}
while(temp != 0xf0)
{
temp = P0 ;
temp = temp & 0xf0;
}
//display() ;
}
}
P0 = 0xfb;
temp = P0;
temp = temp & 0xf0;
if(temp != 0xf0)
{
delays(10);
temp = P0;
temp = temp & 0xf0;
if(temp != 0xf0)
{
temp = P0;
switch(temp)
{
case 0xeb:
key = 8;
break;
case 0xdb:
key = 9;
break;
case 0xbb:
key = 10;
break;
case 0x7b:
key = 11;
break;
}
while(temp != 0xf0)
{
temp = P0 ;
temp = temp & 0xf0;
}
//display() ;
}
}
P0 = 0xf7;
temp = P0;
temp = temp & 0xf0;
if(temp != 0xf0)
{
delays(10);
temp = P0;
temp = temp & 0xf0;
if(temp != 0xf0)
{
temp = P0;
switch(temp)
{
case 0xe7:
key = 12;
break;
case 0xd7:
key = 13;
break;
case 0xb7:
key = 14;
break;
case 0x77:
key = 15;
break;
}
while(temp != 0xf0)
{
temp = P0 ;
temp = temp & 0xf0;
}
//display() ;
}
}
}
void main()
{
while(1)
{
matrixkeyscan();
P2 = table[0];
P1 = shumaguan[key];
}
}
今天,新讲的扫描,没有搞懂。 知道如何控制行,但,对于列的控制,很是不明白、。
期待,详细解释、
此帖出自
小平头技术问答
一周热门 更多>