1
Hello! I’m working with Atmega1280, just started. I don’t know how to use the interrupt. I want to read the state of a pin (PIN 7) and count the time it remained HIGH and then print it. The input signal is a PWM.
// Pin change 0-7 interrupt service routine
//PORTA=(0<<PORTA7)
//TCCR0B=(0<<WGM02) | (0<<CS02) | (0<<CS01) | (1<<CS00);
//TIMSK0=(0<<OCIE0B) | (0<<OCIE0A) | (1<<TOIE0);
//PCMSK0=(1<<PCINT7)
interrupt[PC_INT0] void pin_change_isr0(void)
{
if (PINB & (1 << PINB7)) {
TIMSK0 = (0 << OCIE0B) | (0 << OCIE0A) | (1 << TOIE0); //HABILITA O TIMER
escreve_USB("HIGH");
escreve_USB("\r\n");
}
if (!(PINB & (1 << PINB7))) {
TIMSK0 = (0 << OCIE0B) | (0 << OCIE0A) | (0 << TOIE0); //DESABILITA O TIMER
escreve_USB("LOW");
escreve_USB("\r\n");
ftoa(TCNT0, 4, ton_acel);
escreve_USB(ton_acel);
}
}
// Timer 0 overflow interrupt service routine
interrupt[TIM0_OVF] void timer0_ovf_isr(void)
{
// Reinitialize Timer 0 value
TCNT0 = 0xF9;
}
Bound