|
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
單片機(jī)源程序如下:
- /*
- * name: main.c
- * founction:key work
- */
- #include <reg52.h>
- #include <intrins.h>
- #include "../mydefine/mydefine.h"
- #include "../delay/delay.h"
- //鍵盤(pán)掃描函數(shù)
- uchar Key_scan(void)
- {
- uchar i,j, temp, Buffer[4] = {0xef, 0xdf, 0xbf, 0x7f};
- for(i=0; i<4; i++)
- {
- P1 = Buffer[i];
- delay(200);
- temp = 0x01;
- for(j=0; j<4; j++)
- {
- if(!(P1 & temp))
- {
- return (i+j*4);
- }
- temp <<= 1;
- }
- }
- }
- //主函數(shù)
- void Main(void)
- {
- uchar Key_Value; //定義鍵值
- while(1)
- {
- P1 = 0xf0;
- if(P1 != 0xf0)
- {
- Delay_1ms(10); //按鍵消抖
- if(P1 != 0xf0)
- {
- Key_Value = Key_scan();
- }
- }
- P2 = table[Key_Value];
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
【可用】不錯(cuò)的矩陣鍵盤(pán)例子.rar
(149.28 KB, 下載次數(shù): 7)
2018-7-11 15:36 上傳
點(diǎn)擊文件名下載附件
|
|