新闻中心

EEPW首页>嵌入式系统>设计应用> IAR FOR AVR 定时器中断的使用

IAR FOR AVR 定时器中断的使用

作者: 时间:2016-12-03 来源:网络 收藏
首先看下在iar 里面 iom16.h里面的中断向量表

/* NB! vectors are specified as byte addresses */

本文引用地址://m.amcfsurvey.com/article/201612/325106.htm

#define RESET_vect (0x00)
#define INT0_vect (0x04)
#define INT1_vect (0x08)
#define TIMER2_COMP_vect (0x0C)
#define TIMER2_OVF_vect (0x10)
#define TIMER1_CAPT_vect (0x14)
#define TIMER1_COMPA_vect (0x18)
#define TIMER1_COMPB_vect (0x1C)
#define TIMER1_OVF_vect (0x20)
#define TIMER0_OVF_vect (0x24)
#define SPI_STC_vect (0x28)
#define USART_RXC_vect (0x2C)
#define USART_UDRE_vect (0x30)
#define USART_TXC_vect (0x34)
#define ADC_vect (0x38)
#define EE_RDY_vect (0x3C)
#define ANA_COMP_vect (0x40)
#define TWI_vect (0x44)
#define INT2_vect (0x48)
#define TIMER0_COMP_vect (0x4C)
#define SPM_RDY_vect (0x50)

然后我是用的atmega164mhz晶振

源程序:

#include

char flag=0;

void timer_init() // 中断初始化
{
TCCR1B = 0x04;

TCNT1H = 0xc2;
TCNT1L = 0xf6;

TIMSK_Bit2 = 1; //定时器中断屏蔽寄存器
SREG_Bit7 = 1; // 总中断
}

# pragma vector = TIMER1_OVF_vect
__interruptvoid timer1(void)
{
TCNT1H = 0xc2;
TCNT1L = 0xf6;
flag=1;
}

void main(void)
{
timer_init();
DDRB_Bit1 = 1;
while(1)
{
if(flag==1)
{
PORTB_Bit1 = ~PORTB_Bit1;
flag = 0;
}
}
}



关键词:IARAVR定时器中

评论


技术专区

关闭