#include "Timer.h"

#include "Include.h"

#include "Usart.h"

uint8_t usart_test_dat[5] = {0x11,0x22,0x33,0x44,0x55};
uint8_t usart_test_len = 5;

uint8_t tim_cnt = 0;
uint8_t tim_flag = 0;


void Tim2Init(void)
{
	TIM_TimeBaseInitTypeDef   TIM_TimeBaseInitStruct;
	NVIC_InitTypeDef          NVIC_InitStruct;
	
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
	
	TIM_DeInit(TIM2);
	TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
	TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_TimeBaseInitStruct.TIM_Period = 249;
	TIM_TimeBaseInitStruct.TIM_Prescaler = 8399;
	TIM_TimeBaseInit(TIM2, &TIM_TimeBaseInitStruct);
	
	NVIC_InitStruct.NVIC_IRQChannel = TIM2_IRQn;
	NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
	NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 5;
	NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
	NVIC_Init(&NVIC_InitStruct);
	

	TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
	TIM_Cmd(TIM2, ENABLE);//¿ªÆô¶¨Ê±50ms
}

void TIM2_IRQHandler(void)
{
	if(RESET != TIM_GetITStatus(TIM2, TIM_IT_Update))
  {
		TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
	
		tim_flag = 1;
		
		tim_cnt++;
		
		if(tim_cnt == 10)
		{
			GPIO_ToggleBits(GPIOE, GPIO_Pin_2);
		}
		
		//TIM_Cmd(TIM2, DISABLE);
	}		
}


