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

📄 drv_timer1.c

📁 Enhanced LPC213x device drivers,tools ADS1.2
💻 C
字号:
#include "config_60_61.h"
#include "include_GD61.h"

/////////////////////////////////////////////////////////////////////////////
void __irq IRQ_Timer1Serving (void);
void Timer1Initialize(void);

void TimeElapseStart(void);
void TimeElapseStop(char *TitlePt);

void DelayUS_(uint32 dly);

/////////////////////////////////////////////////////////////////////////////
void __irq IRQ_Timer1Serving(void)
{
//do something here.
	T1IR 		= 0x01;		/* 清除中断标志		   */
	VICVectAddr = 0x00;		/* 通知VIC中断处理结束 */
}

/////////////////////////////////////////////////////////////////////////////
void Timer1Initialize(void)
{
//定时器1初始化
	T1TC   = 0;					//set timer1 initialization value
	T1PR   = 0;					//pclk output to timer1 directly
	T1MCR  = 0x03;				/* 设置T1MR0匹配后复位T1TC,并产生中断标志	*/
	T1MR0  = LPC_FPCLK/1000;	/* 1/1000秒钟定时							*/
	T1TCR  = 0x01;				/* 启动定时器	ok */

//设置定时器1中断IRQ
	VICVectCntl5 = 0x20|INT_TIMER1;	//enable int vector and assign priority of int.
	VICVectAddr5 = (uint32)IRQ_Timer1Serving;	//assign the address of int handler.
	VICIntEnable = 1<<INT_TIMER1;				//

}

/////////////////////////////////////////////////////////////////////////////
void TimeElapseStart(void)
{
//定时器1初始化
	T1TC   = 0;				//set timer1 initialization value
	T1PR   = 0;				//pclk output to timer1 directly
	T1TCR  = 0x01;			/* 启动定时器 */
}

/////////////////////////////////////////////////////////////////////////////
void TimeElapseStop(char *TitlePt)
{
char dbuffer[100];
uint32 buff;

	T1TCR = 0x00;				/* stop timer1*/
	buff  = T1TC;
	buff  = buff*100/1106 + buff*8/1106/1106;  //11.0592
	sprintf(dbuffer,"%s elapsed time: %d us = %d ms",TitlePt,buff,((buff+500)/1000));
	DB_SendString(dbuffer);
}

/////////////////////////////////////////////////////////////////////////////
void DelayUS_(uint32 dly)
{
volatile uint32 us_buff;
volatile uint32 us_buff1;
volatile uint32 us_buff2;

	us_buff = (dly>=500)? dly:500;
	
	while(us_buff){
		us_buff--;

		us_buff1=12*us_buff;	//dummy operation, only for delay time
		us_buff1++;
		us_buff2=us_buff1;
	}
}


////////////////////////////////////////////////////////////////////////////
// end of file //

⌨️ 快捷键说明

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