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

📄 kbd_drv.c

📁 自己编写的MP3源码和大家交流分享一下
💻 C
字号:
/*C**************************************************************************
* NAME:         kbd_drv.c
*----------------------------------------------------------------------------
* Copyright (c) 2003 Atmel.
*----------------------------------------------------------------------------
* RELEASE:      snd1c-refd-nf-4_0_3      
* REVISION:     1.10     
*----------------------------------------------------------------------------
* PURPOSE:
* This file contains the keypad driver routines
*
* NOTES:
* Driver Configuration:
*   - KBD_EXIT_PD in config.h define as:
*      TRUE:  to allow exit of power down by keyboard
*      FALSE: to disallow exit of power down by keyboard
*   - LOCK_ROW in config.h
*   - KEY_LOCK in config.h
* Global Variables:
*   - gl_kbd_lock in bdata space
*****************************************************************************/

/*_____ I N C L U D E S ____________________________________________________*/

#include "config.h"                         /* lib configuration header */
#include "kbd_drv.h"                        /* Keyboard driver definition */


/*_____ M A C R O S ________________________________________________________*/


/*_____ D E F I N I T I O N ________________________________________________*/

static  bdata   bit     gl_kbd_lock;

/*_____ D E C L A R A T I O N ______________________________________________*/

static  void    kbd_set_prio (Byte);
static  void    kbd_install (void);


/*F**************************************************************************
* NAME: kbd_init
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Keyboard initialisation function
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
* ram/xram:
* cycle:
* stack: 
* code:
*****************************************************************************/
void kbd_init (void)
{
  P_KBD |= MSK_COL;             /* all columns inactive */
  gl_kbd_lock = (!LOCK_ROW);    /* Lock Key decoding */
  #if KBD_EXIT_PD
  Kbd_enable_pd_exit();         /* enable keyboard Power-Down exit */
  kbd_set_prio(KBD_PRIO);
  #endif
  kbd_install();
}


/*F**************************************************************************
* NAME: kbd_install
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Keyboard IT and columns mask init
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
* ram/xram:
* cycle:
* stack: 
* code:
*****************************************************************************/
void kbd_install (void)
{
  if (gl_kbd_lock)
  {
    KBCON = KB_LCK;
    P_KBD &= MSK_LCK;
  }
  else
  {
    KBCON = KB_STD;
    P_KBD &= MSK_STD;
  }
  KBSTA = KBSTA;                /* dummy read for clearing pending interrupt */

  #if KBD_EXIT_PD
  Kbd_enable_int();             /* enable or re-enable the kbd interrupt */
  #endif
}


/*F**************************************************************************
* NAME: kbd_set_prio
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Set the keyboard interface priority interrupt
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
* ram/xram:
* cycle:
* stack: 
* code:
*****************************************************************************/
#if KBD_EXIT_PD
void kbd_set_prio (Byte priority)
{
  if ((priority == 1) || (priority == 3))     /* set LSB priority bit */
  {
    IPL1 |=  MSK_EKB;
  }
  if ((priority == 2) || (priority == 3))     /* set MSB priority bit */
  {
    IPH1 |= MSK_EKB;
  }
}
#endif


/*F**************************************************************************
* NAME: kbd_decode
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*   Decoded key pressed
*----------------------------------------------------------------------------
* PURPOSE: 
*   Decode the key that generated an IT
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
* ram/xram:
* cycle:
* stack: 
* code:
*****************************************************************************/
Byte kbd_decode (void)
{
Byte key;

  if (gl_kbd_lock)
  {
    gl_kbd_lock = FALSE;
    kbd_install();
    return (KEY_LOCK);
  }
  else
  {
    P_KBD |= MSK_COL;           /* all columns inactive */
 
    /* COL3 = 0;                /* COL3 test (always 0) */
    key = (P_KBD & MSK_PKB);
    if (key != NK_COL3)
    {
      if (key == KEY_LOCK)
      {
        gl_kbd_lock = TRUE;     /* signal key locked */
      }
      kbd_install();
      return (key);
    }

    COL2 = 0;                   /* COL2 test */
    key = (P_KBD & MSK_PKB);
    if (key != NK_COL2)
    {
      kbd_install();
      return (key);
    }

    COL1 = 0;                   /* COL1 test */
    key = (P_KBD & MSK_PKB);
    if (key != NK_COL1)
    {
      kbd_install();
      return (key);
    }
  
    COL0 = 0;                   /* COL0 test */
    key = (P_KBD & MSK_PKB);
    if (key != NK_COL0)
    {
      kbd_install();
      return (key);
    }
  }
}


/*F**************************************************************************
* NAME: kbd_int
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Keyboard interrupt function
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*   This isr is called when a key is pressed to get out power-down Interrupt
*   is re-enable in the install routine
*----------------------------------------------------------------------------
* REQUIREMENTS:
* ram/xram:
* cycle:
* stack: 
* code:
*****************************************************************************/
#if KBD_EXIT_PD
Interrupt(kbd_int (void), IRQ_KBD)
{
  Kbd_disable_int();              /* disable interrupt */
}
#endif



⌨️ 快捷键说明

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