kbd_drv.c

来自「基于AT89C51SND1的MP3的程序设计(包括播放mp3和录音功能)」· C语言 代码 · 共 177 行

C
177
字号
/*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)
{
  gl_kbd_lock = (!LOCK_ROW);    /* Lock Key decoding */
  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_LCK;
  }
  KBSTA = KBSTA;                /* dummy read for clearing pending interrupt */
}



/*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
  {
	  key = P_KBD;
      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 + =
减小字号Ctrl + -
显示快捷键?