打印

【萌新求助】我这个stm32矩阵4x4显示数字,按键没反应

[复制链接]
1271|4
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
ruoxin1|  楼主 | 2018-2-28 17:14 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
求看看这个程序问题出在哪了,能二位一体动态数码管能显示,但是按矩阵键盘并不会显示我要的数字。

1.jpg (344.77 KB )

1.jpg

2.jpg (362.27 KB )

2.jpg

3.jpg (377.04 KB )

3.jpg

4.jpg (345.63 KB )

4.jpg

相关帖子

沙发
ruoxin1|  楼主 | 2018-2-28 17:29 | 只看该作者
#include "stm32f10x.h" 
#include"sys.h"
u8 KeyValue=0;
void Delay_Ms( u16 time );
u8 anjian(void);
u8 table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};  //Õý³£¹²Ñô¼«´úÂë
void GPIO_Configuration(void);

int main()
{  
  
    GPIO_Configuration();  
   
    while(1)
                {
                anjian();
                GPIO_ResetBits (GPIOC, GPIO_Pin_0);
                GPIOA->ODR=table[KeyValue%10];  
                Delay_Ms(5);
                GPIO_SetBits(GPIOC, GPIO_Pin_0);
                GPIO_ResetBits (GPIOC, GPIO_Pin_1);
                GPIOA->ODR=table[KeyValue/10];  
                Delay_Ms(5);
                GPIO_SetBits(GPIOC, GPIO_Pin_1);
                }
}

void GPIO_Configuration(void)    //GPIO¿ÚÅäÖÃ
{   
  GPIO_InitTypeDef GPIO_InitStructure;
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
  //LED
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOC, &GPIO_InitStructure);  
       
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
        GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
        GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
        GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
        GPIO_Init(GPIOA,&GPIO_InitStructure);
       
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
        GPIO_Init(GPIOB, &GPIO_InitStructure);
        GPIO_SetBits(GPIOB, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3);
        GPIO_ResetBits(GPIOB, GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7);
  
}



void delay_ms(u16 time)       //ÑÓʱº¯Êý½èÓñðÈ˵ĸÄÌì×ÐϸÀí½â´ó¸Å1000Ϊ1s
{      
  u16 i=0;      
  while(time--)      
  {      
    i=12000;      
    while(i--);      
  }      
}

u8 anjian(void)
{
       
        if((GPIO_ReadInputData(GPIOB)&0xff)!=0x0f)
        {
                Delay_Ms(10);
                if((GPIO_ReadInputData(GPIOB)&0xff)!=0x0f)
                {
                        GPIO_SetBits(GPIOB, GPIO_Pin_0);
                        GPIO_ResetBits(GPIOB, GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3);
                        switch(GPIO_ReadInputData(GPIOB)&0xff)
                        {
                        case 0x11: KeyValue = 1; break;
                        case 0x21: KeyValue = 5; break;
                        case 0x41: KeyValue = 9; break;
                        case 0x81: KeyValue = 13;break;
                        }
                        GPIO_SetBits(GPIOB, GPIO_Pin_1);
                        GPIO_ResetBits(GPIOB, GPIO_Pin_0 | GPIO_Pin_2 | GPIO_Pin_3);
                        switch(GPIO_ReadInputData(GPIOB)&0xff)
                        {
                        case 0x12: KeyValue = 2; break;
                        case 0x22: KeyValue = 6; break;
                        case 0x42: KeyValue = 10;break;
                        case 0x82: KeyValue = 14;break;
                        }
                        GPIO_SetBits(GPIOB, GPIO_Pin_2);
                        GPIO_ResetBits(GPIOB, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_3);
                        switch(GPIO_ReadInputData(GPIOB)&0xff)
                        {
                        case 0x14: KeyValue = 3; break;
                        case 0x24: KeyValue = 7; break;
                        case 0x44: KeyValue = 11;break;
                        case 0x84: KeyValue = 15;break;
                        }
                        GPIO_SetBits(GPIOB, GPIO_Pin_3);
                        GPIO_ResetBits(GPIOB, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2);
                        switch(GPIO_ReadInputData(GPIOB)&0xff)
                        {
                        case 0x18: KeyValue = 4; break;
                        case 0x28: KeyValue = 8; break;
                        case 0x48: KeyValue = 12;break;
                        case 0x88: KeyValue = 16;break;
                        }
                        GPIO_SetBits(GPIOB, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3);
                        GPIO_ResetBits(GPIOB, GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 |GPIO_Pin_7);
                        while((GPIO_ReadInputData(GPIOB)&0xff)!=0x0f)
                        {
                        GPIO_ResetBits (GPIOC, GPIO_Pin_0);
                GPIOA->ODR=table[KeyValue%10];  
                Delay_Ms(5);
                GPIO_SetBits(GPIOC, GPIO_Pin_0);
                GPIO_ResetBits (GPIOC, GPIO_Pin_1);
                GPIOA->ODR=table[KeyValue/10];  
                Delay_Ms(5);
                GPIO_SetBits(GPIOC, GPIO_Pin_1);
                        };
                        return KeyValue;
                }
        }
        return 0;
}

        void Delay_Ms( u16 time )
{
                u16 i,j;
                for( i = 0; i < time; i++ )
                                for( j = 10000; j > 0; j-- );
}

使用特权

评论回复
板凳
caijie001| | 2018-3-2 00:15 | 只看该作者
单步调试试试,按着一个按键,看看哪个函数没有进入

使用特权

评论回复
地板
zhaoyu2005| | 2018-3-2 08:44 | 只看该作者
没电路图,让人家根据你的程序反推电路?

使用特权

评论回复
5
dirtwillfly| | 2018-3-2 16:12 | 只看该作者
那么长的代码,很少有人会读的。
建议楼主逐步调试代码看看,还有就是按键和显示分别调试,调试没问题了再进行整合

使用特权

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

本版积分规则

1

主题

2

帖子

0

粉丝