16f883 sleeping mode


Closed Thread
Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    Feb 2013
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Re: 16f883 sleeping mode

    I don't know how to write code to sleep. I want help for it.
    Quote Originally Posted by mackrackit View Post
    The above is from the manual. I post it as I do not see the "SLEEP" command in your code.

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default Re: 16f883 sleeping mode

    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Jan 2012
    Location
    Grid EN19MV
    Posts
    159


    Did you find this post helpful? Yes | No

    Default Re: 16f883 sleeping mode

    Here's some code from when I needed a 16f886 to sleep until PORTB.0 went low. You should be able to adapt it. I should mention that I am self-taught at BASIC so there's probably a better way to do this:


    Code:
    #CONFIG __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _LVP_OFF & _CP_OFF
    
    #ENDCONFIG
    
    DEFINE NO_CLEARWDT 1 'NO WATCHDOG TIMER
    DEFINE OSC 8  'LETS PBP KNOW THE OSCILLATOR IS RUNNING AT 8MHz
    
    OSCCON = %01110001 '8 MHz INTERNAL OSCILLATOR, INTERNAL OSCILLATOR IS USED FOR SYSTEM CLOCK
    
    DISABLE 'NO INTERRUPTS, NO DEBUG COMMENT THIS OUT FOR INTERRUPTS
    
    
    ANSEL = 0 'PORTA ALL DIGITAL
    ANSELH = 0 'PORTB ALL DIGITAL
    
    OPTION_REG = 0 'PORT B PULLUPS ENABLED
    WPUB = %01111111 'PULL UPS ENABLED ON PORTB 0-6
    
    INTCON = 0 'INTERRUPTS DISABLED
    IOCB = %00000001 'PORTB.0 INTERRUPT ON CHANGE ENABLED
    TRISA = 0 'PORTA ALL OUTPUTS
    TRISB = %01111111 'B7 OUTPUT, ALL THE OTHERS INPUTS
    TRISC = 0 'PORTC ALL OUTPUTS
    
    DUMMY VAR BYTE
    
    <irrelevant code here>
    
    INTCON = %00001000 'PORTB CHANGE INTERRUPT ENABLED GIE *NOT* ENABLED
    NAP 0 'NAP (ENTER VERY LOW POWER MODE) FOR ABOUT 18mS.  SINCE THE WATCHDOG TIMER IS NOT ENABLED,
             'THE PROCESSOR WOULD NAP FOREVER, EXCEPT FOR THE FACT THAT THE 'INTERRUPT-ON-STATE-CHANGE'
             'BIT FOR PORTB.0 (MASTER SWITCH) IS ENABLED. THIS MEANS THAT A CHANGE ON THE MASTER SWITCH
             '(OFF TO ON) WILL GENERATE AN INTERRUPT.  HOWEVER, THE GLOBAL INTERRUPT ENABLE BIT IS *NOT*
             'SET.  THIS MEANS A *REAL* INTERRUPT WILL NOT BE GENERATED.  THE PROCESSOR WILL NOT JUMP TO THE INTERRUPT
             'ROUTINE, AND WILL, INSTEAD, EXECUTE THE NEXT INSTRUCTION AFTER THE NAP - IN OTHER WORDS, CONTINUE
             'THE MAIN LOOP WHERE THE NEW STATE OF THE MASTER SWITCH WILL BE CAUGHT BY THE IF STATEMENT.  THIS
             'HAS THE EFFECT OF SHUTTING THE PROCESSOR DOWN (ESSENTIALLY) UNTIL THE MASTER SWITCH IS TURNED ON
             'AGAIN - SAVING THE VEHICLE'S BATTERY IF THE MAIN POWER SWITCH IS ACCIDENTALLY LEFT ON.  OPERATION
             'OF ANY OF THE OTHER SWITCHES WILL NOT CAUSE THE ABOVE TO HAPPEN AS THEIR ENABLE BITS IN THE IOCB
             'REGISTER HAVE NOT BEEN SET.
    DUMMY = PORTB 'READ PORTB TO CLEAR THE MISMATCH THAT GENERATED THE INTERRUPT
    INTCON = 0 'INTERRUPTS OFF 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

  4. #4
    Join Date
    Feb 2013
    Posts
    8


    Did you find this post helpful? Yes | No

    Default Re: 16f883 sleeping mode

    Thanks for your help. Best Regards.

Similar Threads

  1. LCD's and Sleeping Pics
    By andybarrett1 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 1st June 2015, 18:18
  2. 16f883
    By Meriachee in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 10th September 2009, 00:45
  3. 16F883 Code Verify Problem
    By munromh in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 19th February 2009, 11:47
  4. 16F883/886 Help
    By plyrathrt in forum General
    Replies: 9
    Last Post: - 18th August 2008, 08:54
  5. Waking a sleeping PIC
    By anj in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 19th May 2005, 01:51

Members who have read this thread : 2

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

Posting Permissions

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