为什么进不了中断?
void main(void) { porta_init(); TC1_init(1000); sei(); for(;;) { //delay(100000); PORTA ^= 0X00; asm("nop"); } }
void TC1_init(int time_ms) //初始化,可以按毫秒输入定时周期 { TCCR1B |= CLK_8; //时钟源8分频 asm("nop"); int TCNT_value = Change_time(time_ms); TIM16_WriteTCNT1(TCNT_value); //写16位寄存器 TIMSK|=(1<<TOIE1); //允许T1溢出中断 }
////////////////////////////////////////////// int Change_time(int i) { char tcc = TCCR1B |=0x07; switch( tcc ) { case CLK_1 : return(CLK_IO_HZ * i); break; case CLK_8 : return(CLK_IO_HZ * i*8); break; case CLK_64 : return(CLK_IO_HZ * i*64); break; case CLK_256 : return(CLK_IO_HZ * i*256); break; case CLK_1024: return(CLK_IO_HZ * i*1024); break; } } /////////////////////////
void porta_init(void) { DDRA |= 0XFF; PORTA = 0XFF; }
SIGNAL(SIG_OVERFLOW1)//定时器1中断 { TC1_init(500); PORTA ^= 0XFF; //sei(); } // void TIM16_WriteTCNT1( unsigned int i ) { unsigned char sreg; sreg = SREG; //cli(); TCNT1 = i; SREG = sreg; }
|