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

[复制链接]
1695|4
 楼主| ruoxin1 发表于 2018-2-28 17:14 | 显示全部楼层 |阅读模式
求看看这个程序问题出在哪了,能二位一体动态数码管能显示,但是按矩阵键盘并不会显示我要的数字。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
 楼主| ruoxin1 发表于 2018-2-28 17:29 | 显示全部楼层
  1. #include "stm32f10x.h"
  2. #include"sys.h"
  3. u8 KeyValue=0;
  4. void Delay_Ms( u16 time );
  5. u8 anjian(void);
  6. u8 table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};  //Õý³£¹²Ñô¼«´úÂë
  7. void GPIO_Configuration(void);

  8. int main()
  9. {  
  10.   
  11.     GPIO_Configuration();  
  12.    
  13.     while(1)
  14.                 {
  15.                 anjian();
  16.                 GPIO_ResetBits (GPIOC, GPIO_Pin_0);
  17.                 GPIOA->ODR=table[KeyValue%10];  
  18.                 Delay_Ms(5);
  19.                 GPIO_SetBits(GPIOC, GPIO_Pin_0);
  20.                 GPIO_ResetBits (GPIOC, GPIO_Pin_1);
  21.                 GPIOA->ODR=table[KeyValue/10];  
  22.                 Delay_Ms(5);
  23.                 GPIO_SetBits(GPIOC, GPIO_Pin_1);
  24.                 }
  25. }

  26. void GPIO_Configuration(void)    //GPIO¿ÚÅäÖÃ
  27. {   
  28.   GPIO_InitTypeDef GPIO_InitStructure;
  29.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
  30.   //LED
  31.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1;
  32.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  33.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  34.   GPIO_Init(GPIOC, &GPIO_InitStructure);  
  35.        
  36.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE);
  37.         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;
  38.         GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
  39.         GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  40.         GPIO_Init(GPIOA,&GPIO_InitStructure);
  41.        
  42.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
  43.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
  44.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  45.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  46.         GPIO_Init(GPIOB, &GPIO_InitStructure);
  47.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
  48.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  49.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;
  50.         GPIO_Init(GPIOB, &GPIO_InitStructure);
  51.         GPIO_SetBits(GPIOB, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3);
  52.         GPIO_ResetBits(GPIOB, GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7);
  53.   
  54. }



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

  64. u8 anjian(void)
  65. {
  66.        
  67.         if((GPIO_ReadInputData(GPIOB)&0xff)!=0x0f)
  68.         {
  69.                 Delay_Ms(10);
  70.                 if((GPIO_ReadInputData(GPIOB)&0xff)!=0x0f)
  71.                 {
  72.                         GPIO_SetBits(GPIOB, GPIO_Pin_0);
  73.                         GPIO_ResetBits(GPIOB, GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3);
  74.                         switch(GPIO_ReadInputData(GPIOB)&0xff)
  75.                         {
  76.                         case 0x11: KeyValue = 1; break;
  77.                         case 0x21: KeyValue = 5; break;
  78.                         case 0x41: KeyValue = 9; break;
  79.                         case 0x81: KeyValue = 13;break;
  80.                         }
  81.                         GPIO_SetBits(GPIOB, GPIO_Pin_1);
  82.                         GPIO_ResetBits(GPIOB, GPIO_Pin_0 | GPIO_Pin_2 | GPIO_Pin_3);
  83.                         switch(GPIO_ReadInputData(GPIOB)&0xff)
  84.                         {
  85.                         case 0x12: KeyValue = 2; break;
  86.                         case 0x22: KeyValue = 6; break;
  87.                         case 0x42: KeyValue = 10;break;
  88.                         case 0x82: KeyValue = 14;break;
  89.                         }
  90.                         GPIO_SetBits(GPIOB, GPIO_Pin_2);
  91.                         GPIO_ResetBits(GPIOB, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_3);
  92.                         switch(GPIO_ReadInputData(GPIOB)&0xff)
  93.                         {
  94.                         case 0x14: KeyValue = 3; break;
  95.                         case 0x24: KeyValue = 7; break;
  96.                         case 0x44: KeyValue = 11;break;
  97.                         case 0x84: KeyValue = 15;break;
  98.                         }
  99.                         GPIO_SetBits(GPIOB, GPIO_Pin_3);
  100.                         GPIO_ResetBits(GPIOB, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2);
  101.                         switch(GPIO_ReadInputData(GPIOB)&0xff)
  102.                         {
  103.                         case 0x18: KeyValue = 4; break;
  104.                         case 0x28: KeyValue = 8; break;
  105.                         case 0x48: KeyValue = 12;break;
  106.                         case 0x88: KeyValue = 16;break;
  107.                         }
  108.                         GPIO_SetBits(GPIOB, GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3);
  109.                         GPIO_ResetBits(GPIOB, GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 |GPIO_Pin_7);
  110.                         while((GPIO_ReadInputData(GPIOB)&0xff)!=0x0f)
  111.                         {
  112.                         GPIO_ResetBits (GPIOC, GPIO_Pin_0);
  113.                 GPIOA->ODR=table[KeyValue%10];  
  114.                 Delay_Ms(5);
  115.                 GPIO_SetBits(GPIOC, GPIO_Pin_0);
  116.                 GPIO_ResetBits (GPIOC, GPIO_Pin_1);
  117.                 GPIOA->ODR=table[KeyValue/10];  
  118.                 Delay_Ms(5);
  119.                 GPIO_SetBits(GPIOC, GPIO_Pin_1);
  120.                         };
  121.                         return KeyValue;
  122.                 }
  123.         }
  124.         return 0;
  125. }

  126.         void Delay_Ms( u16 time )
  127. {
  128.                 u16 i,j;
  129.                 for( i = 0; i < time; i++ )
  130.                                 for( j = 10000; j > 0; j-- );
  131. }
caijie001 发表于 2018-3-2 00:15 | 显示全部楼层
单步调试试试,按着一个按键,看看哪个函数没有进入
zhaoyu2005 发表于 2018-3-2 08:44 | 显示全部楼层
没电路图,让人家根据你的程序反推电路?
dirtwillfly 发表于 2018-3-2 16:12 | 显示全部楼层
那么长的代码,很少有人会读的。
建议楼主逐步调试代码看看,还有就是按键和显示分别调试,调试没问题了再进行整合
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

2

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部