/*
** ###################################################################
**
**     THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
**
**     Filename  : TI1.C
**
**     Project   : Full1
** 
**     Processor : MC68HC908AZ60MFU
**
**     Beantype  : TimerInt
**
**     Version   : Bean 02.053, Driver 01.02, CPU db: 2.81.019
**
**     Compiler  : Metrowerks HC08 C Compiler V-5.0.13
**
**     Date/Time : 2.4.2002, 9:36
**
**     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                  : TIM (16-bit)
**         Compare name                : TIMmod
**         Counter shared              : No
**
**         High-speed CPU mode
**             Prescaler               : divide-by-64
**             Clock                   : 31250 Hz
**           Initial period/frequency
**             Xtal ticks              : 16000000
**             microseconds            : 2000000
**             milliseconds            : 2000
**             seconds                 : 2
**             seconds (real)          : 2.0000000
**
**         Runtime setting             : none
**
**         Initialization:
**              Timer                  : Enabled
**              Events                 : Enabled
**
**         Timer registers
**              Counter                : TCNT      [76]
**              Mode                   : TSC       [75]
**              Run                    : TSC       [75]
**              Prescaler              : TSC       [75]
**
**         Compare registers
**              Compare                : TMOD      [78]
**
**         Flip-flop registers
**
**     Contents  :
**
**         No public methods
**
**
**     (c) Copyright UNIS, spol. s r.o. 1997-2002
**
**     UNIS, spol. s r.o.
**     Jundrovska 33
**     624 00 Brno
**     Czech Republic
**
**     http      : www.processorexpert.com
**     mail      : info@processorexpert.com
**
** ###################################################################
*/


/* MODULE TI1. */

#include "Events.h"
#include "PE_Error.h"
#include "TI1.h"

#pragma MESSAGE DISABLE C2705          /* WARNING C2705: Possible loss of data */
#pragma MESSAGE DISABLE C5919          /* WARNING C5919: Conversion of floating to unsigned integral */



/*
** ===================================================================
**     Method      :  TI1_SetCV (bean TimerInt)
**
**     Description :
**         This method is internal. It is used by Processor Expert
**         only.
** ===================================================================
*/
static void SetCV(word Val)
{
  TMODH = (*(TWREG*)&Val).b.high;      /* Store given value to the compare register */
  TMODL = (*(TWREG*)&Val).b.low;
}

/*
** ===================================================================
**     Method      :  TI1_SetPV (bean TimerInt)
**
**     Description :
**         This method is internal. It is used by Processor Expert
**         only.
** ===================================================================
*/
static void SetPV(byte Val)
{
  TSC_PS = Val;                        /* Store given value to the prescaler */
  TSC_TRST = 1;                        /* Reset counter */
}

/*
** ===================================================================
**     Method      :  TI1_Init (bean TimerInt)
**
**     Description :
**         This method is internal. It is used by Processor Expert
**         only.
** ===================================================================
*/
void TI1_Init(void)
{
  TSC = 112;                           /* Set up (output) compare mode */
  SetCV(62500);                        /* Store appropriate value to the compare register according to the selected high speed CPU mode */
  SetPV(6);                            /* Set prescaler register according to the selected high speed CPU mode */
  TSC_TSTOP = 0;                       /* Run counter */
}

/*
** ===================================================================
**     Method      :  TI1_Interrupt (bean TimerInt)
**
**     Description :
**         This method is internal. It is used by Processor Expert
**         only.
** ===================================================================
*/
__interrupt void TI1_Interrupt(void)
{
  TSC_TOF = 0;                         /* Reset interrupt request flag */
  TI1_OnInterrupt();                   /* Invoke user event */
}


/* END TI1. */

/*
** ###################################################################
**
**     This file was created by UNIS Processor Expert 02.84 for 
**     the Motorola HC08 series of microcontrollers.
**
** ###################################################################
*/
