51单片机矩阵键盘的一些问题
下面是我写的程序#include<reg52.h>#defineucharunsignedchar#defineuintunsignedintucharcodetabb[...
下面是我写的程序
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code tabb[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x40};
uchar code taba[]={0xfd,0xfb,0xf7,0xe0,0xd0,0xb0,0x70};
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
uchar i=0,j,temp;
P2=0; //P2口是选择数码管全打开
P1=0XFF; //P1口连着4列3行的矩阵键盘,P1.0没有接键盘
while(1)
{
P1=taba[i];
temp=P1;
temp&=0xf0;
if(temp!=0xf0)
{
delay(1);
temp=P1;
temp&=0XF0;
if(temp!=0xf0)
{
for(j=3;j<7;j++)
{
if(temp==taba[j])
P0=tabb[(j-3+(i<<2))];
}
}
}
i++;
i&=0x03;
}
}
P0口接数码管
不知道为何,我上电后数码管就显示字母C,请高手指点下 展开
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code tabb[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x40};
uchar code taba[]={0xfd,0xfb,0xf7,0xe0,0xd0,0xb0,0x70};
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void main()
{
uchar i=0,j,temp;
P2=0; //P2口是选择数码管全打开
P1=0XFF; //P1口连着4列3行的矩阵键盘,P1.0没有接键盘
while(1)
{
P1=taba[i];
temp=P1;
temp&=0xf0;
if(temp!=0xf0)
{
delay(1);
temp=P1;
temp&=0XF0;
if(temp!=0xf0)
{
for(j=3;j<7;j++)
{
if(temp==taba[j])
P0=tabb[(j-3+(i<<2))];
}
}
}
i++;
i&=0x03;
}
}
P0口接数码管
不知道为何,我上电后数码管就显示字母C,请高手指点下 展开
4个回答
意法半导体(中国)投资有限公司
2020-01-15 广告
2020-01-15 广告
单片机(Microcontrollers)是一种集成电路芯片,是采用超大规模集成电路技术把具有数据处理能力的中央处理器CPU、随机存储器RAM、只读存储器ROM、多种I/O口和中断系统、定时器/计数器等功能(可能还包括显示驱动电路、脉宽调制...
点击进入详情页
本回答由意法半导体(中国)投资有限公司提供
展开全部
程序看着有点乱,没有电路图吗?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
电路图呢??
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的思路有点不懂,看看我的吧:
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit p25=P2^5;
sbit p37=P3^7;
uchar num,nn,hang;
uchar tabledu[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
display(uchar);
void delay(uchar x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=10;b>0;b--);
}
void main()
{
while(1)
{
P1=0xf7;
hang=P1;
hang=hang&0xf0;
if(hang!=0xf0)
{
delay(50);
if(hang!=0xf0)
{
switch(hang)
{
case 0xe0:num=0;
break;
case 0xd0:num=1;
break;
case 0xb0:num=2;
break;
case 0x70:num=3;
break;
}
while(hang!=0xf0)
{
hang=P1;
hang=hang&0xf0;
}
}
}
P1=0xfb;
hang=P1;
hang=hang&0xf0;
if(hang!=0xf0)
{
delay(50);
if(hang!=0xf0)
{
switch(hang)
{
case 0xe0:num=4;
break;
case 0xd0:num=5;
break;
case 0xb0:num=6;
break;
case 0x70:num=7;
break;
}
while(hang!=0xf0)
{
hang=P1;
hang=hang&0xf0;
}
}
}
P1=0xfd;
hang=P1;
hang=hang&0xf0;
if(hang!=0xf0)
{
delay(50);
if(hang!=0xf0)
{
switch(hang)
{
case 0xe0:num=8;
break;
case 0xd0:num=9;
break;
case 0xb0:num=10;
break;
case 0x70:num=11;
break;
}
while(hang!=0xf0)
{
hang=P1;
hang=hang&0xf0;
}
}
}
P1=0xfe;
hang=P1;
hang=hang&0xf0;
if(hang!=0xf0)
{
delay(50);
if(hang!=0xf0)
{
switch(hang)
{
case 0xe0:num=12;
break;
case 0xd0:num=13;
break;
case 0xb0:num=14;
break;
case 0x70:num=15;
break;
}
while(hang!=0xf0)
{
hang=P1;
hang=hang&0xf0;
}
}
}
display(num);
}
}
display(uchar i)
{
p25=0;
p37=0;
P2=0xfe;
P0=tabledu[i];
delay(100);
}
#include <reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit p25=P2^5;
sbit p37=P3^7;
uchar num,nn,hang;
uchar tabledu[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
display(uchar);
void delay(uchar x)
{
uint a,b;
for(a=x;a>0;a--)
for(b=10;b>0;b--);
}
void main()
{
while(1)
{
P1=0xf7;
hang=P1;
hang=hang&0xf0;
if(hang!=0xf0)
{
delay(50);
if(hang!=0xf0)
{
switch(hang)
{
case 0xe0:num=0;
break;
case 0xd0:num=1;
break;
case 0xb0:num=2;
break;
case 0x70:num=3;
break;
}
while(hang!=0xf0)
{
hang=P1;
hang=hang&0xf0;
}
}
}
P1=0xfb;
hang=P1;
hang=hang&0xf0;
if(hang!=0xf0)
{
delay(50);
if(hang!=0xf0)
{
switch(hang)
{
case 0xe0:num=4;
break;
case 0xd0:num=5;
break;
case 0xb0:num=6;
break;
case 0x70:num=7;
break;
}
while(hang!=0xf0)
{
hang=P1;
hang=hang&0xf0;
}
}
}
P1=0xfd;
hang=P1;
hang=hang&0xf0;
if(hang!=0xf0)
{
delay(50);
if(hang!=0xf0)
{
switch(hang)
{
case 0xe0:num=8;
break;
case 0xd0:num=9;
break;
case 0xb0:num=10;
break;
case 0x70:num=11;
break;
}
while(hang!=0xf0)
{
hang=P1;
hang=hang&0xf0;
}
}
}
P1=0xfe;
hang=P1;
hang=hang&0xf0;
if(hang!=0xf0)
{
delay(50);
if(hang!=0xf0)
{
switch(hang)
{
case 0xe0:num=12;
break;
case 0xd0:num=13;
break;
case 0xb0:num=14;
break;
case 0x70:num=15;
break;
}
while(hang!=0xf0)
{
hang=P1;
hang=hang&0xf0;
}
}
}
display(num);
}
}
display(uchar i)
{
p25=0;
p37=0;
P2=0xfe;
P0=tabledu[i];
delay(100);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询