新人求助 求大神教教我~~~
时间:10-02
整理:3721RD
点击:
51单片机键盘扫描的问题
程序在下面,用keilc调试过 可以实现键盘扫描 但是把程序烧到板子上按键 任何键按下之后都会显示九 个别键按下后还会有9 4 8三个数轮流显示 最终只显示数字9 求大神看一下程序哪里有问题 ps~~刚刚申请的号 只有一个积分 大神不要走~~~
#include<reg51.h>
#include<intrins.h>
#include<math.h>
void delay1ms(unsigned int q) large;
unsigned char saomiaoh() large;
unsigned char saomiaol() large;
unsigned char kk;
#define led P0
#define kb P3
sbit P26=P2^6;
sbit P27=P2^7;
unsigned char code show[16]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
unsigned char data i=0,j=0;
unsigned char data n=0xe0,m=0x0e;
void main()
{
void delay1ms(unsigned int q) large;
unsigned char saomiaol() large;
unsigned char saomiaoh() large;
P26=0;
补充内容 (2016-12-13 17:42):
P27=1;
led=0xfe;
P27=0;
P26=1;
while(1)
{
i=saomiaoh();
j=saomiaol();
led=show[i*4+j];
delay1ms(500000);
kb=0xff;
}
}
void delay1ms(unsigned int q) large
{
while(--q);
}
unsigned char saomiaol() large
{void delay1ms(unsigned int q) large;
kk=kb;
kb=kb&0xf0;
delay1ms(500000);
for(j=0;j<=3;j++)
{
if(n==kb)
{
break;
}
else
n=n|0x0f;
n=_crol_(n,1);
n=n&0xf0;
}
kb=kk;
return j;
}
unsigned char saomiaoh() large
{
void delay1ms(unsigned int q) large;
kk=kb;
kb=kb&0x0f;
delay1ms(500000);
for(i=0;i<=3;i++)
{
if(m==kb)
{
break;
}
else
m=m|0xf0;
m=_crol_(m,1);
m=m&0x0f;
}
kb=kk;
return i;
}
补充内容 (2016-12-13 17:42):
P27=1;
led=0xfe;
P27=0;
P26=1;
while(1)
{
i=saomiaoh();
j=saomiaol();
led=show[i*4+j];
delay1ms(500000);
kb=0xff;
}
}
void delay1ms(unsigned int q) large
{
while(--q);
}
unsigned char saomiaol() large
{void delay1ms(unsigned int q) large;
kk=kb;
kb=kb&0xf0;
delay1ms(500000);
for(j=0;j<=3;j++)
{
if(n==kb)
{
break;
}
else
n=n|0x0f;
n=_crol_(n,1);
n=n&0xf0;
}
kb=kk;
return j;
}
unsigned char saomiaoh() large
{
void delay1ms(unsigned int q) large;
kk=kb;
kb=kb&0x0f;
delay1ms(500000);
for(i=0;i<=3;i++)
{
if(m==kb)
{
break;
}
else
m=m|0xf0;
m=_crol_(m,1);
m=m&0x0f;
}
kb=kk;
return i;
}
程序在下面,用keilc调试过 可以实现键盘扫描 但是把程序烧到板子上按键 任何键按下之后都会显示九 个别键按下后还会有9 4 8三个数轮流显示 最终只显示数字9 求大神看一下程序哪里有问题 ps~~刚刚申请的号 只有一个积分 大神不要走~~~
#include<reg51.h>
#include<intrins.h>
#include<math.h>
void delay1ms(unsigned int q) large;
unsigned char saomiaoh() large;
unsigned char saomiaol() large;
unsigned char kk;
#define led P0
#define kb P3
sbit P26=P2^6;
sbit P27=P2^7;
unsigned char code show[16]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};
unsigned char data i=0,j=0;
unsigned char data n=0xe0,m=0x0e;
void main()
{
void delay1ms(unsigned int q) large;
unsigned char saomiaol() large;
unsigned char saomiaoh() large;
P26=0;
补充内容 (2016-12-13 17:42):
P27=1;
led=0xfe;
P27=0;
P26=1;
while(1)
{
i=saomiaoh();
j=saomiaol();
led=show[i*4+j];
delay1ms(500000);
kb=0xff;
}
}
void delay1ms(unsigned int q) large
{
while(--q);
}
unsigned char saomiaol() large
{void delay1ms(unsigned int q) large;
kk=kb;
kb=kb&0xf0;
delay1ms(500000);
for(j=0;j<=3;j++)
{
if(n==kb)
{
break;
}
else
n=n|0x0f;
n=_crol_(n,1);
n=n&0xf0;
}
kb=kk;
return j;
}
unsigned char saomiaoh() large
{
void delay1ms(unsigned int q) large;
kk=kb;
kb=kb&0x0f;
delay1ms(500000);
for(i=0;i<=3;i++)
{
if(m==kb)
{
break;
}
else
m=m|0xf0;
m=_crol_(m,1);
m=m&0x0f;
}
kb=kk;
return i;
}
补充内容 (2016-12-13 17:42):
P27=1;
led=0xfe;
P27=0;
P26=1;
while(1)
{
i=saomiaoh();
j=saomiaol();
led=show[i*4+j];
delay1ms(500000);
kb=0xff;
}
}
void delay1ms(unsigned int q) large
{
while(--q);
}
unsigned char saomiaol() large
{void delay1ms(unsigned int q) large;
kk=kb;
kb=kb&0xf0;
delay1ms(500000);
for(j=0;j<=3;j++)
{
if(n==kb)
{
break;
}
else
n=n|0x0f;
n=_crol_(n,1);
n=n&0xf0;
}
kb=kk;
return j;
}
unsigned char saomiaoh() large
{
void delay1ms(unsigned int q) large;
kk=kb;
kb=kb&0x0f;
delay1ms(500000);
for(i=0;i<=3;i++)
{
if(m==kb)
{
break;
}
else
m=m|0xf0;
m=_crol_(m,1);
m=m&0x0f;
}
kb=kk;
return i;
}
是你写的程序有问题,还不止一处!
例如这里:
P26=0;
补充内容 (2016-12-13 17:42): //这里是什么鬼?
P27=1; // P26和P27 刚清零和置一
led=0xfe;
P27=0; // 这里就变了,不知何意?
P26=1;
感觉你写的真的有点乱!你先看一下书,梳理一下自己的思路
而且你的delayms50000,感觉会超出量程,可以另外编写一个秒的程序