This is part of a program I used to put a PIC16F685 to sleep running at 8MHz.
The unit runs on a CR2032 coin cell and managed to get it down to less than 50nA in Sleep mode.
I had to make sure the circuit was not going to be sourcing power to anything while on standby and it's important to shut things OFF before bedding down.
I read somewhere that the @ NOP after the @ SLEEP would be needed and found it would not stay asleep unless it was there. Hey, as long as it worked!
Code:
'=========================================================================
' SLEEP Mode
' This routine provides an Ultra Low power consumtion until a button is
' pressed. All I/O's are setup for the PORTA/B Interrupt On Change function
' prior to going into standby condition. Any state change detected to these
' PORTs starts main and directs to proper routine.
'=========================================================================
Sleep_mode:
OPTION_REG.7 = 0 ' Global weak pull-up enable bit enabled
WPUA = %00011111 ' Weak pull-ups enable on PORTA inputs except RA5
WPUB = %00000000 ' Weak pull-ups disabled on PORTB
MOSI = 0 ' Turn OFF SPI data line
_CSN = 0 ' Turn OFF module select line
TXEN = 1 ' Transmitter Vcc OFF
SEND = 0 ' Turn OFF MS encoder SEND input
Action = 0 ' Turn OFF all outputs
m = 0 ' Mode counter reset
IOCA = %00000110 ' Mode input pin RA4 configured for IOC.
IOCB = %10000000 ' ID_new input pin RB7 configured for IOC.
Store_A = PORTA ' Reads PORTA
Store_B = PORTB ' Reads PORTB
INTCON = %00001000 ' RABIE (RA and RB Interupt Enabled)
@ SLEEP ; Goes mimi until a change of state is detected
@ NOP ; 1 instruction cycle
Bookmarks