Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
larny Guru Joined: 31/10/2011 Location: AustraliaPosts: 346
Posted: 10:55pm 25 Jun 2017
Copy link to clipboard
Print this post
I've successfully written many PIC programmes but this my first time with the 16F684.
I have MPLAB 8.92.
I cannot clear INTCON, 0. This instruction does not anything. bcf INTCON, 0 ;RBIF
If I use this clrf INTCON the INTCON value changes from 0x09 to 0x01. I have tried various tricks but to no avail.
I even uninstalled MPLAB & then re-installed it.
This instruction does clear INTCON, 1
bcf INTCON, 1 ;INTF
I feel that there is a software problem with MPLAB as I can't see any reason why it does not clear INTCON, 0
Any assistance will be appreciated.
CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2170
Posted: 02:08am 26 Jun 2017
Copy link to clipboard
Print this post
16F684? I find no mention of RBIF in the PDF. It doesn't have a PORTB
Do you mean 16F84? ... in which case
What are you trying to do when you clear RBIF?
RBIF is not the interrupt enable flag (RBIE does that) but rather an indicator that the interrupt condition has occurred. It gets set to 1 if any of PORTB 4 to 7 change state since RBIF was cleared. Setting RBIF to zero only clears the current interrupt - it will go to 1 "in the background" so it might be that by the time you check (having set it to 0) something could have flipped it back.
Section 2.3.3 of the PIC16F84 datasheet has a note right at the top saying that interrupt bits will be set by the silicon when the stimuli exist regardless of the enable bits. Check out section 6.8.3 on how to disable the RB change interrupt. Reading from this I quite like that it is possible to manually poll for interrupt stimuli without actually having an interrupt - worth bearing in mind.
What is connected to these 4 bits? Bearing in mind that all PIC pins are input by default, is any of them getting unclean signals or floating and maybe seeing noise which could be setting RBIF? Tie any unused inputs to GND or VCC through 10K resistors or use the weak pull-ups (from the option register) and see if that helps. Have you got a scope you can look at any signals to see if there is crap on them (switch bounce is a doozy if you are using these four bits to scan a keypad)?
hEdited by CaptainBoing 2017-06-27
larny Guru Joined: 31/10/2011 Location: AustraliaPosts: 346
Posted: 12:00pm 26 Jun 2017
Copy link to clipboard
Print this post
Thanks for your suggestions. Someone on another forum reminded me that to clear RAIF, I must first read PORTA. I knew that from the past but had forgotten (it's a couple of years since I last used interrupts). Doing that fixed the issue.
CaptainBoing Guru Joined: 07/09/2016 Location: United KingdomPosts: 2170