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

📄 timer.c

📁 基于2410的一个iis总线测试程序 声音控制芯片是飞利浦的UTS1341 可通过xmodem发送声音文件(WAV)到内存
💻 C
字号:
//==========================
//file:timer.c
//Discription:include some method used by the monitor program
//Author: Decell.Zhou
//Versions:
//=========================
#include "timer.h"

#define ENTER_CRITICAL() SET_IF()

#define EXIT_CRITICAL() CLR_IF()

static char timerCount = 0;
			

//============[ISR_timer0]=======
//Discription: the ISR for the timer0
//Pram: none
//return:none
//version
//===============================

static void __irq ISR_timer0(void){
	rSRCPND = (0x1 << 10);//clear the interrupt
	rINTPND = (0x1 << 10);
	if(timerCount == 0){
		timerCount = 0;
	}else{
		timerCount--;
	}
	
}

//============[timerInit]=======
//Discription: this method is used to initial the timer
//Pram: none
//return:none
//version:
//==============================
void timerInit(void){
	//timer setting:
	//PCLK = 135428571Hz / 4 = 3.3857143MHz
	//divider = 4
	//prescale = 255
	//timer count = 33064
	//timer interval = 33064*(1/(66500000/4/256)) = 1.000012 sec
	
	//first,setting the right clock , the right prescale and divied value
	ChangeMPllValue(0x96,0x5,0x1);    // FCLK=136MHz
	rTCFG0 |= (0xff<<0);	//prescale = 255
	rTCFG1 |= (0x1<<0); 	//divider = 4
	//second,setting the right TCNT, enable the auto reload, enable manual update
	rTCNTB0 = 0x8128;	//TCNTB = 64942
	rTCON |= (0x1<<1)|(0x1<<3);	//manual update on,autoreload on
	//third, install the isr for the timer
#ifdef	NOR_BOOT
	pISR_TIMER0 = (int)ISR_timer0 + 0x30000000;
#else
	pISR_TIMER0 = (int)ISR_timer0;
#endif
	
	//at last,change the uart setting because we change the PCLK
	Uart_Init(33857142,115200);

}

//============[timerStart]======
//Discription: this method is used to start the timer
//Pram: none
//return: none
//version: none
//==============================
void timerStart(void){
	//clear the timer gobal varible
	timerCount = 0;
	//enable the timer int mask
	rINTMSK &= ~(0x1<<10);// enable the timer0 interrupt
	//disable the manual update,turn on the timer
	rTCON &= ~(0x1<<1);//disable the timer
	rTCON |= (0x1<<0);//turn on the timer;
}

//============[timerStop]======
//Discription: this method is used to stop the timer
//Pram: none
//return: none
//version: none
//==============================
void timerStop(void){
	//turn off the timer
	rTCON &= ~(0x1<<0);
	//disable the timer0 interrput
	rINTMSK |= (0x1<<10); 
	

}

//============[setTimer]========
//Discription: this method is used to setup the timeout count for the timer
//Pram: 
//		int|second|the time out time is defined in second
//return:none
//==============================
void setTimer(int second){
	ENTER_CRITICAL();
	timerCount = second;
	EXIT_CRITICAL();
}

//============[timerExpire]=====
//Discription: this method checks to see if the timer has timeout
//Pram: none
//return:
//		0|do not timeout
//		1|has been timeout
//==============================
char timerExpire(void){
	if(timerCount == 0){
		return 1;
	}else{
		return 0;
	}
}


⌨️ 快捷键说明

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