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

📄 kbd_drv.c

📁 ATMEL 89c51sndc mp3外接硬盘源码
💻 C
字号:
/*C**************************************************************************
* NAME:         kbd_drv.c
*----------------------------------------------------------------------------
* Copyright (c) 2002 Atmel.
*----------------------------------------------------------------------------
* RELEASE:      snd1c-demo-hdd-0_2_0      
* REVISION:     1.9     
*----------------------------------------------------------------------------
* 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
*****************************************************************************/

/*_____ 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 ________________________________________________*/


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

static  void    kbd_set_prio (Byte);


/*F**************************************************************************
* NAME: kbd_init
*----------------------------------------------------------------------------
* PARAMS:
*
* return:
*----------------------------------------------------------------------------
* PURPOSE: 
*   Keyboard initialisation function
*----------------------------------------------------------------------------
* EXAMPLE:
*----------------------------------------------------------------------------
* NOTE:
*----------------------------------------------------------------------------
* REQUIREMENTS:
* ram/xram:
* cycle:
* stack: 
* code:
*****************************************************************************/
bit kbd_init (void)
{
  #if KBD_EXIT_PD == TRUE
  Kbd_enable_pd_exit();                     /* enable keyboard Power-Down exit */
  kbd_set_prio(KBD_PRIO);
  Kbd_enable_int();                         /* enable the keyboard interrupt */
  #endif

  KBSTA = KBSTA;                            /* clear pending interrupt */
  P_KBD |= MSK_COL;                         /* all columns inactive */
  if (!Kbd_key_locked())
  {
    KBCON = KB_STD;                         /* detect 1 to 0 transition */
    P_KBD &= MSK_STD;                       /* 0 on all columns */
    return ON;                              /* Keyboard not locked */
  }
  return OFF;                               /* Keyboard locked */
}


/*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;

  P_KBD |= MSK_COL;                         /* all columns inactive */

  /* COL3 = 0;                              /* COL3 test (always 0) */
  key = (P_KBD & MSK_PKB);
  if (key != NK_COL3)
  {
    KBCON |= (KBSTA << 4);                  /* detect 0 to 1 transition */
    P_KBD &= MSK_STD;                       /* 0 on all columns */
    KBSTA = KBSTA;                          /* clear pending interrupt */
    #if KBD_EXIT_PD
    Kbd_enable_int();                       /* re-enable the interrupt */
    #endif
    return (key);
  }

  COL2 = 0;                                 /* COL2 test */
  key = (P_KBD & MSK_PKB);
  if (key != NK_COL2)
  {
    KBCON |= (KBSTA << 4);                  /* detect 0 to 1 transition */
    P_KBD &= MSK_STD;                       /* 0 on all columns */
    KBSTA = KBSTA;                          /* clear pending interrupt */
    #if KBD_EXIT_PD
    Kbd_enable_int();                       /* re-enable the interrupt */
    #endif
    return (key);
  }

  COL1 = 0;                                 /* COL1 test */
  key = (P_KBD & MSK_PKB);
  if (key != NK_COL1)
  {
    KBCON |= (KBSTA << 4);                  /* detect 0 to 1 transition */
    P_KBD &= MSK_STD;                       /* 0 on all columns */
    KBSTA = KBSTA;                          /* clear pending interrupt */
    #if KBD_EXIT_PD
    Kbd_enable_int();                       /* re-enable the interrupt */
    #endif
    return (key);
  }

  COL0 = 0;                                 /* COL0 test */
  key = (P_KBD & MSK_PKB);
  if (key != NK_COL0)
  {
    KBCON |= (KBSTA << 4);                  /* detect 0 to 1 transition */
    KBSTA = KBSTA;                          /* clear pending interrupt */
    #if KBD_EXIT_PD
    Kbd_enable_int();                       /* re-enable the interrupt */
    #endif
    return (key);
  }

  KBCON = KB_STD;                           /* detect 1 to 0 transition */
  P_KBD &= MSK_STD;                         /* 0 on all columns */
  KBSTA = KBSTA;                            /* clear pending interrupt */
  #if KBD_EXIT_PD
  Kbd_enable_int();                         /* re-enable the interrupt */
  #endif
  return NO_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 decode 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 + -