hi, i want to use TImer 2 in the CTC mode to toggle the OC2B pin, so when its toggled, i will use the External Interrupt INT1 to turn on/off the LED. But the LED doesnt change, can anyone tell me why?
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
volatile boolean flag = false;
int main(void){
DDRD &= ~(1 << DDD3) ; //clear PD3 for interrupt 1
DDRB |= (1 << DDB0); //set PB0 for the LED
EICRA |= (1 << ISC01);
EIMSK |= (1 << INT1); //turn on TNT1
PORTB &= ~(1<<PORTB0);
TCCR2B |= (1 << WGM21) | (1 << CS20) | (1 << CS21) | (1 << CS22); //turn on CTC mode and set the prescaler 1024
TIMSK2 |= (1 << OCIE2A);
OCR2B = 99;
sei(); //turn on global enbal interrupt bit
while(1){}
}
ISR(TIMER2_COMPB_vect) {
PORTD ^= (1 << PORTD3);
flag = true;
}
ISR(INT1_vect){
sei();
if (flag) {
PORTB |= (1 << PORTB0);
_delay_ms(1000);
PORTB &= ~(1 << PORTB0);
_delay_ms(1000);
flag = false;
}
}
Your code is very creative, perfect example how to not use interrupts.
Did you connect the PWM pin to the INT1 pin? If not then nothing will happen. But if you did so you most probably run into a stack overflow with infinite calls of the INT1 interrupt handler.
For further assistance please explain what you really want to achieve or demonstrate.
wait? I did the homework. I got stuck so I just need some help. I'm sorry if my lack of knowledge annoys you, i don't want you to do my homework for me. I need some advice from seniors who have more knowledge than me, not mockery (obviously). Thanks anw
Arduino compiler convention uses setup() and loop(), and _delay_ms(x) is generally delay(x), suggesting to me you're not using a compiler linked to / packaged with the Arduino IDE. Doesn't matter, I don't think your question is out of place or anything.
What kind of board & microcontroller are you writing this for?