首页 > 代码库 > 中颖TIM4定时初始化

中颖TIM4定时初始化

//==timer4 define=====
#define		TIM4_DIV1 	 	0X00
#define		TIM4_DIV8		0X01
#define		TIM4_DIV64  		0X02
#define		TIM4_DIV256		0X03

#define		Timer4_Cnt_Enb 		Bank1;T4CON |= (1<<1) //允许计数
#define		Timer4_Cnt_Dis 		Bank1;T4CON &= ~(1<<1)  

#define		Timer4_IEN_Enb 		Bank0;IEN1 |= (1<<1) //中断使能
#define		Timer4_IEN_Dis 		Bank0;IEN1 &= ~(1<<1) 

#define		TIMER4_ENB	   1
#define		TIMER4_DIS	   0

void Init_Timer4(uint16 Tcon,uint8 Pscr)
{
	Bank1;
	T4CON = 0X00 ;
	T4CON |= (Pscr<<4) ;

	TL4 = (65536-Tcon)%256 ;
	TH4 = (65536-Tcon)/256 ;//初始化计数器值

	SWTHL &= ~(1<<1) ; //读TH4 TL4时返回 它的计数值
	Bank0;

}

void Timer4_Enb(uint8 EN)
{
	if(EN == TIMER4_ENB)
	{
		Bank1;
		T4CON |= (1<<1) ; //开T4计数
		Bank0;
		IEN1 |= (1<<6) ; //开T4中断
	}
	else 
	{
		Bank1;
		T4CON &= ~(1<<1) ; 
		Bank0;
		IEN1 &= ~(1<<6) ;
	}
}
//系统时钟12M 定时100us 的中断
Init_Timer4(1200,TIM4_DIV1);
Timer4_Enb(TIMER4_ENB);