矩阵键盘问题高分望解决
程序如下:#include<reg52.h>#defineuintunsignedint#defineucharunsignedchar#definep0P0#defin...
程序如下:
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
#define p0 P0
#define p3 P3
sbit duanx=P2^6;
sbit weix=P2^7;
uchar key,keing,view;
uchar show[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0xfd};
void delay(uint t)
{
while(--t);
}
void keyscan(void)
{
p3=0xf0;
delay(20);
keing=p3;
keing=keing&0xf0;
if(keing==0x70) key=0;
else if(keing==0xb0) key=1;
else if(keing==0xd0) key=2;
else if(keing==0xe0) key=3;
else key=16;
p3=0x0f;
delay(20);
keing=p3;
keing=keing&0x0f;
if(keing==0x07) key=key+12;
else if(keing==0x0b) key=key+8;
else if(keing==0x0d) key=key+4;
else if(keing==0x0e) key=key+0;
else key=16;
view=show[key];
}
void display(uchar view)
{
p0=view;
duanx=1;
duanx=0;
p0=0xfe;
weix=1;
weix=0;
delay(2000);
}
main()
{
while(1)
{
p0=0xff;
p3=0xff;
display(show[16]);
delay(200);
p3=0x0f;
if(p3!=0x0f)
{
keyscan();
display(view);
}
}
}
原理图如下:
程序一开始一直是显示数字6,我的想法是通过矩阵键盘输入,并显示在一位数码管上。。。大家帮忙看看,指出真正的问题所在,问题解决了追加积分。 展开
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
#define p0 P0
#define p3 P3
sbit duanx=P2^6;
sbit weix=P2^7;
uchar key,keing,view;
uchar show[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0xfd};
void delay(uint t)
{
while(--t);
}
void keyscan(void)
{
p3=0xf0;
delay(20);
keing=p3;
keing=keing&0xf0;
if(keing==0x70) key=0;
else if(keing==0xb0) key=1;
else if(keing==0xd0) key=2;
else if(keing==0xe0) key=3;
else key=16;
p3=0x0f;
delay(20);
keing=p3;
keing=keing&0x0f;
if(keing==0x07) key=key+12;
else if(keing==0x0b) key=key+8;
else if(keing==0x0d) key=key+4;
else if(keing==0x0e) key=key+0;
else key=16;
view=show[key];
}
void display(uchar view)
{
p0=view;
duanx=1;
duanx=0;
p0=0xfe;
weix=1;
weix=0;
delay(2000);
}
main()
{
while(1)
{
p0=0xff;
p3=0xff;
display(show[16]);
delay(200);
p3=0x0f;
if(p3!=0x0f)
{
keyscan();
display(view);
}
}
}
原理图如下:
程序一开始一直是显示数字6,我的想法是通过矩阵键盘输入,并显示在一位数码管上。。。大家帮忙看看,指出真正的问题所在,问题解决了追加积分。 展开
1个回答
展开全部
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit duanx = P2^6;
sbit weix = P2^7;
uchar key, k_tmp, view;
uchar show[] = {
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x40};
void keyscan(void)
{
key = 16;
P3 = 0xf0; k_tmp = P3 & 0xf0;
if (k_tmp == 0x70) key = 0;
else if(k_tmp == 0xb0) key = 1;
else if(k_tmp == 0xd0) key = 2;
else if(k_tmp == 0xe0) key = 3;
P3 = 0x0f; k_tmp = P3 & 0x0f;
if (k_tmp == 0x07) key = key + 12;
else if(k_tmp == 0x0b) key = key + 8;
else if(k_tmp == 0x0d) key = key + 4;
else if(k_tmp == 0x0e) key = key + 0;
view = show[key];
}
void display(uchar view)
{
P0 = view; duanx = 1; duanx = 0;
P0 = 0xfe; weix = 1; weix = 0;
}
main()
{
while(1) {
keyscan();
display(view);
}
}
#define uint unsigned int
#define uchar unsigned char
sbit duanx = P2^6;
sbit weix = P2^7;
uchar key, k_tmp, view;
uchar show[] = {
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x40};
void keyscan(void)
{
key = 16;
P3 = 0xf0; k_tmp = P3 & 0xf0;
if (k_tmp == 0x70) key = 0;
else if(k_tmp == 0xb0) key = 1;
else if(k_tmp == 0xd0) key = 2;
else if(k_tmp == 0xe0) key = 3;
P3 = 0x0f; k_tmp = P3 & 0x0f;
if (k_tmp == 0x07) key = key + 12;
else if(k_tmp == 0x0b) key = key + 8;
else if(k_tmp == 0x0d) key = key + 4;
else if(k_tmp == 0x0e) key = key + 0;
view = show[key];
}
void display(uchar view)
{
P0 = view; duanx = 1; duanx = 0;
P0 = 0xfe; weix = 1; weix = 0;
}
main()
{
while(1) {
keyscan();
display(view);
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询