新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 單片機(jī)檢測(cè)矩陣鍵盤.c文件

單片機(jī)檢測(cè)矩陣鍵盤.c文件

作者: 時(shí)間:2016-11-30 來(lái)源:網(wǎng)絡(luò) 收藏

這是電路圖

本文引用地址:http://m.butianyuan.cn/article/201611/323855.htm

仿真文件和完整源碼下載:http://www.51hei.com/bbs/dpj-22586-1.html

下面是矩陣鍵盤.c文件
#include
#include "delay_ms.h"http://利用函數(shù)delay_ms(unsigned int x)延時(shí) x ms
#include "矩陣鍵盤.h" //頭文件中宏定義#define JPJK P3
void baoj1();
unsigned char keyscan()
{
unsigned char temp,key;
key = 0xff;
JPJK = 0xfe; //將第一行線置低電平
temp = JPJK;//讀JPJK的當(dāng)前狀態(tài)到 temp
temp &= 0xf0;// temp = temp & 0xf0 按位與
if(temp != 0xf0)
{
delay_ms(10);//延時(shí)去抖
temp = JPJK;
temp &= 0xf0;
if(temp != 0xf0)//第一行有鍵被按下
{
temp = JPJK;//讀被按下的鍵
baoj1();
switch(temp)
{
case 0xee: key = 1;break;
case 0xde: key = 2;break;
case 0xbe: key = 3;break;
case 0x7e: key = 0x0a;break;
}
while(temp != 0xf0)//等待按鍵釋放
{
temp = JPJK;
temp &= 0xf0;
}
}
}
JPJK = 0xfd; //將第二行線置低電平
temp = JPJK;//讀JPJK的當(dāng)前狀態(tài)到 temp
temp &= 0xf0;// temp = temp & 0xf0
if(temp != 0xf0)
{
delay_ms(10);//延時(shí)去抖
temp = JPJK;
temp &= 0xf0;
if(temp != 0xf0)//第二行有鍵被按下
{
temp = JPJK;//讀被按下的鍵
baoj1();
switch(temp)
{
case 0xed: key = 4;break;
case 0xdd: key = 5;break;
case 0xbd: key = 6;break;
case 0x7d: key = 0x0b;break;
}
while(temp != 0xf0)//等待按鍵釋放
{
temp = JPJK;
temp &= 0xf0;
}
}
}
JPJK = 0xfb; //將第 三行線置低電平
temp = JPJK;//讀JPJK的當(dāng)前狀態(tài)到 temp
temp &= 0xf0;// temp = temp & 0xf0
if(temp != 0xf0)
{
delay_ms(10);//延時(shí)去抖
temp = JPJK;
temp &= 0xf0;
if(temp != 0xf0)//第三行有鍵被按下
{
temp = JPJK;//讀被按下的鍵
baoj1();
switch(temp)
{
case 0xeb: key = 7;break;
case 0xdb: key = 8;break;
case 0xbb: key = 9;break;
case 0x7b: key = 0x0c;break;
}
while(temp != 0xf0)//等待按鍵釋放
{
temp = JPJK;
temp &= 0xf0;
}
}
}
JPJK = 0xf7; //將第四行線置低電平
temp = JPJK;//讀JPJK的當(dāng)前狀態(tài)到 temp
temp &= 0xf0;// temp = temp & 0xf0
if(temp != 0xf0)
{
delay_ms(10);//延時(shí)去抖
temp = JPJK;
temp &= 0xf0;
if(temp != 0xf0)//第四行有鍵被按下
{
temp = JPJK;//讀被按下的鍵
baoj1();
switch(temp)
{
case 0xe7: key = 0;break;
case 0xd7: key = 0;break;
case 0xb7: key = 0x0f;break;
case 0x77: key = 0x0d;break;
}
while(temp != 0xf0)//等待按鍵釋放
{
temp = JPJK;
temp &= 0xf0;
}
}
}
return key; //返回按下的鍵
}



關(guān)鍵詞: 單片機(jī)矩陣鍵盤c文

評(píng)論


技術(shù)專區(qū)

關(guān)閉