在中断中设置OCR寄存器?

时间:2017-01-18 21:48:36

标签: c arduino avr

在ATmega 32u4上我有两个计时器。一个用于测量中断之间的刻度,第二个用于计算刻度数的1/60。我不确定我被允许做什么,如果这是正确的。如果你能告诉我什么是错的,我会很高兴。

void setup(){
    EIMSK |= (1 << INT2); //INT2 enable
    EICRA |= (1 << ISC21) | (1 << ISC20); //INT2 RISING EDGE
    DDRD &= ~(1 << PD2); //PD0 (INT0)(3) as input
    PORTD &= ~(1 << PD2); //PD0 pulldown

    TCCR1B |= (1 << CS11); //prescaler 8
    //TIMER3 - 1/60
    TCCR3A |= (1 << WGM32); //CTC Mode
    TCCR3B |= (1 << CS31); //prescaler 8
    TIMSK3 |= (1 << OCIE3A); //compate interrupt enable
    sei();
}

ISR(INT2_vect) {
    TCNT3 = 0;
    OCR3A = TCNT1 / 60;
    TCNT1 = 0;
    degree = 30;
}

ISR(TIMER3_COMPA_vect) {
    Color * currentColor = &bColor;
    if (degree == 0)
        degree = 59;
    else degree--;
    if (degree == time.second)
        currentColor = &sColor;
    else if (degree == time.minute)
        currentColor = &mColor;
    else if (degree % 5 == 0 && degree / 5 == time.hour)
        currentColor = &hColor;

    //set pwm
    RedReg = currentColor->Red;
    GreenReg = currentColor->Green;
    BlueReg = currentColor->Blue;
}

0 个答案:

没有答案