Here's something to start with. I've converted the assembler example in the app note to PBP for you with one exception. It does not use interrupts. This just uses the ultra low-power wake-up feature to wake from sleep. Global interrupts are disabled.
With a 10K / 1uF RC network on RA0, it wakes up & toggles RC5 ~ once every 34 seconds.
Code:
@ device pic16F688, intrc_osc_noclkout, wdt_off, mclr_off, protect_off
' Note: Default internal osc is set to 4MHz
SleepyTime:
'BCF STATUS, RP0 ;Bank 0
'BSF PORTA, 0 ;Set RA0 data latch
PORTA.0 = 1
'MOVLW H’7’ ;Turn off
'MOVWF CMCON0 ;comparators
CMCON0 = 7
'BSF STATUS, RP0 ;Bank 1
'BCF ANSEL, 0 ;RA0 to digital I/O
ANSEL.0 = 0
'BCF TRISA, 0 ;Output high to
TRISA.0 = 0
'CALL CapDelay ;charge capacitor
PAUSE 100 ' change to suite your RC circuit
'BSF PCON, ULPWUE ;Enable ULP Wake-Up
PCON.5 = 1
'BSF IOCA, 0 ;Select RA0 IOC
IOCA.0 = 1
'BSF TRISA, 0 ;RA0 to input
TRISA.0 = 1
'MOVLW E’10001000’ ;Enable interrupt
'MOVWF INTCON ;and clear flag
INTCON = %00001000 ' Note bit 7 is clear since we're not vectoring to an int handler
'SLEEP ;Wait for IOC
@ SLEEP
INTCON.0 = 0 ' clear int flag on wake-up
Main: ' Do whatever you need here on wakeup
' insert your code here
TOGGLE PORTC.5 ' do your stuff here before entering sleep mode again
GOTO SleepyTime ' do the ultra low-power wake-up thing again afterwards
END
An interesting note on this one is that is works whether you clear the int flag or not!
Bookmarks