SLEEP System

Enter low-power sleep until a reset, a watchdog time-out or an interrupt wakes the PIC.

SyntaxSLEEP
Operandsnone
Operation00h → WDT, 0 → WDT prescaler, 1 → TO, 0 → PD; the oscillator stops
Status bitsTO PD
Words / cycles1 word, 1 cycle
Encoding00 0000 0110 0011

How it works

SLEEP clears the watchdog timer, sets TO, clears PD and stops the oscillator. Because the clock stops, Timer0 stops too, so a Timer0 interrupt cannot wake the device.

The PIC wakes on a watchdog time-out or on an interrupt that is enabled (RB0/INT, a PORTB change, the EEPROM write or a peripheral interrupt), even with GIE clear. It continues with the instruction after SLEEP; if GIE is set, the interrupt routine runs after that instruction.

Example

; SLEEP example from picsimulator.com/instructions/sleep.html
    list p=16f84a
    include <p16f84a.inc>

    org 0
    bsf INTCON, INTE  ; RB0/INT may wake the PIC
    sleep             ; stop here; click RB0 to wake it
    movlw 0x01        ; runs after wake-up

The simulator stays in SLEEP until you click RB0 in the GPIO widget.

Open this example in the simulator

Watch out for

  • Waiting for a Timer0 interrupt with SLEEP never ends: Timer0 doesn't run while the oscillator is stopped.

Related instructions