Society of Robots - Robot Forum
Software => Software => Topic started by: ramjam89 on September 28, 2009, 02:21:42 PM
-
Hey guys, I am in dire need of a simple hardware interrupt example, i've done my research all to no avail. I know it isn't that difficult, but all i need is kick start... so please, if anyone of you can take the time and help me with my interrupt quandary, i'll appreciate it (BIG TIME). I am using the Atmega 8, using interrupt pin INT1 (aka PD3). Here's what i am trying to do, i have a switch connected to the PD3 pin, and i want to program the atmega8 in a way where when i press the switch (transition from 0 to 1), it turns the LED on (which is connected to an output pin). so far the LED is working perfectly with polling, however i want to learn how hardware interrupts work. i am not sure of the declaration of the interrupt per se, nor am i sure of the global declarations that need to be done. here's a sample of my program:
ISR(INT1_vect)
{
while ((PIND & _BV(PD3))) == 1)
LED_on();
}
Any help will be greatly appreciated.
-
You cannot connect a switch directly to a an external interrupt. Bouncing will cause many problems. If you don't know what bouncing is, take a look at http://www.ganssle.com/debouncing.pdf (http://www.ganssle.com/debouncing.pdf)
Now for the software part, here is the main steps:
- configure INT1 (choose the type of trigger, ...)
- enable INT1
- enable interrupts
Your main source of information for this is the datasheet of your micro-controller.
Chelmi.
-
Hey Chelmi, thanks for the quick reply, much appreciated. I figured it out from the datasheet and it worked perfectly. of course to fix the debouncing problem i had to put a delay function, which worked quite well. Thanks anyway.
Cheers