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.

automatically interrupt without press the button

Status
Not open for further replies.

PA3040

Advanced Member level 3
Advanced Member level 3
Joined
Aug 1, 2011
Messages
883
Helped
43
Reputation
88
Reaction score
43
Trophy points
1,308
Activity points
6,936
Dear All
MCU 16f877a
my requirement is to study interrupt, therefore I connected switch to the portb pin 4
so i configured portb change interrupt

BSF INTCON, GIE
BSF INTCON, RBIE

and also sets

BCF OPTION_REG,RBPU

so i simulated with Proteus.
when I enable the pullup, it automatically interrupt without press the button

Please advice
 

Hi,

You have two types of interrupt on PortB.

RB0 has the INT interrupt that will do so on either the rising or falling edge of a signal

RB4-7 has the Interrupt on Change feature so just one or all four pins can be compared for any change of state and create an interrupt.

As well as setting up and enabling each type of interrupt RB0 or RB4-7 you must set up your ISR.

See the 877A .template file in MPasm and also the 877A datasheet for details of how to do that.

Interesting to see that you have come back to Assembler, thought you were going along with C .. ?
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
i configured portb change interrupt

BSF INTCON, GIE
BSF INTCON, RBIE
BCF OPTION_REG,RBPU

so i simulated with Proteus.
when I enable the pullup, it automatically interrupt without press the button

Hi;

It is due the wrong order.

First set the used PORTB pin(s) as input via TRISB
then clear RBPU to enable pullups
then read PORTB once to clear mismatch condition
then clear RBIF (on change it flag)
then set RBIE to enable on change it
finally, only now set GIE (enable global interrupts)

zuisti
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Hi wp 100
After long time you replied to me
Thanks lot for reply
May I asked a small question?

Does effect the portb change when RBPU Enable ?

Please advice

- - - Updated - - -

Dear suisti
Thanks again and again for reply

I will check as you advised

Thanks
 

Hi wp 100
After long time you replied to me
Thanks lot for reply
May I asked a small question?

Does effect the portb change when RBPU Enable ?

Please advice



Hi,

No, had not avoided you, it was that I saw some of your recent posts were in C.
As I only do assembler did not think I could offer any help to your C posts, seems you have come back to assembler ..

RBPU should not affect the Interrupt on Change, its just like having weak external pull up resistors.
Its bCf to turn them On.

When you do the Interrupt on Change it compares the current state to the previous state, you might find it useful to read the port just before you enable the interrupts. movf PORTB,W
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
...
RBPU should not affect the Interrupt on Change
...
No, I do not agree with this. I think that if the pullups are enabled after the interrupt "arming" (as PA3040 did it), then it really may cause interrupt, if (because of) the PORTB pins (may) have changed.
Follow the method what I wrote above.
 
  • Like
Reactions: PA3040

    PA3040

    Points: 2
    Helpful Answer Positive Rating
Dear Zuisti,

Thanks lot for help
My problem is solved, by advice you and wp100 and others

Thanks again and again
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top