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

📄 freescale

📁 Freescale 系列单片机常用模块与综合系统设计
💻
字号:
/** ###################################################################
**     THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
**     Filename  : KEY.C
**     Project   : Smoke_Detector
**     Processor : MC9S08JM60CLHE
**     Component : KBI
**     Version   : Component 01.095, Driver 01.20, CPU db: 3.00.046
**     Compiler  : CodeWarrior HCS08 C Compiler
**     Date/Time : 2010-1-25, 17:30
**     Abstract  :
**         This bean "KBI" implements the Freescale Keyboard 
**         Interrupt Module (KBI/KBD) which allows to catch events 
**         on choiced external pins. These pins share one KBI/KBD 
**         interrupt which can be caused by an events on the pins.
**     Settings  :
**         Keyboard                    : KBI 
**         Used pins           
**         Pin 0                       : PTG0_KBIP0
**         Pull resistor               : up
**         Generate interrupt on       : falling
**         Interrupt service           : Enabled
**         Interrupt                   : Vkeyboard
**         Interrupt Priority          : 
**         Enable in init. code        : Yes
**         Events enabled in init.     : Yes
**     Contents  :
**         GetVal  - byte KEY_GetVal(void);
**         SetEdge - byte KEY_SetEdge(byte edge);
**
**     Copyright : 1997 - 2009 Freescale Semiconductor, Inc. All Rights Reserved.
**     
**     http      : www.freescale.com
**     mail      : support@freescale.com
** ###################################################################*/

/* MODULE KEY. */

#include "Events.h"
#include "KEY.h"



/*
** ===================================================================
**     Event       :  KEY_OnInterrupt (module Events)
**
**     Component   :  KEY [KBI]
**     Description :
**         This event is called when the active signal edge/level
**         occurs. This event is enabled only if <Interrupt
**         service/event> property is enabled.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
ISR(KEY_Interrupt)
{
  KBISC_KBACK = 0x01;                  /* Clear the interrupt flag */
  KEY_OnInterrupt();                   /* Invoke user event */
}

/*
** ===================================================================
**     Method      :  KEY_GetVal (component KBI)
**
**     Description :
**         Returns the value of pins
**     Parameters  : None
**     Returns     :
**         ---             - The value of associated pins (bits ordered
**                           according to the bean list of pins)
** ===================================================================
*/
/*
byte KEY_GetVal(void)

**      This method is implemented as macro. See KEY.h file.      **
*/

/*
** ===================================================================
**     Method      :  KEY_SetEdge (component KBI)
**
**     Description :
**         Sets the sensitive edge. If all selected pins don't have the
**         same edge setting possibility, the method allows to set only
**         those edges that are common (possible to set for all
**         selected pins).
**     Parameters  :
**         NAME            - DESCRIPTION
**         edge            - Edge type:
**                           0 - falling edge
**                           1 - rising edge
**                           2 - both edges
**                           3 - low level
**                           4 - high level
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_RANGE - Value is out of range
** ===================================================================
*/
byte KEY_SetEdge(byte edge)
{
  if ((edge > 4) || (edge == 2)) {     /* If parameter is out of range */
    return ERR_RANGE;                  /* ....then return error */
  }
  KBISC_KBIE = 0;                      /* Disable device */
  if ((edge == 3) || (edge == 4)) {    /* Level selected */
    KBISC_KBMOD = 0x01;                /* Set the level */
    if (edge == 3) {
    /* KBIES: KBEDG0=0 */
      KBIES &= ~0x01;                  /* The low level */
    }
    else {
    /* KBIES: KBEDG0=1 */
      KBIES |= 0x01;                   /* The high level */
    }
  }
  else {                               /* Edge selected */
    KBISC_KBMOD = 0;                   /* Set the edge */
    if (edge == 0) {
    /* KBIES: KBEDG0=0 */
      KBIES &= ~0x01;                  /* The falling edge */
    }
    else {
    /* KBIES: KBEDG0=1 */
      KBIES |= 0x01;                   /* The rising edge */
    }
  }
  KBISC_KBACK = 0x01;                  /* Clear the interrupt flag */
  KBISC_KBIE = 0x01;                   /* Enable device */
  return ERR_OK;
}

/*
** ===================================================================
**     Method      :  KEY_Init (component KBI)
**
**     Description :
**         Initializes the associated peripheral(s) and the bean internal 
**         variables. The method is called automatically as a part of the 
**         application initialization code.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void KEY_Init(void)
{
  /* KBIES: KBEDG7=0,KBEDG6=0,KBEDG5=0,KBEDG4=0,KBEDG3=0,KBEDG2=0,KBEDG1=0,KBEDG0=0 */
  setReg8(KBIES, 0x00);                 
  /* KBISC: ??=0,??=0,??=0,??=0,KBF=0,KBACK=0,KBIE=0,KBMOD=0 */
  setReg8(KBISC, 0x00);                 
  /* KBIPE: KBIPE0=1 */
  setReg8Bits(KBIPE, 0x01);            /* Enable appropriate interrupt pin(s) */ 
  /* KBISC: KBACK=1 */
  setReg8Bits(KBISC, 0x04);            /* Clear the interrupt flag */ 
  /* KBISC: KBIE=1 */
  setReg8Bits(KBISC, 0x02);            /* Enable interrupts */ 
}

/* END KEY. */

/*
** ###################################################################
**
**     This file was created by Processor Expert 3.07 [04.34]
**     for the Freescale HCS08 series of microcontrollers.
**
** ###################################################################
*/

⌨️ 快捷键说明

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