IAR FOR AVR 定时器中断的使用
/* 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;
}
}
}
IARAVR定时器中 相关文章:
- IAR For AVR 定时器中断初值计算方法(12-03)
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)