标题: 单片机4x4矩阵式按键,ISIS仿真+编程 [打印本页]

作者: afeigg    时间: 2018-11-29 16:17
标题: 单片机4x4矩阵式按键,ISIS仿真+编程
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)


单片机源程序如下:
  1. #include<reg51.h>
  2. unsigned int key;
  3. unsigned int temp;
  4. void delay(unsigned int x);
  5. unsigned char code tabll[]={
  6. 0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
  7. 0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x00};
  8. sbit c1=P2^4;
  9. sbit c2=P2^5;
  10. sbit c3=P2^6;
  11. sbit c4=P2^7;
  12. void main()
  13. {
  14.      while(1)
  15.      {
  16.           P2=0xff;
  17.           c1=0;
  18.           temp=P2;
  19.           if((temp&0x0f)!=0x0f)
  20.           {
  21. //                delay(10);
  22.                 temp=P2;
  23.                 if((temp&0x0f)!=0x0f)
  24.                 {
  25.                      switch(temp)
  26.                      {
  27.                      case 0xee:key=3;break;
  28.                      case 0xed:key=2;break;
  29.                      case 0xeb:key=1;break;
  30.                      case 0xe7:key=0;break;
  31.                      }
  32.                 P0=tabll[key];
  33.                 }
  34.            }
  35.             P2=0xff;
  36.           c2=0;
  37.           temp=P2;
  38.           if((temp&0x0f)!=0x0f)
  39.           {
  40.                 delay(10);
  41.                 temp=P2;
  42.                 if((temp&0x0f)!=0x0f)
  43.                 {
  44.                      switch(temp)
  45.                      {
  46.                      case 0xde:key=7;break;
  47.                      case 0xdd:key=6;break;
  48.                      case 0xdb:key=5;break;
  49.                      case 0xd7:key=4;break;
  50.                      }
  51.                 P0=tabll[key];
  52.                 }
  53.            }
  54.           P2=0xff;
  55.           c3=0;
  56.           temp=P2;
  57.           if((temp&0x0f)!=0x0f)
  58.           {
  59.                 delay(10);
  60.                 temp=P2;
  61.                 if((temp&0x0f)!=0x0f)
  62.                 {
  63.                      switch(temp)
  64.                      {
  65.                      case 0xbe:key=11;break;
  66.                      case 0xbd:key=10;break;
  67.                      case 0xbb:key=9;break;
  68.                      case 0xb7:key=8;break;
  69.                      }
  70.                 P0=tabll[key];
  71.                 }
  72.            }
  73.           P2=0xff;
  74.           c4=0;
  75.           temp=P2;
  76.           if((temp&0x0f)!=0x0f)
  77.           {
  78.                 delay(10);
  79.                 temp=P2;
  80.                 if((temp&0x0f)!=0x0f)
  81.                 {
  82.                      switch(temp)
  83.                      {
  84.                      case 0x7e:key=15;break;
  85.                      case 0x7d:key=14;break;
  86.                      case 0x7b:key=13;break;
  87.                      case 0x77:key=12;break;
  88.                      }
  89.                      P0=tabll[key];
  90.                  }
  91.              }
  92.           }
  93.        }
  94.        void delay(unsigned int x)
  95.        {
  96.        unsigned int i,j;
  97.        for(i=x;i>0;i--)
  98.            for(j=200;j>0;j--);
  99.        }
复制代码

所有资料51hei提供下载:
4x4矩阵式按键.rar (51.13 KB, 下载次数: 30)



作者: FJT1226954678    时间: 2019-3-31 23:06
下载看看




欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1