这个实验利用avr内部定时器一,通过定时器中断控制led的闪烁.详情见附件
平台:FDRAVR开发板
代码:
#include
interrupt [TIM1_OVF] void timer1_ovf_isr(void)
{
PORTB=~PORTB;//输出取反
TCNT1H=0X80;//重新设定初时值
TCNT1L=0X00;
}
// Declare your global variables here
void main(void)
{
DDRB="0XFF"; //PORTB设置为输出
PORTB="0XFF";
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: 62.500 kHz
// Mode: Normal top="FFFFh"
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: On
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x03;//设置时钟分频
TCNT1H=0x00;
TCNT1L=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK="0x04"; //开启定时器1中断
// Global enable interrupts
#asm("sei") //开全局中断
while (1)
{
// Place your code here
};
}
文章评论(0条评论)
登录后参与讨论