单片机检测矩阵键盘.c文件
这是电路图
仿真文件和完整源码下载:http://www.51hei.com/bbs/dpj-22586-1.html
下面是矩阵键盘.c文件:
#include
#include "delay_ms.h"//利用函数delay_ms(unsigned int x)延时 x ms
#include "矩阵键盘.h" //头文件中宏定义#define JPJK P3
void baoj1();
unsigned char keyscan()
{
unsigned char temp,key;
key = 0xff;
JPJK = 0xfe; //将第一行线置低电平
temp = JPJK;//读JPJK的当前状态到 temp
temp &= 0xf0;// temp = temp & 0xf0 按位与
if(temp != 0xf0)
{
delay_ms(10);//延时去抖
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的当前状态到 temp
temp &= 0xf0;// temp = temp & 0xf0
if(temp != 0xf0)
{
delay_ms(10);//延时去抖
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的当前状态到 temp
temp &= 0xf0;// temp = temp & 0xf0
if(temp != 0xf0)
{
delay_ms(10);//延时去抖
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的当前状态到 temp
temp &= 0xf0;// temp = temp & 0xf0
if(temp != 0xf0)
{
delay_ms(10);//延时去抖
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; //返回按下的键
}
单片机矩阵键盘c文 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)