標(biāo)題: 可用的不錯(cuò)的單片機(jī)矩陣鍵盤例子 [打印本頁]

作者: yangdejin    時(shí)間: 2018-7-11 15:37
標(biāo)題: 可用的不錯(cuò)的單片機(jī)矩陣鍵盤例子
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機(jī)源程序如下:
  1. /*
  2. * name:     main.c
  3. * founction:key        work
  4. */
  5. #include <reg52.h>
  6. #include <intrins.h>
  7. #include "../mydefine/mydefine.h"
  8. #include "../delay/delay.h"

  9. //鍵盤掃描函數(shù)
  10. uchar Key_scan(void)
  11. {
  12.         uchar i,j, temp, Buffer[4] = {0xef, 0xdf, 0xbf, 0x7f};
  13.         for(i=0; i<4; i++)
  14.         {
  15.                 P1 = Buffer[i];
  16.                 delay(200);                                                  
  17.                 temp = 0x01;                                                                                                                                                                    
  18.                 for(j=0; j<4; j++)
  19.                 {
  20.                         if(!(P1 & temp))
  21.                         {
  22.                                 return (i+j*4);
  23.                         }
  24.                         temp <<= 1;
  25.                 }       
  26.         }
  27. }
  28. //主函數(shù)
  29. void Main(void)
  30. {
  31.         uchar Key_Value;        //定義鍵值
  32.         while(1)
  33.         {
  34.                 P1 = 0xf0;
  35.                 if(P1 != 0xf0)
  36.                 {
  37.                         Delay_1ms(10);        //按鍵消抖
  38.                         if(P1 != 0xf0)
  39.                         {
  40.                                 Key_Value = Key_scan();               
  41.                         }
  42.                 }
  43.                 P2 = table[Key_Value];       
  44.         }
  45. }
復(fù)制代碼

所有資料51hei提供下載:
【可用】不錯(cuò)的矩陣鍵盤例子.rar (149.28 KB, 下載次數(shù): 7)







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