⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 The aim of this application note is to show to scan the 4x4 matrix keypad multiplexed with a four
💻 C
字号:
/******************** (C) COPYRIGHT 2003 STMicroelectronics*********************
* File Name          : main.c
* Author             : MCD Application Team
* Date First Issued  : 14/09/2003
* Description        : This file is used for the STR71x GPIO SCANNING A 4x4 MATRIX
*                      KEYPAD application note (AN1799).
********************************************************************************
* History:
*  20/12/2004 : V1.2
*  14/09/2003 : created
********************************************************************************
 THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH
 CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
 AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT
 OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
 OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION
 CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
#include "71x_lib.h"

u8 DecodeKey(u8 Key);

u8 b7SegmentTable[16] = {0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,
                         0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71};

u8 bDP,KeyCode,CharToDisplay[4] = {0,0,0,0};
bool KeyPressed;

#define KEY_0 0x84
#define KEY_1 0x18
#define KEY_2 0x14
#define KEY_3 0x12
#define KEY_4 0x28
#define KEY_5 0x24
#define KEY_6 0x22
#define KEY_7 0x48
#define KEY_8 0x44
#define KEY_9 0x42
#define KEY_A 0x11
#define KEY_B 0x21
#define KEY_C 0x41
#define KEY_D 0x81
#define KEY_E 0x88
#define KEY_F 0x82


int main(void)
{
 u8 i;
 #ifdef DEBUG
 debug();
 #endif

/*   GPIO 1&2 ports configuration ------------------------------------------------*/
  /*  Configure the GPIO 1 port to output Puch-Pull */
  GPIO_Config(GPIO1, 0x0FFF, GPIO_OUT_PP);
  /*  Configure the GPIO 2 port to Input Pull Up /Pull Down Weak Push-Pull */
  GPIO_Config(GPIO2, 0x0F00, GPIO_IPUPD_WP);
  GPIO_WordWrite(GPIO1, 0x0F00);

/*  Set system clock to 32 MHz with a main oscilator = 16 MHz---------------------*/
  /*  Configure the PLL with a multiplication factor = 16 and division factor = 4 */
  RCCU_PLL1Config(RCCU_Mul_16, RCCU_Div_4);

  /*  Set the APB2 clock to default */
  RCCU_PCLKConfig(RCCU_DEFAULT);

  /*  Set the RCLK to the PLL output */
  RCCU_RCLKSourceConfig(RCCU_PLL1_Output);

/*  EIC configuration------------------------------------------------------------- */
  /*  Initialize the interrupt controller */
  EIC_Init();

  /*  Set the Timer 0 interrupt channel priority level to 1 */
  EIC_IRQChannelPriorityConfig(T0TIMI_IRQChannel, 1);

  /*  Enable the Timer 0 IRQ channel interrupts */
  EIC_IRQChannelConfig(T0TIMI_IRQChannel, ENABLE);

  /*  Set the XTI interrupt channel priority level to 2 */
  EIC_IRQChannelPriorityConfig(XTI_IRQChannel, 2);

  /*  Enable the XTI IRQ channel interrupts */
  EIC_IRQChannelConfig(XTI_IRQChannel, ENABLE);

  /*  Enable IRQ interrupts */
  EIC_IRQConfig(ENABLE);

/*  Configure the External Interrupt Unit----------------------------------------- */
  /*  Initialize the XTI */
  XTI_Init();

  /*  Configure the line 2, 3, 4 and 5 edge. */
  XTI_LineModeConfig(XTI_Line2|XTI_Line3|XTI_Line4|XTI_Line5, XTI_RisingEdge);

  /*  Enable the line 2, 3, 4 and 5 interrupt. */
  XTI_LineConfig(XTI_Line2|XTI_Line3|XTI_Line4|XTI_Line5, ENABLE);

  /*  Enable Interrupt. */
  XTI_ModeConfig(XTI_Interrupt, ENABLE);

/*  TIM0 configuration------------------------------------------------------------ */
  /* Configure the Prescaler to 0x04 to get an Overflow interrupt every 5.120 ms
     This will gives an update rate of 48.8 Hz*/
  /*   Inisialize the Timer 0 */
  TIM_Init( TIM0 );

  /*  Configure the Timer 0 prescaler */
  TIM_PrescalerConfig(TIM0, 0x02);

  /*  Enable the Overflow Interrupt */
  TIM_ITConfig(TIM0, TIM_TO_IT, ENABLE);

  /*  Start the TIM0 Counter */
  TIM_CounterConfig(TIM0, TIM_START);

  /*  infinite loop */
   while(1)
    for(i=0;i<4;i++)
      {
         while(!KeyPressed); /*  Wait until key pressed */
         KeyPressed = FALSE;
         CharToDisplay[i] = DecodeKey(KeyCode);
      }
}
/*******************************************************************************
* Function Name  : DecodeKey
* Description    : This function translate the key code to the key value.
* Input          : The Key Code
* Output         : None
* Return         : The Key Value
*******************************************************************************/
u8 DecodeKey(u8 Key)
{
  switch(Key)
  {
    case KEY_0 : return  0x00;
    case KEY_1 : return  0x01;
    case KEY_2 : return  0x02;
    case KEY_3 : return  0x03;
    case KEY_4 : return  0x04;
    case KEY_5 : return  0x05;
    case KEY_6 : return  0x06;
    case KEY_7 : return  0x07;
    case KEY_8 : return  0x08;
    case KEY_9 : return  0x09;
    case KEY_A : return  0x0A;
    case KEY_B : return  0x0B;
    case KEY_C : return  0x0C;
    case KEY_D : return  0x0D;
    case KEY_E : return  0x0E;
    case KEY_F : return  0x0F;
    default    : return  0x10;
  }
}

/******************* (C) COPYRIGHT 2003 STMicroelectronics *****END OF FILE****/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -