首要看下在iar 里边 iom16.h里边的中止向量表
/* NB! vectors are specified as byte addresses */
#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)
然后我是用的atmega16 4mhz晶振
源程序:
#include
char flag=0;
void timer_init() // 中止初始化
{
TCCR1B = 0x04;
TCNT1H = 0xc2;
TCNT1L = 0xf6;
TIMSK_Bit2 = 1; // 定时器中止屏蔽寄存器
SREG_Bit7 = 1; // 总中止
}
# pragma vector = TIMER1_OVF_vect
__interrupt void 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;
}
}
}