仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x00};//0-f-最后一个空
uchar j=1;
sbit p37=P3^7;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display(uchar shu)
{
P1=table[shu];
delay(5);
}
uchar keyscan()
{
uchar temp,num;
P2=0xfe;
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
p37=0;
delay(5);
temp=P2;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P2;
switch(temp)
{
case 0xee:num=1;break;
case 0xde:num=2;break;
case 0xbe:num=3;break;
default:break;
}
while(temp!=0xf0)//**********松手检测 松手后显示
{
j=0;
temp=P2;
temp=temp&0xf0;
}
}
}p37=1;
P2=0xfd;
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
p37=0;
delay(5);
temp=P2;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P2;
switch(temp)
{
case 0xed:num=4;break;
case 0xdd:num=5;break;
case 0xbd:num=6;break;
}
while(temp!=0xf0)
{
j=0;
temp=P2;
temp=temp&0xf0;
}
}
}p37=1;
P2=0xfb;
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
p37=0;
delay(5);
temp=P2;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P2;
switch(temp)
{
case 0xeb:num=7;break;
case 0xdb:num=8;break;
case 0xbb:num=9;break;
}
while(temp!=0xf0)
{
j=0;
temp=P2;
temp=temp&0xf0;
}
}
}p37=1;
P2=0xf7;
temp=P2;
temp=temp&0xf0;
if(temp!=0xf0)
{
p37=0;
delay(5);
temp=P2;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P2;
switch(temp)
{
case 0xe7:num=16;break;
case 0xd7:num=0;break;
case 0xb7:num=16;break;
}
while(temp!=0xf0)
{
j=0;
temp=P2;
temp=temp&0xf0;
}
}
}p37=1;
//if(j==1)num=16;
return num;
}
void main()
{
p37=1;
while(1)
{
display(keyscan());
//display(7);
}
}
仿真.7z
(117.53 KB, 下载次数: 72)
视频.7z
(6.02 MB, 下载次数: 14)
|