找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

帖子
查看: 2159|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

4*4矩陣鍵盤調(diào)試程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:299427 發(fā)表于 2018-3-30 14:46 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit d1=P2^0;
sbit d2=P2^1;
sbit d3=P2^2;
sbit d4=P2^3;
uchar code table[]={0xcf,0xa4,0xb0,0x88};
void delay(uint z);
uchar temp;
int num;
void main()
{
d1=0;
d2=0;
d3=0;
d4=0;
while(1)
{
  P1=0x7f;
  temp=P1;
  temp=temp&0x0f;
  while(temp!=0x0f)
  { delay(5);
   temp=P1;
   temp=temp&0x0f;
    while(temp!=0x0f)
    { temp=P1;
     switch(temp)
     {
       case 0x77: num=0;
     break;
     case 0x7b: num=1;
     break;
     case 0x7d: num=2;
     break;
     case 0x7e: num=3;
     break;
     }
     while(temp!=0x0f)  //松手檢測
      {
       temp=P1;
       temp=temp&0x0f;
      }
      P0=table[num];
       }
  }
        P1=0xbf;
  temp=P1;
  temp=temp&0x0f;
  while(temp!=0x0f)
  { delay(5);
   temp=P1;
   temp=temp&0x0f;
    while(temp!=0x0f)
    { temp=P1;
     switch(temp)
     {
       case 0xb7: num=0;
     break;
     case 0xbb: num=1;
     break;
     case 0xbd: num=2;
     break;
     case 0xbe: num=3;
     break;
     }
     while(temp!=0x0f)
      {
       temp=P1;
       temp=temp&0x0f;
      }
      P0=table[num];
       }
  }
        P1=0xdf;
  temp=P1;
  temp=temp&0x0f;
  while(temp!=0x0f)
  { delay(5);
   temp=P1;
   temp=temp&0x0f;
    while(temp!=0x0f)
    { temp=P1;
     switch(temp)
     {
       case 0xd7: num=0;
     break;
     case 0xdb: num=1;
     break;
     case 0xdd: num=2;
     break;
     case 0xde: num=3;
     break;
     }
      while(temp!=0x0f)
      {
       temp=P1;
       temp=temp&0x0f;
      }
      P0=table[num];
       }
  }
        P1=0xef;
  temp=P1;
  temp=temp&0x0f;
  while(temp!=0x0f)
  { delay(5);
   temp=P1;
   temp=temp&0x0f;
    while(temp!=0x0f)
    { temp=P1;
     switch(temp)
     {
       case 0xe7: num=0;
     break;
     case 0xeb: num=1;
     break;
     case 0xed: num=2;
     break;
     case 0xee: num=3;
     break;
     }
     while(temp!=0x0f)
      {
       temp=P1;
       temp=temp&0x0f;
      }
      P0=table[num];
       }
  }         
}     
}
void delay(uint z)
{
uint x;
uchar y;
for(x=1000;x>0;x--)
  for(y=z;y>0;y--);
}
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:298786 發(fā)表于 2018-4-22 15:54 | 只看該作者
怎么不可以打包啊
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表