c51经典子程序代码全集
源代码在线查看: 键盘扫描和键值检测.txt
C51编程:斑竹老大帮帮忙呀!!! [chenchenxxx] [55次] 01-6-7 下午 07:58:31
各位朋友你们好,我最近刚刚接触C51语言,并且要用它来编辑一个键盘扫描和键值检测程
序,我觉得很难,因为我刚刚接触这个语言,请各位C51语言的编程高手帮帮我吧,谢谢
了!这个键盘是通过138译码器(A,B,C三端分别接89C52单片机的P1-0,P1-1,P1-2)
和89C52单片机的P1-4,P1-5,P1-6三个端口组成一个3*8距阵的24键的键盘,该怎么实现键
盘扫描程序呀,大家如果方便的话帮帮兄弟我,请联系我chenchenxxx@163.com,
OICQ为41103971,谢谢大家了!
好像你已经贴了两遍,明天编一个给你好啦, [青青子木㊣] [7次] 01-6-7 下午 08:04:13
我作键扫描的方法特笨,明天贴出来后,还得请大虾们出出主意,如何提高效率,今天不编
了我得下班回家。
已经编好了 [青青子木㊣] [50次] 01-6-7 下午 08:47:27
匆匆编完,还没有编译,也许会有点小错误,这基本上是我编矩阵式键盘的方法,不知大虾
有什么建议,或好的方法?拿出来共享共享怎样
#include
#define keyvalue1 1
#define keyvalue2 2
#define keyvalue3 3
#define keyvalue4 4
#define keyvalue5 5
#define keyvalue6 6
#define keyvalue7 7
#define keyvalue8 8
#define keyvalue9 9
#define keyvalue10 10
#define keyvalue11 11
#define keyvalue12 12
#define keyvalue13 13
#define keyvalue14 14
#define keyvalue15 15
#define keyvalue16 16
#define keyvalue17 10
#define keyvalue18 11
#define keyvalue19 19
#define keyvalue20 20
#define keyvalue21 21
#define keyvalue22 22
#define keyvalue23 23
#define keyvalue24 24
SetKeyRow(unsigned char row)
{
if (row P1=(P1&0xf8)|row;
}
//----------------------------------------------------------
unsigned char ReadKeyCol()
{
unsigned char temp;
P1=P1|0x70;
temp=P1&0x70;
if (temp==0x70) return 0xaa;
else return temp;
}
/**/
unsigned char GetKey()
{
unsigned char key;
SetKeyRow(0);
key=ReadKeyCol();
if (key!=0xaa)
{
switch (key)
{
case 3:return keyvalue1;break;
case 5:return keyvalue2;break;
case 6:return keyvalue3;break;
default:break;
}
}
SetKeyRow(1);
key=ReadKeyCol();
if (key!=0xaa)
{
switch (key)
{
case 3:return keyvalue4;break;
case 5:return keyvalue5;break;
case 6:return keyvalue6;break;
default:break;
}
}
SetKeyRow(2);
key=ReadKeyCol();
if (key!=0xaa)
{
switch (key)
{
case 3:return keyvalue7;break;
case 5:return keyvalue8;break;
case 6:return keyvalue9;break;
default:break;
}
}
SetKeyRow(3);
key=ReadKeyCol();
if (key!=0xaa)
{
switch (key)
{
case 3:return keyvalue10;break;
case 5:return keyvalue11;break;
case 6:return keyvalue12;break;
default:break;
}
}
SetKeyRow(4);
key=ReadKeyCol();
if (key!=0xaa)
{
switch (key)
{
case 3:return keyvalue13;break;
case 5:return keyvalue14;break;
case 6:return keyvalue15;break;
default:break;
}
}
SetKeyRow(5);
key=ReadKeyCol();
if (key!=0xaa)
{
switch (key)
{
case 3:return keyvalue16;break;
case 5:return keyvalue17;break;
case 6:return keyvalue18;break;
default:break;
}
}
SetKeyRow(6);
key=ReadKeyCol();
if (key!=0xaa)
{
switch (key)
{
case 3:return keyvalue19;break;
case 5:return keyvalue20;break;
case 6:return keyvalue21;break;
default:break;
}
}
SetKeyRow(7);
key=ReadKeyCol();
if (key!=0xaa)
{
switch (key)
{
case 3:return keyvalue22;break;
case 5:return keyvalue23;break;
case 6:return keyvalue24;break;
default:break;
}
}
rerurn 0xaa;
}
谢谢您了! [chenchenxxx] [4次] 01-6-10 上午 10:29:24
谢谢您了,有机会我们认识一下吧,呵呵!
点击这里回复这篇贴子>>
_____________________________________________________________________________
Copyright?,C51BBS论坛 2000-2001