bitsurfer
Member level 3
- Joined
- Jul 19, 2012
- Messages
- 56
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- Croatia
- Activity points
- 1,734
Hello,
As absolute beginner to AVR microcontrollers I try several examples from net in order to fire interrupt 0 on ATMEGA 32.
I try approach from here:
http://www.avr-tutorials.com/interrupts/avr-external-interrupt-c-programming
But as other examples this one also don't work in my case.
Here is my exact code:
From all my readings that code should work but it don't do a code which is inside ISR(INT0_vect).
Since I haven't debugger I don't know if interrupt is even fired.
Chip is new so maybe something with fuses.
Any idea why this might not work?
As absolute beginner to AVR microcontrollers I try several examples from net in order to fire interrupt 0 on ATMEGA 32.
I try approach from here:
http://www.avr-tutorials.com/interrupts/avr-external-interrupt-c-programming
But as other examples this one also don't work in my case.
Here is my exact code:
Code:
#define F_CPU 7372800
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#define DataPort PORTB
#define DataDDR DDRB
ISR(INT0_vect)
{
unsigned char i;
_delay_ms(500); // because of debouncing
/* This for loop blink LEDs on Dataport 5 times*/
for(i = 0; i < 5; i++)
{
DataPort = 0x00;
_delay_ms(500);
DataPort = 0xFF;
_delay_ms(500);
}
DataPort = 0;
int main(void)
{
DDRD = 1<<PD2; // Set PD2 as input (Using for interupt INT0)
PORTD = 1<<PD2; // Enable PD2 pull-up resistor
cli();
GICR = 1<<INT0; // Enable INT0
MCUCR = 1<<ISC01; // Trigger INT0 on falling edge
sei(); // Enable Global Interrupt
DataDDR = 0xFF; // Configure Dataport as output
DataPort = 0x01; // Initialise Dataport to 1
while(1)
{
if(DataPort >= 0x80)
DataPort = 1;
else
DataPort = (DataPort << 1);
_delay_ms(500);
}
}
From all my readings that code should work but it don't do a code which is inside ISR(INT0_vect).
Since I haven't debugger I don't know if interrupt is even fired.
Chip is new so maybe something with fuses.
Any idea why this might not work?