ATxmega程序c语言,转:ATxmega入门之四:ATxmage定时器模块介绍

比如我们需要实现一个1ms的定时器中断功能:

void TC1_Init(void)

{

// Unmask clock for TCC1

tc_enable(&TCC1);

// Enable overflow interrupt

tc_set_overflow_interrupt_level(&TCC1, TC_INT_LVL_LO);

// Configure TC in normal mode

tc_set_wgm(&TCC1, TC_WG_NORMAL);

// Configure call back interrupt

tc_set_overflow_interrupt_callback(&TCC1,

ceb_ovf_interrupt_callback);

// Configure TC period and and resolution

tc_write_period(&TCC1, sysclk_get_main_hz()/1000);

tc_set_resolution(&TCC1, sysclk_get_main_hz());

}

上述就是初始化定时器的过程,tc_enable使能定时器模块,这里使用定时器的TCC1模块;tc_set_overflow_interrupt_level使能定时器溢出中断,和设置定时器溢出中断优先级;tc_set_wgm设置定时器为正常模式,由于定时器有多种操作模式;简单理解就是从0计数到设置的周期值,发生溢出中断,在下一个时钟周期计数器变为0;tc_set_overflow_interrupt_callback设置溢出中断回调函数,当溢出中断时,系统会调用ceb_ovf_interrupt_callback这个回调函数;tc_write_period设置定时器周期;tc_set_resolution设置定时器时钟分频;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值