本程序所用的原理图下载:点这里,单片机芯片运用的stc89c52;找到相应部分即可.这是一整个单片机开发板的电路图其他的疏忽.
hex文件及其工程文件下载:http://www.51hei.com/f/juzhen.rar 以下是经过测验的源代码:
/*
*功用:运用矩阵按键使得按键按下时数码管上显现各自对应的数字(0 ~ F);
*日期:2013-05-03-17:51;
*作者:徐冉
*特别阐明:本程序代码现已经过调试,仅供学习运用;
*
*/
/***********AT89C52-RC 单片机51hei 试验板***********/
/*****************51hei-开发板*********************/
#include
typedef unsigned int uint;
typedef unsigned char uchar;
sbit wela = P2^7;
sbit dula = P2^6;
sbit FM = P2^3;
uchar code table[] = {
0x3F, //”0″
0x06, //”1″
0x5B, //”2″
0x4F, //”3″
0x66, //”4″
0x6D, //”5″
0x7D, //”6″
0x07, //”7″
0x7F, //”8″
0x6F, //”9″
0x77, //”A”
0x7C, //”B”
0x39, //”C”
0x5E, //”D”
0x79, //”E”
0x71, //”F”
0x76, //”H”
0x38, //”L”
0x37, //”n”
0x3E, //”u”
0x73, //”P”
0x5C, //”o”
0x40, //”-“
0x00, //平息
0x00 //自定义
};
uchar key, temp;
void display(uchar num);
void Marix_keyscan();
void delay(uint xms);
void main()
{
dula = 1;
P0 = 0x00;
dula = 0;
wela = 1;
P0 = 0xea;
wela = 0;
while(1)
{
Marix_keyscan();
display(key);
}
}
void display(uchar num)
{
dula = 1;
P0 = table[num];
dula = 0;
}
void delay(uint xms)
{
uint i, j;
for(i = xms; i > 0; i–)
for(j = 125; j > 0; j–);
}
void Marix_keyscan()
{
P3 = 0xfe;
temp = P3;
temp &= 0xf0;
if(temp != 0xf0)
{
delay(5);
temp = P3;
temp &= 0xf0;
if(temp != 0xf0)
{
FM = 0;
temp = P3;
switch(temp)
{
case 0xee: key = 0;
break;
case 0xde: key = 1;
break;
case 0xbe: key = 2;
break;
case 0x7e: key = 3;
break;
default:
break;
}
while(temp != 0xf0)
{
temp = P3;
temp &= 0xf0;
}
delay(5);
while(temp != 0xf0)
{
temp = P3;
temp &= 0xf0;
}
FM = 1;
}
}
P3 = 0xfd;
temp = P3;
temp &= 0xf0;
if(temp != 0xf0)
{
delay(5);
temp = P3;
temp &= 0xf0;
if(temp != 0xf0)
{
FM = 0;
temp = P3;
switch(temp)
{
case 0xed:key = 4;
break;
case 0xdd:key = 5;
break;
case 0xbd:key = 6;
break;
case 0x7d:key = 7;
break;
default:
break;
}
while(temp != 0xf0)
{
temp = P3;
temp &= 0xf0;
}
delay(5);
while(temp != 0xf0)
{
temp = P3;
temp &= 0xf0;
}
FM = 1;
}
}
P3 = 0xfb;
temp = P3;
temp &= 0xf0;
if(temp != 0xf0)
{
delay(5);
temp = P3;
temp &= 0xf0;
if(temp != 0xf0)
{
FM = 0;
temp = P3;
switch(temp)
{
case 0xeb: key = 8;
break;
case 0xdb: key = 9;
break;
case 0xbb: key = 10;
break;
case 0x7b: key = 11;
break;
default:
break;
}
while(temp != 0xf0)
{
temp = P3;
temp &= 0xf0;
}
delay(5);
while(temp != 0xf0)
{
temp = P3;
temp &= 0xf0;
}
FM = 1;
}
}
P3 = 0xf7;
temp = P3;
temp &= 0xf0;
if(temp != 0xf0)
{
delay(5);
temp = P3;
temp &= 0xf0;
if(temp != 0xf0)
{
FM = 0;
temp = P3;
switch(temp)
{
case 0xe7: key = 12;
break;
case 0xd7: key = 13;
break;
case 0xb7: key = 14;
break;
case 0x77: key = 15;
break;
default:
break;
}
while(temp != 0xf0)
{
temp = P3;
temp &= 0xf0;
}
delay(5);
while(temp != 0xf0)
{
temp = P3;
temp &= 0xf0;
}
FM = 1;
}
}
}
51单片机矩阵键盘检测源代码(按键数码管显现0-F)
本程序所用的原理图下载:点这里,单片机芯片使用的stc89c52;找到相应部分即可这是一整个单片机开发板的电路图其他的忽略hex文件及其工程
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/zhishi/shuzi/254025.html