lm3s811 矩阵键盘

2019-03-24 15:44发布

lm3s811如何使用 线反转法,读出4 *4矩阵键盘值,好象读出的数据老是不对。 此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
8条回答
citymoon
1楼-- · 2019-03-24 20:15
。试试zlg7290芯片去
ddllxxrr
2楼-- · 2019-03-24 20:39
< :TI_MSP430_内容页_SA7 --> 反转时延时20ms,再试下,不行把程序贴上
uhhznb
3楼-- · 2019-03-24 20:50
 精彩回答 2  元偷偷看……
uhhznb
4楼-- · 2019-03-24 22:18

#ifndef KEYBOARD_H
#define KEYBOARD_H
//定义长标识符成较短的形式
#define SysCtlPeriEnable             SysCtlPeripheralEnable
#define SysCtlPeriDisable            SysCtlPeripheralDisable
#define GPIOPinTypeIn                GPIOPinTypeGPIOInput
#define GPIOPinTypeOutOD        GPIOPinTypeGPIOOutputOD

//行线使用GPIOB(0-3)1111
#define KEYBOARD_LIN_PERIPH        SYSCTL_PERIPH_GPIOB
#define KEYBOARD_LIN_BASE           GPIO_PORTB_BASE
#define KEYBOARD_LIN_PIN        0x0F                  
//列线使用GPIOC(4-7)1111
#define KEYBOARD_COL_PERIPH        SYSCTL_PERIPH_GPIOC
#define KEYBOARD_COL_BASE           GPIO_PORTC_BASE
#define KEYBOARD_COL_PIN       0xF0                            

#endif

 

 


uchar scanKeyboard(void)
{

 ulong scanValue[20]={0xEE,0xDE,0xBE,0x7E,
                     0xED,0xDD,0xBD,0x7D,
                     0xEB,0xDB,0xBB,0x7B,
                     0xE7,0xD7,0xB7,0x77,                                                         
                    };

 const ulong keyASC[20]={'1','2','3','4',
                            '5','6','7','8',
                            '9','10','11','12',
                            '13','14','15','16',
                        }; 


//定义变量及使能GPIOC和GPIOB    
ulong key,temp,temp1,temp2,temp3;
SysCtlPeripheralEnable(KEYBOARD_LIN_PERIPH);
SysCtlPeripheralEnable(KEYBOARD_COL_PERIPH);
//9个引脚全部上拉电阻有效
GPIOPadConfigSet(KEYBOARD_LIN_BASE,KEYBOARD_LIN_PIN,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_OD_WPU);
GPIOPadConfigSet(KEYBOARD_COL_BASE,KEYBOARD_COL_PIN,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_OD_WPU);
GPIOPinTypeOutOD(KEYBOARD_LIN_BASE,KEYBOARD_LIN_PIN);       
GPIOPinTypeIn(KEYBOARD_COL_BASE,KEYBOARD_COL_PIN);             
GPIOPinWrite(KEYBOARD_LIN_BASE,KEYBOARD_LIN_PIN,0x00);           
temp1=GPIOPinRead(KEYBOARD_COL_BASE,KEYBOARD_COL_PIN)& KEYBOARD_COL_PIN; 
                                 

GPIOPadConfigSet(KEYBOARD_LIN_BASE,KEYBOARD_LIN_PIN,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_OD_WPU);
GPIOPadConfigSet(KEYBOARD_COL_BASE,KEYBOARD_COL_PIN,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_OD_WPU);
GPIOPinTypeIn(KEYBOARD_LIN_BASE,KEYBOARD_LIN_PIN);              
GPIOPinTypeOutOD(KEYBOARD_COL_BASE,KEYBOARD_COL_PIN);            
GPIOPinWrite(KEYBOARD_COL_BASE,KEYBOARD_COL_PIN,0x00);              
temp2=GPIOPinRead(KEYBOARD_LIN_BASE,KEYBOARD_LIN_PIN)& KEYBOARD_LIN_PIN;  
temp=temp1 | temp2;                  

if(temp!=0xFF)                                          
{            
    SysCtlDelay(13*(SysCtlClockGet()/3000));
    GPIOPadConfigSet(KEYBOARD_LIN_BASE,KEYBOARD_LIN_PIN,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_OD_WPU);
    GPIOPadConfigSet(KEYBOARD_COL_BASE,KEYBOARD_COL_PIN,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_OD_WPU);
    GPIOPinTypeOutOD(KEYBOARD_LIN_BASE,KEYBOARD_LIN_PIN);    
    GPIOPinTypeIn(KEYBOARD_COL_BASE,KEYBOARD_COL_PIN);         
    GPIOPinWrite(KEYBOARD_LIN_BASE,KEYBOARD_LIN_PIN,0x00);        
    temp1=GPIOPinRead(KEYBOARD_COL_BASE,KEYBOARD_COL_PIN)& KEYBOARD_COL_PIN;
   
    GPIOPadConfigSet(KEYBOARD_LIN_BASE,KEYBOARD_LIN_PIN,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_OD_WPU);
    GPIOPadConfigSet(KEYBOARD_COL_BASE,KEYBOARD_COL_PIN,GPIO_STRENGTH_2MA,GPIO_PIN_TYPE_OD_WPU);
    GPIOPinTypeIn(KEYBOARD_LIN_BASE,KEYBOARD_LIN_PIN);        
    GPIOPinTypeOutOD(KEYBOARD_COL_BASE,KEYBOARD_COL_PIN);       
    GPIOPinWrite(KEYBOARD_COL_BASE,KEYBOARD_COL_PIN,0x00);        
    temp2=GPIOPinRead(KEYBOARD_LIN_BASE,KEYBOARD_LIN_PIN)& KEYBOARD_LIN_PIN;
  
 temp3=temp1 | temp2;
  
   if(temp3==temp)
    {
       for(key=0;key<20;key++) 
         if(temp==scanValue[key])
           {
             GPIOPinTypeIn(KEYBOARD_LIN_BASE,KEYBOARD_LIN_PIN);
             GPIOPinTypeIn(KEYBOARD_COL_BASE,KEYBOARD_COL_PIN); 
             return(keyASC[key]);        
           }
    }

  else

    {

      return('E');

    }
}
return ('N');
}

uhhznb
5楼-- · 2019-03-24 23:02
程序已经贴出来了, 有谁能帮我看看问题出在哪里吗?
永远的不知
6楼-- · 2019-03-25 04:08
 精彩回答 2  元偷偷看……

一周热门 更多>

相关问题

    相关文章