我的这个32读入矩阵键盘的程序不太好使似乎是由于gpio配置有问题?哪里有问题呀

2019-07-20 14:21发布

#include "key.h"
#include "delay.h"
#include "sys.h"

void GPIO_Configuration(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;  
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT ;      
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;                                             
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_PuPd =GPIO_PuPd_UP;                                                  
  GPIO_Init(GPIOD, &GPIO_InitStructure);
       
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;//ÆÕí¨êäèëÄ£ê½
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//100M
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;//ÏÂà-
  GPIO_Init(GPIOD, &GPIO_InitStructure);//3õê¼»ˉGPIOE4
       
/*GPIO_InitTypeDef GPIO_InitStructuress;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);                     

       
        GPIO_InitStructuress.GPIO_Pin = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3;  
  GPIO_InitStructuress.GPIO_Mode = GPIO_Mode_OUT ;      
  GPIO_InitStructuress.GPIO_OType = GPIO_OType_PP;                                             
  GPIO_InitStructuress.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructuress.GPIO_PuPd =GPIO_PuPd_UP;                                                  
  GPIO_Init(GPIOD, &GPIO_InitStructuress);
       
               
         GPIO_InitStructuress.GPIO_Pin =GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;   
         GPIO_InitStructuress.GPIO_Mode =GPIO_Mode_IN ;
         GPIO_InitStructuress.GPIO_Speed = GPIO_Speed_100MHz;
         GPIO_InitStructuress.GPIO_PuPd = GPIO_PuPd_DOWN ;
         GPIO_Init(GPIOD, &GPIO_InitStructuress); */
}

extern u8 Keyspress()
{
u8 KeyValue='m';


GPIO_SetBits(GPIOD,GPIO_Pin_0);
GPIO_ResetBits(GPIOD,GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3);

switch(GPIO_ReadInputData(GPIOD)&0xff)
              {
                case 0x11:KeyValue='c';break;

                case 0x21:KeyValue='d';break;

                case 0x41:KeyValue='e';break;

                case 0x81:KeyValue='f';break;
               }
                GPIO_SetBits(GPIOD,GPIO_Pin_1);

                GPIO_ResetBits(GPIOD,GPIO_Pin_0|GPIO_Pin_2|GPIO_Pin_3);

                 switch(GPIO_ReadInputData(GPIOD)&0xff)
               {
                 case 0x12:KeyValue='8';break;

                 case 0x22:KeyValue='9';break;


                 case 0x42:KeyValue='a';break;

                 case 0x82:KeyValue='b';break;

                }
                 GPIO_SetBits(GPIOD,GPIO_Pin_2);

                 GPIO_ResetBits(GPIOD,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_3);


                  switch(GPIO_ReadInputData(GPIOD)&0xff)
                   {
                    case 0x14:KeyValue='4';break;

                    case 0x24:KeyValue='5';break;

                    case 0x44:KeyValue='6';break;

                    case 0x84:KeyValue='7';break;
                   }
                    GPIO_SetBits(GPIOD,GPIO_Pin_3);

                    GPIO_ResetBits(GPIOD,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2);

                   switch(GPIO_ReadInputData(GPIOD)&0xff)
                    {
                     case 0x18:KeyValue='0';break;

                     case 0x28:KeyValue='1';break;

                     case 0x48:KeyValue='2';break;

                     case 0x88:KeyValue='3';break;
                     }
                        GPIO_SetBits(GPIOD,GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2 |GPIO_Pin_3);
                        GPIO_ResetBits(GPIOD, GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 |GPIO_Pin_7);


return KeyValue;
}


0条回答

一周热门 更多>