各位老师好,帮忙看个程序。我的按键按下没有反应。
#include <reg52.h>
sbit dua=P2^2;
sbit wei=P2^3;
//unsigned char key;
unsigned char code table[]=
{0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
0x76,0x79,0x38,0x3f};
void delay(unsigned int t)
{
while(t--);
}
keyscan()
{
unsigned char h,l;
P3=0xf0;
//h=P3&0xf0;
if(P3!=0xf0)
{
delay(500);
if(P3!=0xf0)
{
h=P3;
P3=0x0f;
l=P3;
h=h|l;
while(h!=0xf0);
delay(500);
}
switch(h)
{
case 0xee:return 0;break;
case 0xde:return 1;break;
case 0xbe:return 2;break;
case 0x7e:return 3;break;
case 0xed:return 4;break;
case 0xdd:return 5;break;
case 0xbd:return 6;break;
case 0x7d:return 7;break;
case 0xeb:return 8;break;
case 0xdb:return 9;break;
case 0xbb:return 10;break;
case 0x7b:return 11;break;
case 0xe7:return 12;break;
case 0xd7:return 13;break;
case 0xb7:return 14;break;
case 0x77:return 15;break;
//default:return 0xff;break;
}
}
}
void display(unsigned char i)
{
wei=1;
P0=0;
wei=0;
dua=1;
P0=table[i];
dua=0;
}
void main()
{
while(1)
{
keyscan();
display(keyscan());
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
老师你说怎么改一下能好呢?
一周热门 更多>