hwtimer.c

来自「Renesas(Hitachi SuperH)SH7708的UCOS2源码,uC」· C语言 代码 · 共 75 行

C
75
字号
/*---------------------------------------------------------------------------*/
/*  Timer Module                                                             */
/*  Author: Kuan, Yeou-Fuh                                                   */
/*---------------------------------------------------------------------------*/
#include "sh7707.h"
#include "includes.h"

void InitTimer ( void );
void StartTimer ( char );
void StopTimer ( char );

/*---------------------------------------------------------------------------*/
/*  To generate Tk times interrupt per second, TCOR is calculated by         */
/*  the following formula.                                                   */
/*  Pclk: Peripheral Clock.                                                  */
/*  Tk  : Desired Realtime Clock times per second.                           */
/*  TCORn = ((Pclk * 1000000) / (256 * Tk)) - 1.                             */
/*  n = 0, 1, 2 (timer channel number).                                      */
/*---------------------------------------------------------------------------*/
void InitTimer ()
{
   /* Set Timer 0 */
   int Pclk;

//   Pclk = 20000000L;
	Pclk = 15000000L;

   TSTR  = 0x00;                /* Halt timer befor writing to registers */
   TCOR0 = (Pclk/256/50) - 1;  /* Set Compare match register            */
   TCNT0 = (Pclk/256/50) - 1;  /* Initial timer counter                 */   //
                                /* 100 times interrupt per second        */
   TCR0  = 0x0023;              /* Interrupt enable when underflow       */
                                /* TCNT count clock is Pclk/256          */
   TCR1  = 0x0000;
   TCR2  = 0x0000;
   return;
}

/******************************************/
/* Timer Unit Setting                     */
/******************************************/
void StartTimer ( char channel )
{
   switch ( channel )
   {
      case 0:
           TSTR |= 0x01;
           break;
      case 1:
           TSTR |= 0x02;
           break;
      case 2:
           TSTR |= 0x04;
           break;
   }
   return;
}

void StopTimer ( char channel )
{
   switch ( channel )
   {
      case 0:
           TSTR &= 0xFE;
           break;
      case 1:
           TSTR &= 0xFD;
           break;
      case 2:
           TSTR &= 0xFB;
           break;
   }
   return;
}

⌨️ 快捷键说明

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