【ATmega4809 Curiosity Nano测评】定时器
<div class='showpostmsg'><p>ATmega4809 的定时器与普通的AVR类似,但是功能增加了许多,用法也更加复杂了。</p><p> </p>
<p>下面的程序使用TCA的普通模式,当定时器溢出后产生中断,在中断里翻转LED。</p>
<p> </p>
<pre>
<code class="language-cpp">#define F_CPU 20000000L/6
#include <xc.h>
#include <avr/interrupt.h>
SIGNAL(TCA0_OVF_vect)
{
TCA0.SINGLE.INTFLAGS |= (1<<0);
PORTF.OUTTGL |= (1<<5);
}
int main(void) {
// PF5 as LED
PORTF.DIR |= (1<<5);
//TCC0
// NORMAL mode
TCA0.SINGLE.CTRLB = 0;
// DIV1024
TCA0.SINGLE.CTRLA |= (7<<1) | (1<<0);
// OVF interrupt
TCA0.SINGLE.INTCTRL = (1<<0);
TCA0.SINGLE.PER = F_CPU/1024;
// enable interrupt
sei();
while(1)
{
}
return 0;
}
</code></pre>
<p><br />
<br />
<br />
<b><font color="#5E7384">此内容由EEWORLD论坛网友<font size="3">dcexpert</font>原创,如需转载或用于商业用途需征得作者同意并注明出处</font></b></p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script>
页:
[1]