仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
51hei.gif (81.16 KB, 下載次數(shù): 65)
下載附件
2022-3-24 17:57 上傳
矩陣鍵盤,按鍵顯示數(shù)字
單片機源程序如下:
#include<reg51.h>
#define uchar unsigned char
sbit L1=P1^0;
sbit L2=P1^1;
sbit L3=P1^2;
sbit L4=P1^3;
uchar dis[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
unsigned int time;
delay(time)
{
unsigned int j;
for(j=0;j<time;j++)
{}
}
main()
{
uchar temp;
uchar i;
while(1)
{
P1=0xef;
for(i=0;i<=3;i++)
{
if(L1==0)P0=dis[i*4+0];
if(L2==0)P0=dis[i*4+1];
if(L3==0)P0=dis[i*4+2];
if(L4==0)P0=dis[i*4+3];
delay(500);
temp=P1;
temp=temp|0x0f;
temp=temp<<1;
temp=temp|0x0f;
P1=temp;
}
}
}
Keil代碼與Proteus仿真下載:
矩陣鍵盤模塊.7z
(52.73 KB, 下載次數(shù): 28)
2022-3-24 17:58 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|