📄 hwtimer.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 + -