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

📄 delay_timer.c

📁 SPI主机模式进行串行通信
💻 C
字号:
/** ###################################################################
**     THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
**     Filename  : Delay_timer.C
**     Project   : spi_master
**     Processor : 56F8346
**     Beantype  : TimerInt
**     Version   : Bean 02.110, Driver 01.22, CPU db: 2.87.097
**     Compiler  : Metrowerks DSP C Compiler
**     Date/Time : 2009-1-12, 16:11
**     Abstract  :
**         This bean "TimerInt" implements a periodic interrupt.
**         When the bean and its events are enabled, the "OnInterrupt"
**         event is called periodically with the period that you specify.
**         TimerInt supports also changing the period in runtime.
**         The source of periodic interrupt can be timer compare or reload
**         register or timer-overflow interrupt (of free running counter).
**     Settings  :
**         Timer name                  : TMRA0 (16-bit)
**         Compare name                : TMRA0_Compare
**         Counter shared              : No
**
**         High speed mode
**             Prescaler               : divide-by-128
**             Clock                   : 468750 Hz
**           Initial period/frequency
**             Xtal ticks              : 800000
**             microseconds            : 100000
**             milliseconds            : 100
**             seconds (real)          : 0.1000000
**             Hz                      : 10
**
**         Runtime setting             : none
**
**         Initialization:
**              Timer                  : Enabled
**              Events                 : Enabled
**
**         Timer registers
**              Counter                : TMRA0_CNTR [61509]
**              Mode                   : TMRA0_CTRL [61510]
**              Run                    : TMRA0_CTRL [61510]
**              Prescaler              : TMRA0_CTRL [61510]
**
**         Compare registers
**              Compare                : TMRA0_CMP1 [61504]
**
**         Flip-flop registers
**              Mode                   : TMRA0_SCR [61511]
**     Contents  :
**         Enable       - byte Delay_timer_Enable(void);
**         Disable      - byte Delay_timer_Disable(void);
**         EnableEvent  - byte Delay_timer_EnableEvent(void);
**         DisableEvent - byte Delay_timer_DisableEvent(void);
**
**     (c) Copyright UNIS, spol. s r.o. 1997-2005
**     UNIS, spol. s r.o.
**     Jundrovska 33
**     624 00 Brno
**     Czech Republic
**     http      : www.processorexpert.com
**     mail      : info@processorexpert.com
** ###################################################################*/

/* MODULE Delay_timer. */

#include "Events.h"
#include "Delay_timer.h"

static bool EnUser;                    /* Enable/Disable device by user */
static bool EnEvent;                   /* Enable/Disable events */


/*
** ===================================================================
**     Method      :  SetCV (bean TimerInt)
**
**     Description :
**         Sets compare or preload register value. The method is called 
**         automatically as a part of several internal methods.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void SetCV(word Val)
{
  EnterCritical();                     /* Disable global interrupts */
  setReg(TMRA0_CMPLD1,Val);            /* Store given value to the compare preload 1 register */
  setReg(TMRA0_CMPLD2,Val);            /* Store given value to the compare preload 2 register */
  ExitCritical();                      /* Enable global interrupts */
}

/*
** ===================================================================
**     Method      :  SetPV (bean TimerInt)
**
**     Description :
**         Sets prescaler value. The method is called automatically as a 
**         part of several internal methods.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void SetPV(byte Val)
{
  setRegBitGroup(TMRA0_CTRL,PCS,Val);  /* Store given value to the prescaler */
  setReg(TMRA0_CNTR,0);                /* Reset counter */
}

/*
** ===================================================================
**     Method      :  HWEnDi (bean TimerInt)
**
**     Description :
**         Enables or disables the peripheral(s) associated with the bean.
**         The method is called automatically as a part of the Enable and 
**         Disable methods and several internal methods.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
static void HWEnDi(void)
{
  if (EnUser) {                        /* Enable device? */
    setReg(TMRA0_CMP1,getReg(TMRA0_CMPLD1)); /* Refresh compare 1 register */
    setReg(TMRA0_CMP2,getReg(TMRA0_CMPLD2)); /* Refresh compare 2 register */
    setRegBitGroup(TMRA0_CTRL,CM,1);   /* Run counter */
  }
  else {                               /* Disable device? */
    setRegBitGroup(TMRA0_CTRL,CM,0);   /* Stop counter */
    setReg(TMRA0_CNTR,0);              /* Reset counter */
  }
}

/*
** ===================================================================
**     Method      :  Delay_timer_Enable (bean TimerInt)
**
**     Description :
**         Enables the bean - it starts the timer. Events may be
**         generated ("DisableEvent"/"EnableEvent").
**     Parameters  : None
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
** ===================================================================
*/
byte Delay_timer_Enable(void)
{
  if (!EnUser) {                       /* Is the device disabled by user? */
    EnUser = TRUE;                     /* If yes then set the flag "device enabled" */
    HWEnDi();                          /* Enable the device */
  }
  return ERR_OK;                       /* OK */
}

/*
** ===================================================================
**     Method      :  Delay_timer_Disable (bean TimerInt)
**
**     Description :
**         Disables the bean - it stops the timer. No events will be
**         generated.
**     Parameters  : None
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
** ===================================================================
*/
byte Delay_timer_Disable(void)
{
  if (EnUser) {                        /* Is the device enabled by user? */
    EnUser = FALSE;                    /* If yes then set the flag "device disabled" */
    HWEnDi();                          /* Disable the device */
  }
  return ERR_OK;                       /* OK */
}

/*
** ===================================================================
**     Method      :  Delay_timer_EnableEvent (bean TimerInt)
**
**     Description :
**         Enables the events.
**     Parameters  : None
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
** ===================================================================
*/
byte Delay_timer_EnableEvent(void)
{
  EnEvent = TRUE;                      /* Set the flag "events enabled" */
  return ERR_OK;                       /* OK */
}

/*
** ===================================================================
**     Method      :  Delay_timer_DisableEvent (bean TimerInt)
**
**     Description :
**         Disables the events.
**     Parameters  : None
**     Returns     :
**         ---             - Error code, possible codes:
**                           ERR_OK - OK
**                           ERR_SPEED - This device does not work in
**                           the active speed mode
** ===================================================================
*/
byte Delay_timer_DisableEvent(void)
{
  EnEvent = FALSE;                     /* Set the flag "events disabled" */
  return ERR_OK;                       /* OK */
}

/*
** ===================================================================
**     Method      :  Delay_timer_Init (bean TimerInt)
**
**     Description :
**         Initializes the associated peripheral(s) and the beans 
**         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 Delay_timer_Init(void)
{
  /* TMRA0_CTRL: CM=0,PCS=0,SCS=0,ONCE=0,LENGTH=1,DIR=0,Co_INIT=0,OM=4 */
  setReg(TMRA0_CTRL,36);               /* Stop timer, use alternating compare registers */
  /* TMRA0_SCR: TCF=0,TCFIE=1,TOF=0,TOFIE=0,IEF=0,IEFIE=0,IPS=0,INPUT=0,Capture_Mode=0,MSTR=0,EEOF=0,VAL=0,FORCE=0,OPS=0,OEN=0 */
  setReg(TMRA0_SCR,16384);             /* Enable compare interrupt */
  setReg(TMRA0_CNTR,0);                /* Reset counter register */
  setReg(TMRA0_LOAD,0);                /* Reset load register */
  setReg(TMRA0_CMP1,46874);            /* Set up compare 1 register */
  setReg(TMRA0_CMP2,46874);            /* Set up compare 2 register */
  /* TMRA0_COMSCR: ??=0,??=0,??=0,??=0,??=0,??=0,??=0,??=0,TCF2EN=0,TCF1EN=0,TCF2=0,TCF1=0,CL2=1,CL1=2 */
  setReg(TMRA0_COMSCR,6);              /* Compare load control */
  EnEvent = TRUE;                      /* Enable events */
  EnUser = TRUE;                       /* Enable device */
  SetCV(46874);                        /* Store appropriate value to the compare register according to the selected high speed CPU mode */
  SetPV(15);                           /* Set prescaler register according to the selected high speed CPU mode */
  HWEnDi();                            /* Enable/disable device according to status flags */
}

/*
** ===================================================================
**     Method      :  Delay_timer_Interrupt (bean TimerInt)
**
**     Description :
**         The method services the interrupt of the selected peripheral(s)
**         and eventually invokes the beans event(s).
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
#pragma interrupt alignsp saveall
void Delay_timer_Interrupt(void)
{
  clrRegBit(TMRA0_SCR,TCF);            /* Reset interrupt request flag */
  if (EnEvent) {                       /* Are the events enabled? */
    Delay_timer_OnInterrupt();         /* Invoke user event */
  }
}

/* END Delay_timer. */

/*
** ###################################################################
**
**     This file was created by UNIS Processor Expert 2.97 [03.74]
**     for the Freescale 56800 series of microcontrollers.
**
** ###################################################################
*/

⌨️ 快捷键说明

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