?? kbd_drv.c
字號:
/*C**************************************************************************
* $RCSfile: kbd_drv.c,v $
*----------------------------------------------------------------------------
* Copyright (c) 2002 Atmel.
*----------------------------------------------------------------------------
* RELEASE: $Name: DEMO_FAT_1_9_9 $
* REVISION: $Revision: 1.5 $
* FILE_CVSID: $Id: kbd_drv.c,v 1.5 2002/07/16 09:54:55 njourdan Exp $
*----------------------------------------------------------------------------
* 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 ________________________________________________*/
extern 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 == TRUE
Kbd_enable_pd_exit(); /* enable keyboard Power-Down exit */
kbd_set_prio(KBD_PRIO);
Kbd_enable_int(); /* enable or re-enable the keyboard interrupt */
#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 + -