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

📄 to1.c

📁 GCC 做的MOTOROLA 的单片机 振荡程序
💻 C
字号:
/** ###################################################################
**     THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
**     Filename  : TO1.C
**     Project   : LowFreqSG
**     Processor : MC68HC908LV8CFA
**     Beantype  : TimerOut
**     Version   : Bean 02.147, Driver 01.27, CPU db: 2.89.060
**     Compiler  : CodeWarrior HC08 C Compiler
**     Date/Time : 2006-9-6, 11:54
**     Abstract  :
**         This bean implements a periodic signal generator 1:1 (Flip-Flop Output).
**         The signal alternates the "0" and "1" output values in exactly
**         regular intervals; that is why the time length of the "0" part
**         of one pulse is equal to the "1" part of one pulse.
**     Settings  :
**         Used output pin             : 
**             ----------------------------------------------------
**                Number (on package)  |    Name
**             ----------------------------------------------------
**                       38            |  PTB4_T2CH0
**             ----------------------------------------------------
**
**         Timer name                  : TIM2 (16-bit)
**         Compare name                : TIM20
**           Counter shared            : No
**           Output compare            : buffered
**
**         High speed mode
**             Prescaler               : divide-by-2
**             Clock                   : 3997696 Hz
**           Pulse width
**             Xtal ticks              : 328
**             microseconds            : 10000
**             milliseconds            : 10
**             seconds (real)          : 0.0100000
**             Hz                      : 100
**
**         Runtime setting             : none
**
**         Initialization:
**              Output level           : high
**              Timer                  : Enabled
**              Events                 : Enabled
**
**         Timer registers
**              Counter                : T2CNT     [$002C]
**              Mode                   : T2SC      [$002B]
**              Run                    : T2SC      [$002B]
**              Prescaler              : T2SC      [$002B]
**
**         Compare registers
**              Compare                : T2CH0     [$0031]
**              Compare 2              : T2CH1     [$0034]
**
**         Flip-flop registers
**              Mode                   : T2SC0     [$0030]
**     Contents  :
**         No public methods
**
**     (c) Copyright UNIS, spol. s r.o. 1997-2006
**     UNIS, spol. s r.o.
**     Jundrovska 33
**     624 00 Brno
**     Czech Republic
**     http      : www.processorexpert.com
**     mail      : info@processorexpert.com
** ###################################################################*/


/* MODULE TO1. */

#include "PE_Error.h"
#include "TO1.h"

#pragma MESSAGE DISABLE C2705          /* WARNING C2705: Possible loss of data */
#pragma MESSAGE DISABLE C5919          /* WARNING C5919: Conversion of floating to unsigned integral */

bool Alt;                       /* Alternate compare register */

/* Internal method prototypes */

/*
** ===================================================================
**     Method      :  SetCV (bean TimerOut)
**
**     Description :
**         The method computes and sets compare eventually modulo value 
**         for time measuring.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void SetCV(word Val);
/*
** ===================================================================
**     Method      :  SetPV (bean TimerOut)
**
**     Description :
**         The method sets prescaler of the device.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void SetPV(byte Val);

/* End of Internal methods declarations */

/*
** ===================================================================
**     Method      :  SetCV (bean TimerOut)
**
**     Description :
**         The method computes and sets compare eventually modulo value 
**         for time measuring.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void SetCV(word Val)
{
  Alt = !Alt;                          /* Change alternate compare registeres */
  if (Alt) {
    T2CH1H = (*(TWREG*)&Val).b.high;   /* Store given value to the compare register */
    T2CH1L = (*(TWREG*)&Val).b.low;
  }
  else {
    T2CH0H = (*(TWREG*)&Val).b.high;   /* Store given value to the compare register */
    T2CH0L = (*(TWREG*)&Val).b.low;
  }
  T2MODH = (*(TWREG*)&Val).b.high;     /* Store given value to the modulo register */
  T2MODL = (*(TWREG*)&Val).b.low;
}

/*
** ===================================================================
**     Method      :  SetPV (bean TimerOut)
**
**     Description :
**         The method sets prescaler of the device.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void SetPV(byte Val)
{
  T2SC_PS = Val;                       /* Store given value to the prescaler */
  T2SC_TRST = 1;                       /* Reset counter */
}

/*
** ===================================================================
**     Method      :  TO1_Init (bean TimerOut)
**
**     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 TO1_Init(void)
{
  /* T2SC: TOF=0,TOIE=0,TSTOP=1,TRST=1,??=0,PS2=0,PS1=0,PS0=0 */
  setReg8(T2SC, 0x30);                 /* Stop and reset counter */ 
  /* T2SC0: CH0F=0,CH0IE=0,MS0B=1,MS0A=0,ELS0B=0,ELS0A=0,TOV0=0,CH0MAX=0 */
  setReg8(T2SC0, 0x20);                /* Set output signal level to high */ 
  /* T2SC0: CH0F=0,CH0IE=0,MS0B=1,MS0A=1,ELS0B=0,ELS0A=1,TOV0=0,CH0MAX=0 */
  setReg8(T2SC0, 0x34);                 
  Alt = FALSE;                         /* Set up currently active channel flag */
  setReg8(T2CH0H, 0x9C);               /* Store initial value to the duty-compare register */ 
  setReg8(T2CH0L, 0x28);                
  SetCV((word)0x9C28);                 /* Store appropriate value to the compare register according to the selected high speed CPU mode */
  SetPV((byte)0x01);                   /* Set prescaler register according to the selected high speed CPU mode */
  /* T2SC: TSTOP=0 */
  clrReg8Bits(T2SC, 0x20);             /* Run counter */ 
}

/* END TO1. */

/*
** ###################################################################
**
**     This file was created by UNIS Processor Expert 2.98 [03.80]
**     for the Freescale HC08 series of microcontrollers.
**
** ###################################################################
*/

⌨️ 快捷键说明

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