@ Sleep Usage & Need to Read PortB


Closed Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2013
    Posts
    41

    Default @ Sleep Usage & Need to Read PortB

    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

  2. #2
    Join Date
    Jan 2012
    Location
    Grid EN19MV
    Posts
    157


    Did you find this post helpful? Yes | No

    Default Re: @ Sleep Usage & Need to Read PortB

    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......
    "I have noticed that even those who assert that everything is predestined and that
    we can change nothing about it still look both ways before they cross the street"


    -Stephen Hawking

  3. #3
    Join Date
    Jul 2013
    Posts
    41


    Did you find this post helpful? Yes | No

    Default Re: @ Sleep Usage & Need to Read PortB

    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.)

Similar Threads

  1. HSEROUT & Sleep Question
    By rocket_troy in forum Serial
    Replies: 3
    Last Post: - 5th March 2014, 02:20
  2. Replies: 6
    Last Post: - 12th March 2011, 14:11
  3. 18f24k20 & portb.1 (rb1)
    By bmagistro in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 9th March 2009, 21:01
  4. Sleep & nap
    By keymuu in forum mel PIC BASIC Pro
    Replies: 24
    Last Post: - 4th December 2008, 19:45
  5. interupt & Sleep Problem - HELP!!
    By Santana in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 23rd November 2004, 11:39

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts