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 to Reset 8051 Interrupt by NOT Using RETI Instruction?

Status
Not open for further replies.

2:43AM

Junior Member level 1
Joined
Feb 6, 2010
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Midwest USA
Activity points
1,419
For an 8051 microcontroller, is this possible?

My code uses the external interrupt 0 to branch out a main program and go into a lengthy subroutine, then again branching out into an appopriate sub-main program based on values in the accumulator. At this point, the micro is where it should be, running the code as long as it's supposed to. However, I want to have the external interrupt 0 reset and available to branch out again, if required.

The RETI instruction would indeed reset the interrupt and allow the micro to take action for future interrupts. However, placing a RETI anywhere in the subroutine or subsequent sub-main programs would cause the micro to go back to the main program where the Program Counter originally left off. I don't want that!

Is it possible to reset a flag or something to reset an interrupt and allow it to be used again WITHOUT using the RETI instruction?

Thanks for any help!
 

Re: How to Reset 8051 Interrupt by NOT Using RETI Instructio

I am not sure what you are asking.

I think restoring the stack pointer to what you set it at originally (or during startup) should accomplish what you want.

When you are in the ISR and must jump to another routine without the reti instruction, resetting the stack pointer should clear the return address from the stack still allowing the interrupt to occur at a later time.

I had to do this once in a program quite a few years ago, so I cannot remember what else (if anything) I did.

Good Luck
 

Re: How to Reset 8051 Interrupt by NOT Using RETI Instructio

I will try this and let you know how it goes. This sounds promising. :D
 

Re:How to Reset 8051 Interrupt by NOT Using RETI Instruction

ctownsend said:
I think restoring the stack pointer to what you set it at originally (or during startup) should accomplish what you want.

When you are in the ISR and must jump to another routine without the reti instruction, resetting the stack pointer should clear the return address from the stack still allowing the interrupt to occur at a later time.

This is what I need to do. However, I will ask a dumb question. How is this done? :D Do I need to go through a whole PUSH/POP sequence? Initially at startup, the SP was set above the register/bit area (value of 1Bh moved onto SP).

I tried MOV SP, #1Bh after the interrupt-to-subroutine-to-subroutine is complete, but it did not work. Therefore, I imagine it's a little mor complex than this!

After reading the good tutorial on interrupts on 8052.com, it advises to always make sure the ACC and other "R" registers are restored to their previous values BEFORE the interrupt occurs. This makes sense, but in my code, I don't need to know the values of these registers. New values will be moved into them for different purposes.

I'm stuck. :cry:
 

Re: How to Reset 8051 Interrupt by NOT Using RETI Instructio

Anyone? Bueller? Bueller? :?:

Here is a code synopsis of what I'm trying to do:
(assume interrupts are enabled, the stack pointer is set @ 25h)


org 0013h
nop
ljmp EX1_Receive

org 0100h
main:
nop
nop
nop
sjmp main

EX1_Receive:
mov VAR2, #8
Loopy1:
jnb VAR1
mov C, VAR1
rlc A
djnz VAR2, Loopy1
cjne A, #0xFF, Go_There
Run_Program:
nop
nop
sjmp Run_Program

Go_There:
nop;
nop;
sjmp Go_There


Now this is a really crappy interpretation summary of my code. But essentially, I need the micro to respond to the external interrupt, jump to the subroutine to poll bits from the outside world (timing not an issue in this example, obviously), rotate 8 bits through the accumulator, then compare the value of the accumulator to a direct value. Then if it is the same, go to the program code in which the micro is to stay. If not go to the other location and stay. However, in the code locations in which the micro is to stay, it needs to respond to future external interrupts. This is where I am stuck. A RETI instruction will cause the micro to go back to the "main" code, which is long gone...a place where the micro may never visit again!

So what do I need to do? Thanks in advance!
 

Re: How to Reset 8051 Interrupt by NOT Using RETI Instructio

There is no other way than the RETI instruction to tell the microcontroller that an interrupt subroutine is completed ..
Whatever else you do (eg. reducing SP by 2, as in the RET instruction) will cause the illusion of your main program running normally, however, your interrupt will only be executed once ..
You have to use RETI to overcome this issue ..

Try to employ a flag that when set in the ExtInt routine will tell the microcontroller in the “main” code to branch to wherever you want it to go ..
Set those “traps” in the main code as often as you like ..

Rgds,
IanP
:D
 

Re: How to Reset 8051 Interrupt by NOT Using RETI Instructio

Now that I see your code, it is better to go with what IanP suggested.

Next time you post code, please use code tags.
try this:

Code:
Flags       DATA	20h		; 
OKFlag      BIT	Flags.0	; 


;include this at startup

	mov	flags,#0

org 0013h
	nop
	ljmp EX1_Receive

org 0100h
main:
	jnb	OKFlag,main		;wait here until flag set

Run_Prog:
;you can disable interrupt(s) here
;
;....do something here
;
;maybe re-enable interrupt(s) here if needed
	mov	flags,#0		;restore flag 
	sjmp	main	


EX1_Receive:
	mov VAR2, #8
Loopy1:
	jnb VAR1
	mov C, VAR1
	rlc A
	djnz VAR2, Loopy1
	cjne A, #0xFF, Go_There
	sjmp	Go_Back

Go_There:
	setb OKFlag

Go_Back:
	reti
 

Re: How to Reset 8051 Interrupt by NOT Using RETI Instructio



May be you want this:



// Kill interrupt state
IRQ_DESTROY:
RETI

// Code with hi priority but low duration
IRQ:
BLABLA
BLABLA
BLABLA
CALL IRQ_DESTROY

// Code with lo priority but hi duration
JB IRQ_LONG_DUR, EXIT // if this code isn't reentrant
SETB IRQ_LONG_DUR
BLABLA
BLABLA
BLABLA
CLR IRQ_LONG_DUR
EXIT:
RET



Good luck.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top