dsPIC33EP timer1 初始化设置及应用

//文件 p33timer1.h

#ifndef _P33TIMER1_H_
#define _P33TIMER1_H_
//#include "p33timer1.h"

#define		TIMER1_IEN_ENB	_T1IE = 1
#define		TIMER1_IEN_DIS	_T1IE = 0

//timer1输入时钟分频
#define		TIMER1_DIV1		(0<<4)
#define		TIMER1_DIV8		(1<<4)
#define		TIMER1_DIV64	(2<<4)
#define		TIMER1_DIV256	(3<<4)


//=========================================
extern void Init_Timer1(uint16 T1div,uint16 Tcon) ;

#endif



//文件 p33timer1.c

#include "global.h"
#include "p33timer1.h"

//***************************************
// 函数名称:Init_Timer1
// 函数功能:初始化timer1
// 入口参数:时钟分频系数 定时器计数个数
// 出口参数:无
// 返回值:无
// Timer1 的时钟源 = Fp(即外设时钟)
//***************************************
void Init_Timer1(uint16 T1div,uint16 Tcon)
{
	T1CON = 0X0000|T1div ;
	PR1 = Tcon ; //重装载寄存器
	TMR1 = 0x0000 ; //计数器
	_T1IF = 0 ;
	_T1IE = 0 ;
	T1CON |= (1<<15) ; //开启定时器1	
}

//应用实例

void main(void)
{
	
	//外设时钟64分频到时钟 计数3599次 
	Init_Timer1(TIMER1_DIV64,3599) ;// 
	TIMER1_IEN_ENB ; //开启定时器中断
//	TIMER1_IEN_DIS ;

	while(1)
	{

	}
	

}


posted on 2013-10-30 21:57  新一  阅读(582)  评论(0)    收藏  举报

导航