📄 timer.c
字号:
/**************************************************************************************************
*
* Copyright (c) 2001 - 2003 Winbond Electronics Corp. All rights reserved.
*
* FILENAME
* timer.c
*
* VERSION
* 1.0
*
* DESCRIPTION
* This file contains the timer initial routine and timer ISR.
*
* DATA STRUCTURES
* None
*
* FUNCTIONS
* 1. TimerX_ISR()
* 2. TimerInitialize()
* 3. ShowCurTime()
*
* HISTORY
* 04/14/2003 Ver 1.0 Created by PC30 MNCheng
*
* REMARK
* None
*
*************************************************************************************************/
#include <stdio.h>
#include "740defs.h"
volatile uint32 cur_ticks = 0; //1 sec = 100 ticks
void TimerX_ISR()
{
cur_ticks++;
TISR = 0;
}
void TimerInitialize(int channel)
{
Disable_Int(TIMERINT0+channel);
if (channel == 0)
{
//TCR0 = 0x68000000; /* CE=1, IE=1, periodic mode, pre-scaler=1 */
//TICR0 = (EXT_CLOCK_RATE / TICKS_PER_SEC); /* timer initial count */
outpw(TCR0, 0x68000000);
outpw(TICR0, (EXT_CLOCK_RATE / TICKS_PER_SEC));
}
else
{
//TCR1 = 0x68000000; /* CE=1, IE=1, periodic mode, pre-scaler=1 */
//TICR1 = (EXT_CLOCK_RATE / TICKS_PER_SEC); /* timer initial count */
outpw(TCR1, 0x68000000);
outpw(TICR1, (EXT_CLOCK_RATE / TICKS_PER_SEC));
}
SetIntISR(TIMERINT0+channel, TimerX_ISR);
Enable_Int(TIMERINT0+channel);
} /* end Timer Initialize */
void ShowCurTime()
{
volatile uint32 t_hr, t_min, t_sec;
uint32 ticks;
ticks = cur_ticks; //get current tick count !
t_sec = ticks / TICKS_PER_SEC;
t_min = t_sec / 60;
t_sec %= 60;
t_hr = t_min / 60;
t_min %= 60;
UART_printf("RUNNING TIME - %2d : %2d : %2d\n", t_hr, t_min, t_sec);
UART_printf("%c[1A", 0x1B);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -