標題: 單片機矩陣鍵盤,按鍵顯示數(shù)字Proteus仿真代碼 [打印本頁]

作者: 14003    時間: 2022-3-23 16:04
標題: 單片機矩陣鍵盤,按鍵顯示數(shù)字Proteus仿真代碼
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)

矩陣鍵盤,按鍵顯示數(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)





歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1