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

📄 timer.c

📁 nxp的ARM9处理器LPC3180代码,提供了几乎所有的外设示例程序.
💻 C
字号:
/*****************************************************************************
 *   timer.c: Timer C file for Philips LPC318x Family Microprocessors
 *
 *   Copyright(C) 2006, Philips Semiconductor
 *   All rights reserved.
 *
 *   History
 *   2005.10.01  ver 1.00    Prelimnary version, first Release
 *
******************************************************************************/
#include "LPC318x.h"			/* LPC318X Peripheral Registers	*/
#include "type.h"
#include "target.h"
#include "irq.h"
#include "timer.h"

volatile DWORD timer_counter = 0;

/******************************************************************************
** Function name:		Timer0Handler
**
** Descriptions:		Timer/Counter 0 interrupt handler
**
**
** parameters:			None
** Returned value:		None
** 
******************************************************************************/
void TIMER_ISR( void ) 
{  
    timer_counter++;		/* global timer counter */

    HSTIM_CTRL |=  (1 << 1);	/* Set the Timer Reset bit, counter to 0x0 */
    HSTIM_CTRL &= ~(1 << 1);	/* Clear the Reset bit */
     
    HSTIM_INT |= (1 << 2);	/* Clear the match2 interrupt */
    return;
}

/******************************************************************************
** Function name:		enable_timer
**
** Descriptions:		Enable timer
**
** parameters:			None
** Returned value:		None
** 
******************************************************************************/
void enable_timer( void )
{
    HSTIM_CTRL |=  (1 << 1);	/* Set the Timer Reset bit, counter to 0x0 */
    HSTIM_CTRL &= ~(1 << 1);	/* Clear the Reset bit */
    HSTIM_MCTRL |= (1 << 6);	/* Enable Interrupt generation on Match2 */
    HSTIM_CTRL |= (1 << 0);	/* Start the Timer */
    return;
}

/******************************************************************************
** Function name:		disable_timer
**
** Descriptions:		Disable timer
**
** parameters:			None
** Returned value:		None
** 
******************************************************************************/
void disable_timer( void )
{
    HSTIM_MCTRL &= ~(1 << 6);	/* Disable Interrupt generation on Match2 */
    HSTIM_CTRL &= ~(1 << 0);	/* Sttop the Timer */
    return;
}

/******************************************************************************
** Function name:		init_timer
**
** Descriptions:		Initialize timer, set timer interval, reset timer,
**				install timer interrupt handler
**
** parameters:			None
** Returned value:		None
** 
******************************************************************************/
void init_timer( void ) 
{
    DWORD reload_value, periph_clk;

    timer_counter = 0;

    TIMCLK_CTRL |= (1 << 1);	/* Enable the High Speed Timer Clock */
    HSTIM_CTRL &= ~(1 << 0);	/* Stop the Timer */
    HSTIM_CTRL |=  (1 << 1);	/* Set the Timer Reset bit, counter to 0x00000000 */
    HSTIM_CTRL &= ~(1 << 1);	/* Clear the Reset bit */

    /* Use timer match 2 as interrupt */ 
    HSTIM_INT |= (1 << 2);	/* Clear match2 interrupt */

    /* Get Peripheral Clock Divider Value, set time out value based PCLK */
    periph_clk = CPU_CLK / (PERIPH_DIV + 1 );
    reload_value = (periph_clk / TIMER_TICKS) - 1;
    HSTIM_MATCH2 = reload_value;	/* reload match2 value */
    
    HSTIM_PCOUNT = 0;		/* Set the Timer Prescaler to 0 */
//    HSTIM_CTRL |= (1 << 2);	/* Timer stops when the CPU is in debug mode */
   
    Install_MIC( 5, INT_HIGH_LEVEL, INT_LEVEL_SENSITIVE, TIMER_ISR );
    Enable_MIC( 5 );
    return;
}

/******************************************************************************
**                            End Of File
******************************************************************************/

⌨️ 快捷键说明

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