I'm a total newbie when it comes to the @SLEEP function, but I would like to use it in some coming projects so I'm hoping someone can give me a hand at setting up the chip and getting it working. Optimal settings preferred as from what I gather in searches here turning things off and setting ports before sleep has some effect on overall current draw while sleeping. And yes I have read and searched the forums but I can't seem to figure it out.
I have this very basic and useless program here as an example and I would like to know how to implement the @SLEEP function and then wake the chip back up on a port change (button press).
Basically with the above as long as GPIO.3 is pressed every 5 seconds it will never enter the sleep IF/THEN but when it does I would like the chip to go to sleep and wait for GPIO.3 to be pressed again as the wake up interrupt and then resume.Code:@ DEVICE PIC12F683, MCLR_OFF, INTRC_OSC_NOCLKOUT, WDT_OFF, BOD_OFF, PWRT_OFF, FCMEN_OFF, IESO_OFF, CPD_ON, PROTECT_ON INTCON = %10001000 'internal oscillator OSCCON = %01110000 ' 8mHz CMCON0 = 7 'Comparators off GPIO = %00000000 'outputs low TRISIO = %00010000 'GP3 as input x VAR WORD 'timeout counter x=0 Main HIGH GPIO.0 'turn on led so I know the chip is alive IF GPIO.3 = 1 THEN HIGH GPIO.1 'light up GPIO.1 so I know the button was pressed PAUSE 50 LOW GPIO.1 x=0 'reset the timeout counter if the button is pressed ENDIF pause 100 x=x+1 IF x>50 THEN 'go to sleep here if GPIO.3 is not pressed for 5 seconds 'should come out of sleep when GPIO.3 is again pressed PAUSE 100 ENDIF GOTO Main
From my searches here it appears I need to set flags and further configure the chip but that is all just words to me as it's not clicking upstairs. Can someone toss this dog a bone?




Bookmarks