标题:
今天学会了写矩阵键盘的程序!
[打印本页]
作者:
hutians
时间:
2015-2-10 17:54
标题:
今天学会了写矩阵键盘的程序!
本帖最后由 hutians 于 2015-2-10 17:59 编辑
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uchar table[]={
0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xc6,0xa1,0x86,0x8e
};
uint num;
uchar temp;
sbit duan=P1^0;
void delay(uint z)
{
uint i,j;
for(i=z;i>0;i--)
for(j=20;j>0;j--);
}
void display()
{
duan=1;
P0=table[num];
duan=0;
delay(50);
}
uchar keyboard(void)
{
{
P2=0xfe;
temp=P2;
temp&=0xf0;
if(temp!=0xf0)
{
delay(50);
temp=P2;
temp&=0xf0;
switch(temp)
{
case 0x70:num=0;break;
case 0xb0:num=1;break;
case 0xd0:num=2;break;
case 0xe0:num=3;break;
}
while(temp!=0xf0)
{
temp=P2;
temp&=0xf0;
}
display();
}
}
{
P2=0xfd;
temp=P2;
temp&=0xf0;
if(temp!=0xf0)
{
delay(50);
temp=P2;
temp&=0xf0;
switch(temp)
{
case 0x70:num=4;break;
case 0xb0:num=5;break;
case 0xd0:num=6;break;
case 0xe0:num=7;break;
}
while(temp!=0xf0)
{
temp=P2;
temp&=0xf0;
}
display();
}
}
{
P2=0xfb;
temp=P2;
temp&=0xf0;
if(temp!=0xf0)
{
delay(50);
temp=P2;
temp&=0xf0;
switch(temp)
{
case 0x70:num=8;break;
case 0xb0:num=9;break;
case 0xd0:num=10;break;
case 0xe0:num=11;break;
}
display();
}
}
{
P2=0xf7;
temp=P2;
temp&=0xf0;
if(temp!=0xf0)
{
delay(50);
temp=P2;
temp&=0xf0;
switch(temp)
{
case 0x70:num=12;break;
case 0xb0:num=13;break;
case 0xd0:num=14;break;
case 0xe0:num=15;break;
}
display();
}
}
}
void main()
{
while(1)
{
keyboard();
}
}
为自己加油!
作者:
安卓开发
时间:
2015-2-10 20:10
寻求1名安卓软件工程师合作伙伴,工资3000元以上,可入股。
要求:1,手机应用基本开发,手机软件更新及升级。
2,可来我方工作者优先
3,上班时间2015年3月
有意者可联系QQ:3144934451
作者:
hmgqljz111
时间:
2019-11-12 14:04
你这个好象不对吧。检测第一行的时候应该是0XFE,然后键值是7E,DE,BE,EE,
作者:
枭奇电子
时间:
2020-2-24 12:45
能不能添加注释
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1