PDA

View Full Version : @ Sleep Usage & Need to Read PortB



Zebryk
- 18th April 2015, 17:50
Hi All,

I wrote a little routine for putting PIC18F47J13 to Sleep and Waking Up from a key press. Works fine. Interested in the need to read PortB before @ Sleep? Reading various articles, I think the idea is to perform the read establishing the Before condition for the PortB Interrupt on Change function will work. After doing the read in these articles, nothing subsequently is done with the "Dummy" var. Although that makes some sense, it works with and without. Mostly trying to understand the rules here as otherwise it will bite me in the nose at some inconvenient time.

Dummy = PortB ' Read PortB to support Interrupt on Change Starting Reference?


WakeSleep:
' Get Ready for Sleep
INTCON.7 = 1 ' Enable GIE (Global Interrupt Enable)
INTCON.3 = 1 ' Enable RBIE (PortB Change Interrupt Enable)
INTCON.0 = 0 ' Clear RBIF (PortB Interrupt Flag)


@ Sleep
' Stop using Interrupts (So as not be interrupted!)
INTCON.7 = 0 ' Disable GIE (Global Interrupt Enable)
INTCON.3 = 0 ' Disable RBIE (PortB Change Interrupt Enable)
INTCON.0 = 0 ' Clear RBIF (PortB Interrupt Flag)


If swCoast = 0 Then ' Do Stuff Here
LED = 1
Pause 1000
LED = 0
EndIf


GoTo WakeSleep

andywpg
- 19th April 2015, 01:20
See, I read it as you have to read the port AFTER it wakes up so that you clear the mismatch that caused the interrupt.

I'm gonna have to go read that again......

Zebryk
- 20th April 2015, 03:11
Right. The data sheet says there are (3) ways to clear the "mismatch".
But, just doing the below seems both simple and direct.

INTCON.0 = 0 ' Clear RBIF (PortB Interrupt Flag)

Not sure how, why, and when you would want to use the other two?
(I prefer not to have UFO code in my projects.)