我正在尝试计算我对按钮的点击次数(Coun 并在 4 个 LED 上模拟它,它必须计数到 9,然后 TCNT0 等于 OCR0 ,所以中断被触发,TCNT0 再次变为零,依此类推。但它在 9 后继续直到255 . 未设置输出比较匹配标志。(不发生比较匹配)。
ISR(TIMER0_COMP_vect){
}
int main(){
DDRC=0xff; //configure PORTC leds
CLEAR_BIT(DDRB,0); //configure T0 Pin as input
SET_BIT(PORTB,0); //enable internal PULL-UP resistance
TCCR0 = 0x4E; //Counter mode(falling edge),CTC mode .
TCNT0=0; //timer register initial value
OCR0=9; //set MAX value as 9
SET_BIT(TIMSK,OCIE0); //Enable On compare interrupt
SET_BIT(SREG,7); //Enable All-interrupts
while (1){
PORTC=TCNT0; //Let Leds simulates the value of TCNT0
}
}