74HC595扩展矩阵按键,出现检测不到的情况,有经验的赐教

2020-01-18 18:42发布

本帖最后由 haolaishi 于 2013-1-17 17:38 编辑

74HC595扩展矩阵按键,出现检测不到的情况,有经验的赐教

AAA.jpg (390.42 KB, 下载次数: 1) 下载附件 2013-1-17 17:38 上传

//////----代码如下:----//////////////////////////////////////////////////////////////////////////////////////////////////////////
/**************************************
**************************************/
#include "hc595.h"

/**************************************
延时5毫秒(STC12C5A60S2@12M)
不同的工作环境,需要调整此函数
此延时函数是使用1T的指令周期进行计算,与传统的12T的MCU不同
**************************************/
void Delay20ms(void)
{
    unsigned int n = 5000;

    while (n--)
    {
        _nop_();
        _nop_();
        _nop_();
        _nop_();
        _nop_();
    }
}
/*------------------------------------------------
                发送字节程序
------------------------------------------------*/
unsigned char SendByte(unsigned char dat)
{   
  unsigned char i,a;
  a=dat;
//  dat=_crol_(dat,1);     
   for(i=0;i<8;i++)
        {
         SRCLK=0;
         SER=dat&0x80;
         dat<<=1;
         SRCLK=1;
         }
        LATCH=0;
    LATCH=1;
    return a;     
}

/*------------------------------------------------
                按键扫描程序
------------------------------------------------*/

unsigned char keyscan(void)
{
        unsigned char sccode,recode,i;
        SendByte(0x00);
        if((P4&0x70)!=0x70)
        {
                Delay20ms();
                if((P4&0x70)!=0x70)
                {
                        SendByte(0xfe);
                        recode=0xfe;
                        for(i=0;i<5;i++)
                        {
                                if((P4&0x70)!=0x70)
                                {
                                PutChar(64,28,'c');
                                sccode=(P4&0x70)|0x8f;
                                return((~sccode)+(~recode));
                                }

                                else
                                {                            //recode=_cror_(0x7f,1);
//                                 recode=_crol_(recode,1);  //recode=SendByte(_cror_(0x7f,1));
//                                 SendByte(0x7f);
                                 PutChar(30,28,'b');
                                }
                        }
                }
        }
        else
        {
        PutChar(0,28,'A');
        }
        return(0);

}

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
13条回答
lcw_swust
1楼-- · 2020-01-18 19:18
楼主,电路图里的结点打多了吧
haolaishi
2楼-- · 2020-01-18 23:33
现在问题是,不管按哪个按键,都会出现((P4&0x70)!=0x70),三条行线一直能检测到有低电平存在
xivisi
3楼-- · 2020-01-19 02:17
 精彩回答 2  元偷偷看……
haolaishi
4楼-- · 2020-01-19 06:07
经测试,595是工作正常的,不影响595的工作
haolaishi
5楼-- · 2020-01-19 09:39
lcw_swust 发表于 2013-1-17 17:31
楼主,电路图里的结点打多了吧

更新过了,但是PCB是没问题,这个是我刚才翻转不小心弄错的。谢谢了
fulitun
6楼-- · 2020-01-19 13:08
是不是P4设置问题?

一周热门 更多>