#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit wei=P2^7;
sbit duan=P2^6;
uchar du[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
uchar we[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void delay(uint a)
{uint i,j;
for(i=a;i>0;i--)
for(j=110;j>0;j--)
;
}
void display(uchar num)
{
duan=1;
P0=du[num];
duan=0;
}
void keycan()
{uchar key,keyl,keyh,l;
P1=0x00;
P3=0x0f;
keyl=P3;
keyl=keyl&0x0f;
if(keyl!=0x0f)
{delay(10);
if(keyl!=0x0f)
{
keyl=keyl<<4;
keyl=keyl|0x0f;
keyh=P1;
keyh=keyh&0x0f;
keyl=keyl&0xf0;
key=keyl+keyh;
}
switch(key)
{ case 0xee :l=0;break;
case 0xde :l=1;break;
case 0xbe :l=2;break;
case 0x7e :l=3;break;
case 0xed :l=4;break;
case 0xdd :l=5;break;
case 0xbd :l=6;break;
case 0x7d :l=7;break;
case 0xeb :l=8;break;
case 0xdb :l=9;break;
case 0xbb :l=10;break;
case 0x7b :l=11;break;
case 0xe7 :l=12;break;
case 0xd7 :l=13;break;
case 0xb7 :l=14;break;
case 0x77 :l=15;break;
}
display(l);
}
}
void main()
{
wei=1;
P0=0x02;
wei=0;
while(1)
{
keycan();
}
}
数码管上显示对应的按键
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
太他妈的感谢您了 大神
一周热门 更多>