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.

89S51 Interrupt problem. Please Help

Status
Not open for further replies.

joajas

Junior Member level 1
Joined
Jul 17, 2004
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
176
When I run the code on the actual hardware. The controller interrupt always trigger twice when I press the interrupt trigger button once, or when I do a hardware reset. Below is the code. Please advice how I can overcome this problem, thanks.

I am using a Atmel 89S51 controller with some leds and couple of push buttons.


#include <sfr51.inc>

ORG 0000H
LJMP MAIN

ORG 0100H
MAIN: SETB EA ;ENABLE EXTERNAL INTERRUPT 0 AND INTERRUPT 1
SETB EX1
SETB IT0 ;SET TO EDGE TRIGGERED (NEGATIVE EDGE)
SETB IT1 ;SET TO EDGE TRIGGERED (NEGATIVE EDGE)

HERE: LJMP HERE

EX0_ISR: MOV P2,#FFH
LCALL DELAY
CLR P2.2
LCALL DELAY
CLR P2.3
LCALL DELAY
CLR P2.4
LCALL DELAY
RET


DELAY: MOV TMOD,#10H
MOV R0,#1EH

NEXT: MOV TH1,#B1H
MOV TL1,#E0H
SETB TR1

WAIT1: JNB TF1, WAIT1
CLR TR1
CLR TF1
DJNZ R0, NEXT
RET

ORG 0013H
LCALL EX0_ISR
RETI
END
 

Your button's contacts bouncing during the transition?

Probably this is reason...
 

It is not clear whether this push button is conneted directly to the input pin of the interrupt or through some kind of SR bistable logic. The problem with direct connect might be that when you push the button the input logic of the interrupt may "see" more than one negative edge (Prell-effect).
From the code I could not understand how you figure out that your interrupt runs twice at every press of the button. The interrupt clears 3 bits of port 2 each one after the other placing delays between them. But how sets these pins back?
You also enable INT1, but I could not see any code for it. If somehow this interrupt is also triggered than God knows what is execute. Some portion of the INT0, I guess. This might seen by you as running the Int0 twice. If you want somebody help you more than please be more specific about your HW.

Belsugului
 

The button for reset is connected direct to the reset pin of the controller, the button for interrupt is connected to int0 pin. Both button allows me to toggle between a logic 1 and a logic 0.

int1 is enabled for future use, i have not written the code for that yet.

I used leds to help me determine how the controller handles my code. Sort of indicator where it tells me when I push the int trigger button I should see the leds going off one after another.

Therefore in my case, when ever I push the reset button or the int trigger button, the leds goes off one after another, after all leds goes off, immediately they will all light up and goes off one after another again. This is how I determined that the int was triggered twice.

Please advice thanks
 

I tried that code on 87C51 but it didn't work at all.
So I changed the code by adding timer1 interrupt and timer1 interrupt priority=1, and now this code works correctly..
Here it is:
ORG 0000H
LJMP MAIN
ORG 0003H
LCALL EX0_ISR
RETI
ORG 001BH
RETI

ORG 0100H
MAIN: SETB EA ;ENABLE EXTERNAL INTERRUPT 0 AND INTERRUPT 1
SETB EX0
SETB ET1
SETB IT0 ;SET TO EDGE TRIGGERED (NEGATIVE EDGE)
;SETB IT1 ;SET TO EDGE TRIGGERED (NEGATIVE EDGE)
SETB PT1

HERE: LJMP HERE

EX0_ISR: MOV P2,#0FFH
LCALL DELAY
CLR P2.2
LCALL DELAY
CLR P2.3
LCALL DELAY
CLR P2.4
LCALL DELAY
RET

DELAY: MOV TMOD,#10H
MOV R0,#1Eh

NEXT: MOV TH1,#0B1H
MOV TL1,#0E0H
SETB TR1

WAIT1: JNB TF1, $
CLR TR1
CLR TF1
DJNZ R0, NEXT
RET

END

Good luck and regards ..
IanP
 

Salam ;


i think it's better to use a short delay ( 10mlS ) after each interrupt for checking that the interrupt is true not noise , you can do it by disabling EX0 after interrupt ( during interrupt routin ) then call delay for 10mlS and check input pin for being 0 , then do what you wamt , and don't remember to enable interrupt before RETI instruction .this is done mostly when a swich is connected to the pin ,because of bounce and rebounce function of a key .

regards.
 

maybe there's many bounce when u press ur button. so the bounce trigger ur micros more then once
 

Thanks for all suggestions. So how do I make sure that I eliminated the chance of microcontroller being trigger twice due to the button's behavior? Or how should I connect my button to the controller, directly to the pin or with something in between? Please advice, thanks
 

If you have edge triggered interrupt then the best is to use an RS flip-flop between your button and the INT0 pin (that surely will eliminate any problem regarding multiple edges with only one push). Then from the interrupt subrutin you can reset your RS flip-flop. The problem might be here that while you are still pushing teh reset button the interrupt subrutine is already executed, so it will try to reset, while you are setting the RS flip-flop.
Another solution could be tu use a gate with smith trigger. Although this might not be as good as an RS flip-flop you do not need to change its status from subrutine.
I also mentioned that it is not good at all, thet you enable an interrupt without having a subrutine written for it. If a noise triggers the other interrupt, then will be executed even if you did not written a code for it. That means you have an entry point for the interrupt subrutine, end from there the opcodes will be executed. Looking to your code, that means that some portion of the INT0 code will be executed. If somehow when you push the button the INT1 is triggered as well, then this couse to see you your interrupt is executed twice.

Belsugului
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top