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

📄 hwtimer.c

📁 Renesas(Hitachi SuperH)SH7708的UCOS2源码,uC/OS-II 版本2.52.
💻 C
字号:
/*---------------------------------------------------------------------------*/
/*  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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -