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

📄 timer.c

📁 nxp的LPC2888处理器的示例代码.
💻 C
字号:
/*****************************************************************************
 *   timer.c: Timer C file for NXP LPC288x Family Microprocessors
 *
 *   Copyright(C) 2007, NXP Semiconductor
 *   All rights reserved.
 *
 *   History
 *   2007.02.01  ver 1.00    Prelimnary version, first Release
 *
******************************************************************************/
#include "LPC288x.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 IRQ_Timer( void )
{
  timer_counter++;		
  /* Clear the timer interrupt */
  T0CLR=0x0;
  return;
}

/******************************************************************************
** Function name:		init_timer
**
** Descriptions:		Timer/Counter 0 initialization
**
**
** parameters:			None
** Returned value:		TRUE or FALSE
** 
******************************************************************************/
DWORD init_timer( DWORD TimeInterval )
{  		
  /* Configure Interrupt Controller 	  */
  if ( install_IRQ(5, 1, IRQ_Timer ) == FALSE )
  {
	return( FALSE );
  }
  INT_REQ5 = (1<<28)|(1<<27)|(1<<26)|(1<<16)|0x1;
  INT_VECTOR0 = IRQ_TABLE_BASE & MASK_INDEX;

  /* Configure Timer0 */
  T0LOAD = TimeInterval;	/* Timer value  */
  T0VALUE = TimeInterval;
  T0CLR = 0;
  T0CTRL=0x48;
  return( TRUE );
}

/******************************************************************************
** Function name:		start_timer
**
** Descriptions:		Start Timer/Counter 0
**
**
** parameters:			None
** Returned value:		None
** 
******************************************************************************/
void start_timer( void )
{
  DWORD regVal;

  timer_counter = 0;  
  /* Enable timer/counter 0 */
  regVal = T0CTRL;
  regVal |= 0x80;
  T0CTRL = regVal;
  return;
}

/******************************************************************************
** Function name:		stop_timer
**
** Descriptions:		Stop Timer/Counter 0
**
**
** parameters:			None
** Returned value:		None
** 
******************************************************************************/
void stop_timer( void )
{
  DWORD regVal;

  /* Disable timer/counter 0 */
  regVal = T0CTRL;
  regVal &= ~0x80;
  T0CTRL = regVal;
  timer_counter = 0;
  return;
}

/*****************************************************************************
** Function name:		delayMs
**
** Descriptions:		Start the timer delay in milo seconds
**						until elapsed
**
** parameters:			Delay value in milo second			 
** 						
** Returned value:		None
** 
*****************************************************************************/
void delayMs(DWORD TimeInterval)
{
  T0LOAD = TimeInterval;	/* Timer value  */
  T0VALUE = TimeInterval;
  T0CLR = 0;
  /* Prescale divided CGU clock / 256, reload enable, counter enable */
  T0CTRL=0xC8;
  
  /* wait until delay time has elapsed or counter reaches zero. */
  while( T0VALUE );
  return;
}

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

⌨️ 快捷键说明

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