Here's a sample snippet of what I use on a PIC16F677 so you can ignore some of the extra not pertaining to the PIC12F683.
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 loop 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
TXEN = 1 ' Transmitter Vcc OFF
SEND = 0 ' Turn OFF MS encoder SEND input
Action = 0 ' Turn OFF all outputs
m = 0 ' Mode counter reset to zero
IOCA = %00010000 ' Mode input pin configured for IOC
IOCB = %10000000 ' ID_new input pin 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
'=========================================================================
woke_up: ' goes on from here then will go back to sleep with no activity
I basically set everything OFF first then set the IOC, in your case it would be IOC=%000010000.
Take a snapshot of the port to detect a difference.
Set the INTCON and go to Sleep.
Code:
all_my_outputs = 0 ' you want to make sure there's no parasitic currents
' in your circuit of course
all_my_vars = 0 ' zero out your counters if needed
IOC=%00001000 ' Sets GPIO.3 only for Interupt On Change
Store_GPIO = GPIO ' Snapshot of current port state
INTCON.7=1 ' From data sheet: Global Interrupt Enable (GIE) must
' be enabled for individual interrupts to be recognized.
@ SLEEP ; Goes to sleep until a change of state is detected
@ NOP ; 1 instruction cycle - Bruce and others have explained
' why this was needed but I forget why at the moment.
Hope this gets you going.
Bookmarks