打印

矩键和数码管显示的一些问题

[复制链接]
907|5
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
情不醉信仰|  楼主 | 2015-3-12 21:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
自己做用 80c51单片机 开发的一个闹钟  其中一个功能有问题 望各位前辈指点,特别是亲爱的“版主dirtwillfly
”  
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int

uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,
};


//-----中间变量 检测是否有按键------
uchar sum;
//----------------------------------


//----uchar函数变量---------
uchar temp;
//uchar flag;
//--------------------------



//-------存贮数组-----------
uchar number[4];
//---------按下四次------------          

sbit dula=P2^6;
sbit wela=P2^7;

uchar keyscan();     //矩阵键盘检测函数  来源郭天祥视频
void delay();                 //延时函数    用于动态显示
void display(uchar a,uchar b,uchar x,uchar y);  //动态显示

void main()
{
        sum=keyscan();
        while(sum==0)
        {
                sum=keyscan();
        }
        number[0]=sum-1;


        sum=keyscan();
        while(sum==0)
        {
                sum=keyscan();                 
        }
        number[1]=sum-1;


        sum=keyscan();
        while(sum==0)
        {
                sum=keyscan();
        }
        number[2]=sum-1;


        sum=keyscan();
        while(sum==0)
        {
                sum=keyscan();
        }
        number[3]=sum-1;

       
        display(number[0],number[1],number[2],number[3]);

}


问题在于 main函数里面的 四次  调取 keyscan()  我本意是想  按四次矩键  然后先存到数组里面  然后利用动态显示 在数码管上面显示出闹钟时间(时间格式为xx:xx)
烧录进去以后  有时候按四次  有时候按了两次就显示了 有重复的。。。。   (keyscan函数没有按键时返回值为0)   

相关帖子

沙发
情不醉信仰|  楼主 | 2015-3-12 21:34 | 只看该作者
uchar keyscan()                  
{
        uchar flag;
        flag=0;

        P3=0xfe;
        temp=P3;                    
        temp=temp&0xf0;
        if(temp!=0xf0)
        {
                temp=P3;
                temp=temp&0xf0;
                if(temp!=0xf0)
                {
                        temp=P3;
                        switch(temp)
                        {
                        case 0xee:{flag=1;break;}
                        case 0xde:{flag=2;break;}
                        case 0xbe:{flag=3;break;}
                        case 0x7e:{flag=4;break;}
                        }
                        //------检测按键松开两次
                        while(temp!=0xf0)
                        {
                                temp=P3;
                                temp=temp&0xf0;
                        }
                        while(temp!=0xf0)
                        {
                                temp=P3;
                                temp=temp&0xf0;
                        }
                        return flag;  
                }
        }

        P3=0xfd;
        temp=P3;
        temp=temp&0xf0;
        if(temp!=0xf0)
        {
                temp=P3;
                temp=temp&0xf0;
                if(temp!=0xf0)   
                {
                        temp=P3;
                        switch(temp)
                        {
                        case 0xed:{flag=5;break;}
                        case 0xdd:{flag=6;break;}
                        case 0xbd:{flag=7;break;}
                        case 0x7d:{flag=8;break;}
                        }
                        while(temp!=0xf0)
                        {
                                temp=P3;
                                temp=temp&0xf0;
                        }
                        while(temp!=0xf0)
                        {
                                temp=P3;
                                temp=temp&0xf0;
                        }
                        return flag;
                }
        }

       
        P3=0xfb;
        temp=P3;
        temp=temp&0xf0;
        if(temp!=0xf0)
        {
                temp=P3;
                temp=temp&0xf0;
                if(temp!=0xf0)    //确认非外界因素 导致键盘按下
                {
                        temp=P3;
                        switch(temp)
                        {
                        case 0xeb:{flag=9;break;}
                        case 0xdb:{flag=10;break;}
                        }
                        while(temp!=0xf0)
                        {
                                temp=P3;
                                temp=temp&0xf0;
                        }
                        while(temp!=0xf0)
                        {
                                temp=P3;
                                temp=temp&0xf0;
                        }
                        return flag;
                }
        }
        return 0;
}

使用特权

评论回复
板凳
dirtwillfly| | 2015-3-12 21:35 | 只看该作者
按键是不是没消抖?

使用特权

评论回复
地板
dirtwillfly| | 2015-3-12 21:46 | 只看该作者
觉得还是矩阵检测的问题。不知道楼主的晶振频率和使用的郭天祥的按键扫描函数对应的硬件是否一样?

使用特权

评论回复
5
情不醉信仰|  楼主 | 2015-3-13 22:43 | 只看该作者
  蛋疼的不行。  莫非要先把这东西 晒段时间不鸟 然后在去重新整理么

使用特权

评论回复
6
sunli2015| | 2015-4-20 15:31 | 只看该作者
肿么没看到狗在哪儿喂呢? 51不需要喂么?

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

5

主题

40

帖子

0

粉丝