/*Copyright (C), 2024-2030
*文件名:	USER.c
*版  本:	Ver1.00
*日  期:	2025/04/30
*描  述:	常用函数定义
*备  注:     
**********************************************************/
#include "USER.h"
#include "BL51F003T.h"		
#include "main.h"

/**********************************************************/
/**
	* @brief  timer2重载模式0初始化
  * @param  None
  * @retval None
	*/
void timer2_reload_mode0(void)
{
	T2CL = (65536 - 2250);    	 //83.33us = 1/27M*2250
	T2CH = (65536 - 2250) >> 8;  
	TL2 = T2CL;
	TH2 = T2CH;

	T2MOD = T2IE + T2CS;				//T2中断使能+系统时钟
	T2CON = 0x08;								//T2EX使能信号+重载功能
	TR2 = 1;										//T2启动信号
}
/**
	* @brief  timer2重载模式1初始化
  * @param  None
  * @retval None
	*/
void timer2_reload_mode1(void)
{
	T2CL = 0x00;   								
	T2CH = 0x00;
	TL2 = T2CL;
	TH2 = T2CH;
	
	T2MOD = DCEN + T2IE + T2CS;	//重载模式1使能+T2中断使能+系统时钟
	T2CON = 0x40;								//做计时器低17位
	TR2 = 1;										//T2启动信号
}
/**
	* @brief  timer2中断服务
  * @param  None
  * @retval None
	*/
void timer2_isr (void) interrupt 5  
{
#if (TIMER2_RELOAD_MODE == 0)  
	if(TF2 == 1)	//TIME2溢出标志
	{		
		TF2 = 0;
		P03_REV;
	}	
	if(EXF2 == 1) //TIME2触发标志 
	{
		EXF2 = 0;
		P02_REV;
	} 
#elif (TIMER2_RELOAD_MODE == 1) 
	if(TF2 == 1)	//TIME2溢出标志
	{ 
		TF2 = 0;
		P03_REV;
		
		if(EXF2 == 0) //计数器第17位
		{
			P02_REV;
		}
	}
#endif
}


