Getting ExtInt0 to Override ExtInt1
2007-07-20 by Randy Ledyard
Hello
I using a Mega48, coded in ASM. I have debounced switches on PD2 (INT0) and
PD3 (INT1).
In my code, I'm enabling both INT1 and INT0 on a rising edge, and enabling
the global int flag, using something like this:
I have the pins and ports defined in a separate inc file
.cseg
.org 0x00
rjmp RESET
rjmp EXT_INT0
rjmp EXT_INT1
rjmp ERR_01 // PCINT0 ; PCINT0 Handler
// .... rest of isr vectors all point to same address as above
RESET:
INITIALIZE_AVR:
ldi temp, high(RAMEND)
out SPH, temp
ldi temp, low(RAMEND)
out SPL, temp
// set pins for stepper/5804 as outputs
sbi StepDDR, EnablePin
sbi StepDDR, DirPin
sbi StepDDR, StepPin
// set the err LED pin as output
sbi ErrDDR, ErrPin
cbi SwitchDDR, E_SwPin
cbi SwitchDDR, FootSwPin
cbi SwitchDDR, SensorPin
// set default values for pins
StepDown // these are macros
StepLow
EnableOff
ErrPinOff
// set up ext ints 0 & 1
// EICRA has the bits to set the levels of the ints
// we want both INT0 & INT1 to trigger on the rising edge
// for INT0, rising edge, ISC01,ISC00 = 11
// for INT1, rising edge, ISC11_ISC10 = 11
ldi temp, 0b00001111
sts EICRA, temp
// enable INT0 & INT1 => EIMSK - INT0=bit 0, INT1=bit 1
ldi temp, 0b00000011
out EIMSK, temp
sei
// end INIT
MAIN: // inf loop
NOP
rjmp MAIN
EXT_INT1:
// control stepper in here - up/ down stroke
//
// at end of this routine I set the INT1 flag - this way,
// even if the button was accidently pressed twice, it will
// only execute one stroke at a time, and ignores any more
// button presses until the ISR is completed
sbi EIFR, INT1
// end EXT_INT1
EXT_INT0:
// emergency sw was pressed
// blink the emrgency LED
// end EXT_INT0
-- now my question is, how can I get the INT0 switch to IMMEDIATELY
interrupt any code that is running, and go to the EXT_INT0 label and begin
execution the code there? Right now, what's happening is the INT0 waits
until the INT1 routine returns back to MAIN before it jumps to the ISR,
which could be too late....
Randy