大神帮我看下我这个C51单片机4*4矩阵键盘扫描,在keil变量窗口查看键入值。
答案:4 悬赏:20 手机版
解决时间 2021-02-15 10:08
- 提问者网友:書生途
- 2021-02-14 16:19
#include#includevoid delay(unsigned long i ) { unsigned int a; unsigned int b; for(a=i;a>0;a--) for(b=255;b>0;b--);} unsigned char Key_scan(void){ char m,i,k; while(P1!=0xf0) { k=0xfe; for(i=0;i<4;i++){ P1=k; delay(1000); m=P1&0xf0; P0=k&0x0f; switch(m) { case 0xe0:return i; case 0xd0:return i+4; case 0xb0:return i+8; case 0x70:return i+12; default:break; } k=_crol_(k,1); //P1=_crol_(P1,1); } } }void main(){ while(1) { P2=Key_scan(); }}
最佳答案
- 五星知识达人网友:持酒劝斜阳
- 2021-02-14 17:32
uchar scan() //扫描键值的子程序
{
P1=0xf0;
scan0=P1;
delay1ms(20);
if(scan0!=0xf0) //判键是否按下
{
scan0=P1;
if(scan0!=0xf0) //二次判键是否按下
{
P1=0x0f; //线反转法的核心
delay1ms(20);
scan1=P1;
keycode=scan0|scan1; //组合成键编码
for(m=0;m<16;m++)
{
if(keycode==x[m]) //查表得键值
{
key=m;
}
}
}
}
return(key);
}
给你一个可以用的
{
P1=0xf0;
scan0=P1;
delay1ms(20);
if(scan0!=0xf0) //判键是否按下
{
scan0=P1;
if(scan0!=0xf0) //二次判键是否按下
{
P1=0x0f; //线反转法的核心
delay1ms(20);
scan1=P1;
keycode=scan0|scan1; //组合成键编码
for(m=0;m<16;m++)
{
if(keycode==x[m]) //查表得键值
{
key=m;
}
}
}
}
return(key);
}
给你一个可以用的
全部回答
- 1楼网友:一叶十三刺
- 2021-02-14 19:33
uchar keyscan()
{
P3=0xfe;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xee:num=1;
break;
case 0xde:num=2;
break;
case 0xbe:num=3;
break;
case 0x7e:num=4;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfd;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xed:num=5;
break;
case 0xdd:num=6;
break;
case 0xbd:num=7;
break;
case 0x7d:num=8;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xfb;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xeb:num=9;
break;
case 0xdb:num=10;
break;
case 0xbb:num=11;
break;
case 0x7b:num=12;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
P3=0xf7;
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
delay(5);
temp=P3;
temp=temp&0xf0;
while(temp!=0xf0)
{
temp=P3;
switch(temp)
{
case 0xe7:num=13;
break;
case 0xd7:num=14;
break;
case 0xb7:num=15;
break;
case 0x77:num=16;
break;
}
while(temp!=0xf0)
{
temp=P3;
temp=temp&0xf0;
}
}
}
return num;
}
- 2楼网友:过活
- 2021-02-14 18:25
#include<reg52.h>
#include <intrins.h>
void delay(unsigned long i )
{
unsigned int a, b;
for(a = i; a > 0; a--) for(b = 255; b > 0; b--);
}
unsigned char Key_scan(void)
{
unsigned char m, i, k;
P1 = 0xf0;
if (P1 != 0xf0) {
delay(10);
if (P1 != 0xf0) {
k = 0xfe;
for(i = 0; i < 4; i++) {
P1 = k;
m = P1 & 0xf0;
switch(m) {
case 0xe0: return i + 0;
case 0xd0: return i + 4;
case 0xb0: return i + 8;
case 0x70: return i + 12;
}
k = _crol_(k, 1);
}
}
}
return 255;
}
void main()
{
while(1) {
P2 = Key_scan();
}
}
- 3楼网友:纵马山川剑自提
- 2021-02-14 18:13
if (P1 ;
case 0xb0;
m = P1 & 0xf0;
#include
P1 = 0xf0, b;
for(a = i; a >, i, k#include 4; i++) {
P1 = k: return i + 8;
case 0x70: return i + 12;
}
k = _crol_(k, 1);
}
}
}
return 255;
}
void main()
{
while(1) {
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯