Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 05:55 06 May 2024 Privacy Policy
Jump to

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.

Forum Index : Microcontroller and PC projects : Problem with MPLAB

Author Message
larny
Guru

Joined: 31/10/2011
Location: Australia
Posts: 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 Kingdom
Posts: 1985
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: Australia
Posts: 346
Posted: 12:00pm 26 Jun 2017
Copy link to clipboard 
Print this post

  CaptainBoing said   16F684? I find no mention of RBIF in the PDF. It doesn't have a PORTB Sorry, I meant the RAIF not RBIF

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. I normally do that rather than have an interrupt. Then you don't need an ISR. But I need one in this case.

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? I'm simulating it in MPLAB at the moment. I have not yet constructed the hardware. 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. Yes, I'm well aware of the need to tie unused inputs high or low. I've done a lot of CMOS logic design before PICs became available. 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)?
There is only one switch & I'll account for the contact bounce in the software so it will only interrupt once at each switch change i.e. when it closes & later when it opens. Any bounce will be prevented by clearing RAIE as soon as a contact change is detected.

h


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 Kingdom
Posts: 1985
Posted: 07:19pm 26 Jun 2017
Copy link to clipboard 
Print this post

glad you got it sorted.

have fun
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024