求各位指导,先谢谢了。
电路图在图片附件中
这是源程序
#include "reg52.h"
#define uchar unsigned char
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66};
void delay()
{uchar i,j;
for(i=0;i<255;i++)
for(j=0;j<255;j++);
}
uchar keyscan()
{uchar keyv,temp;
keyv=0;
P2=0xff;
temp=P2;
if(~(P2&temp))
{switch(temp)
{case 0xfe:
keyv=1;break;
case 0xfd:
keyv=2;break;
case 0xfb:
keyv=3;break;
case 0xf7:
keyv=4;break;
default:
keyv=0;break;
}
}
return keyv;
}
void main ()
{
unsigned char leds;
while(1)
{leds=keyscan();
P1=table[leds];
delay();
}
}
-
这是仿真图
功能是实现按键状态显示,按下几号键数码管就显示几,没键按下或者多键按下显示0.源程序如下:
#include "reg52.h"
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66};
unsigned char keyscan()
{unsigned char keyv,temp;
keyv=0;
P2=0xff;
temp=P2;
if(~(P2&temp))
{switch(temp)
{case 0xfe:
keyv=1;break;
case 0xfd:
keyv=2;break;
case 0xfb:
keyv=3;break;
case 0xf7:
keyv=4;break;
default:
keyv=0;break;
}
}
return keyv;
}
void main ()
{
unsigned char ledshow;
while(1)
{ledshow=keyscan();
P1=table[ledshow];
}
}
无论怎么按键,为什么数码管不亮呢?请你帮忙看下,谢谢了。
仿真电路
一周热门 更多>