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.

how can I use int0 and int1 at a time with atmega8???

Status
Not open for further replies.

Mithun_K_Das

Advanced Member level 3
Advanced Member level 3
Joined
Apr 24, 2010
Messages
899
Helped
24
Reputation
48
Reaction score
26
Trophy points
1,318
Location
Dhaka, Bangladesh, Bangladesh
Activity points
8,254
read this program. its working well with int1. tell me how can I use both int0 & int1??

////////////////////////////////////////////////////////////////////////////////////////

int cnt = 0, cnt2 = 0; // Global variable cnt

void interrupt_ISR () org IVT_ADDR_INT1
{ // Interrupt rutine
SREG_I_bit = 0; // Disable Interrupts
cnt++;
PORTD = cnt; // Increment variable cnt
SREG_I_bit = 1; // Enable Interrupts
}




void interrupt_ISR () org IVT_ADDR_INT0 // Look here. how can I call/enable

intrrupt 1?






{ // Interrupt rutine
SREG_I_bit = 0; // Disable Interrupts
cnt2++;
PORTC = cnt; // Increment variable cnt
SREG_I_bit = 2; // Enable Interrupts
}

void main()
{ // Main program

DDRD = 0b00110011; // Set PD3 as input
DDRB = 0xFF;
DDRC = 0xFF; // Set PortB as output

//PORTD = 0x00;
PORTB = 0xFF; // Starting value for PortD
GICR = 0x80; // Set the Interrupts
MCUCR = 0x08; // Configure Interrupt for falling edge on PortD.3

SREG_I_bit = 1; // Enable Interrupts

while(1)
{ // Unending loop
PORTB = 0xFF;
Delay_ms(10);
PORTB = 0x00;
Delay_ms(10);
// Write on PortB value of varibale cnt
}
}
 

Hi,
Try with this code:
Code:
int cnt = 0, cnt2 = 0; // Global variable cnt

void interrupt_INT1() org IVT_ADDR_INT1
{ // Interrupt rutine
cnt++;
PORTD = cnt; // Increment variable cnt
}

void interrupt_INT0() org IVT_ADDR_INT0
{ // Interrupt rutine
cnt2++;
PORTC = cnt; // Increment variable cnt
}

void main()
{ // Main program

DDRD = 0b00110011; // Set PD3 and PD2 as input
DDRB = 0xFF;
DDRC = 0xFF; // Set PortB as output

//PORTD = 0x00;
PORTB = 0xFF; // Starting value for PortB
GICR = 0xC0; // Set the Interrupts - INT0 and INT1
MCUCR = 0x0A; // Configure Interrupt for falling edge on INT0 and INT1

SREG_I_bit = 1; // Enable Interrupts

while(1)
{ // Unending loop
PORTB = 0xFF;
Delay_ms(10);
PORTB = 0x00;
Delay_ms(10);
// Write on PortB value of varibale cnt
}
}

I think you can understand how I did it. I set the values of GICR and MCUCR. If you read the datasheet and understand, then it should be clear. I also think you can understand how I set the interrupts.

Hope this helps.
Tahmid.
 
It is possible to group interrupts, however I can't remember how it is done, check avr-gcc compiler documentation. Anyway, the controller itself have interrupt priorities, so one, which has higher priority, will interrupt the lower one :)
 

The interrupt priority depends on the location in the interrupt vector table (IVT), so if INT0 and INT1 interrupts occur at exactly the very same moment, INT0 ISR is served first, then INT1 ISR. This, however, won't cause much errors, as the delay will be in the order of a few microseconds (if not nanoseconds) - or atleast it should be, since you should always keep the ISR very short.

Hope this helps.
Tahmid.
 

The ISR can be long enough if other interrupt will interrupt the going one and then it will be back for the previous interrupt routine, just don't disable interrupts inside interrupt :)
 

Yes. Don't disable interrupt in the ISR. I've removed that bit from the code I posted.

Tahmid.
 

Thanks Tahmid. You really done a great help in my learning session. thanks again. its working...

---------- Post added at 17:17 ---------- Previous post was at 17:16 ----------

have you any idea about 'extreme burner' for avr series?
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top