Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me fix AVR interrupt source code in C

Status
Not open for further replies.

david90

Advanced Member level 1
Joined
May 5, 2004
Messages
423
Helped
9
Reputation
18
Reaction score
4
Trophy points
1,298
Activity points
3,611
how come the interrupt source code below doesn't break? Am I missing something? I just want it to inc. var "a" each time there is a change in int pin 4. This is for 2313 btw.
======
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
int a=1,b=0;

INTERRUPT(SIG_INTERRUPT1)
{
a++;
}
void main (void)
{
DDRD=0;

while(1)
{
b=a;
}

}
 

avr interrupt circuit

You must also set the corresponding bits in the peripheral control registers to configure the interrupt system and enable the interrupts.
 

avr interrupt tutorial

why doesn't the result of variable "a" in the interrupt handler get transfer to variable b by the instruction b=a in the main program? variable b always zero as if "a" is never change
 

avr pin change interrupt

what are some ways to debounce a switch using mcu?
 

avr interrupt while interrupt

go for cavr and iccavr compiler then generate automatic cocde generate c code ,then u find the example code. or u get the large sample project in

https://www.avrfreaks.net/
 

avr interrupt break

If using avr-gcc or (Winavr)

1: use SIGNAL instead of INTERRUPT
Signal disables interruppts while you are in the SIGNAL routine , wheras INTERRUPT is interruptable.

2: to make sure the compiler updates the variables , declare them volatile ie. volatile int a=0,b=1;

3: Maybe have a look at www.avrbeginners.net , tehy have som nice intros to the AVR

/Bingo
 

avr+interrupt

referring to the b=a problem
It is better to use pointers instead of globel variables.
It could be a scope / memory stack problem.
 

avr interrupt signal

Would there be a problem if I use a 5 feet wire to connect a signal from the avr pin to other digital circuit? Is there a limit to how long the wire can be?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top