蓝牙4.0开发之CC2541定时器使用

unsigned short timer_count = 0;

void timer1_init(void)
{
	T1CTL = 0x00;
    T1CTL |= 0xEB; // Set T3 control register: SysClk/32, enable interrupt, run in module mode
	T1CNTL = 0x00; //复位计数器
	T1CCTL0 &= ~0x04;
	T1CC0L = 0xe8;  //计时到1000中断
	T1CC0H = 0x03;
    IEN1 |= (1<<1); // register timer 1 interrupt
}

void timer1_start_free(void)
{
	T1CTL |= 0x01;
}

void timer1_start_module(void)
{
	T1CTL |= 0x02;
}

void timer1_start_eachside(void)
{
	T1CTL |= 0x03;
}

void timer1_stop(void)
{
	T1CTL &= ~0x03;

}
static bool test_led= 0;
_PRAGMA (vector=T1_VECTOR)

__interrupt void T1_ISR (void)

{

	
	if(timer_count > 1000)
	{
		timer_count = 0;
		test_led = !test_led;
		HalLedSet(HAL_LED_1,test_led);
	}
	timer_count++;
  // clear interrupt flag
	IRCON &= ~0x02;

}


你可能感兴趣的:(蓝牙4.0开发)