External Interupt on Atmega128

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

Hello guys,

I have tried to use External interrupt on Atmega128. Its a simple program.

I have a switch connected on PORTE4 , INT4, if detect low level turn on LED on PORTA7. Thats all.

I have done it with the below code.It works well. please let me know if this crude,OK, if so how can i make it better.

#include 

main (void)
{
EIMSK |= (1<<PE4);  // Using INT4
EICRB = 0x00;       // want the low level to generate Interrupt
EIMSK |= (1<<INT4);   // enable INT4


  while(1)
   {
   }
}

INT4_vect(SIG_INTERUPT4)
{
PORTA |= (1<<PA7); //if switch pressed ; ON Led on PA7

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

It will not matter with this simple program but in general, a switch has to be debounced. There are several threads about it - search this forum.

/Martin.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
INT4_vect(SIG_INTERUPT4)

That is not valid syntax for avr-gcc. It should read:

ISR(INT4_vect)

(as explained in the user manual)

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

I think the sei(); instruction is missing.
Without that interrupts are disabled (unless the C init code generates that before main() is called.

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

Quote:

unless the C init code generates that before main() is called.

It doesn't you are right.