Need help configuring INT0 and INT1 in C

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I would like to trigger interrupts from IR detection on INT0 and INT1 using PD2 and PD3 on a ATMega88.

+5v
|
10k
|
--------------PD2/PD3
|
phototransistor
|
GND

I've been going through the datasheets, but an still lost on how to actually do this in the code. From my understanding, I will need to set the EIMSK -> 1 for INT0 and INT1, set SREG -> 1, and set EICRA values for the proper edge detection. At this point, I am kind of stuck.

Can someone help work me through the coding? Thank you.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I will need to set the EIMSK -> 1 for INT0 and INT1, set SREG -> 1, and set EICRA values for the proper edge detection.

To be clear, you need to set the INT0 and INT1 bits in EIMSK to 1. With SREG you need to set the I bit to 1, which is most easily done with "sei()".

Quote:
At this point, I am kind of stuck.

The only thing left to do is set up the interrupt service routines. You will need one for both INT0 and INT1:

ISR(INT0_vect)
{
    // Your INT0 code here
}

ISR(INT1_vect)
{
    // Your INT1 code here
}

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks