; ; *************************************************************************** ; *** Bubble Software Parallax to PIC Source Converter. Copyright 1999. *** ; *** http://www.picnpoke.com email: sales@picnpoke.com *** ; *************************************************************************** ; ; SLEEP period ; Puts the PIC to sleep for 1 to 65535 units of 2.3 seconds. ; The 2.3-second value is approximate. Wide variations in operating temperature ; or supply voltage can double or halve this figure. See the discussion in the ; Nap program listing. ; Device data and reset vector: Note that the watchdog timer is ON. P = pic16c55 #include <16c55.inc> ; processor assembler definitions _CONFIG _xt_osc & _wdt_on & _protect_off reset start org 8 hiB Res 1 lowB Res 1 org 0 SLEEP ; Take twos complement COMF lowB ; of the 16-bit counter BTFSC status,z ; If zero, lowB overflowed, INCF hiB ; so carry into hiB. MOVLW d'15' ; Assign prescaler (div 128) OPTION ; to wdt, then write to option. SLEEP ; Go to sleep. ; SLEEP (cont) start MOVLW d'0' ; Make RB all outputs for LEDs. TRIS 6h CLRW ; At the beginning of the program, BTFSC status,pd ; we set up a Branch-type routine IORLW d'1' ; to take action based on the BTFSC status,to ; power-down (pd) and timeout (to) IORLW d'2' ; bits. ADDWF pcl ; | to | pd| GOTO count_dn ; | 0 | 0 | wdt wakeup: count down. GOTO watch_fail ; | 0 | 1 | wdt timeout: handle it. GOTO mclr_pin ; | 1 | 0 | mclr wakeup: handle it. GOTO main ; | 1 | 1 | power 1st on: goto main. ; This code executes when power is first applied to the PIC (after start). ; It consists of a loop in which the PIC sleeps for 2 hours, then inverts port RB. main MOVLW 0x0C ; Load 3125 (0C35 hex) MOVWF hiB MOVLW 0x35 ; into 16-bit counter. MOVWF lowB CALL Sleep ; Hibernate for 3125 x 2.304 secs. MOVLW d'255' ; Wake up after 2 hours, invert RB. XORWF 6h GOTO main ; Do it again. ; When the PIC wakes up from a wdt timeout, it executes this code, which ; increments the 16-bit value in lowB and hiB, and determines whether it's ; time to wake up. If it's not, the PIC goes back to sleep. If it is, the program ; returns to resume execution at the instruction following call Sleep. count_dn INCF lowB ; lowB = lowB+1. BTFSC status,z ; Overflow in lowB? INCFSZ hiB ; Yes: hiB=hiB+1, overflow?. SLEEP ; No overflow: back to sleep. RETLW 0h ; Overflow. Return to caller ; In an actual application, this code would contain instructions for dealing ; with a reset pulse waking the PIC out of sleep. Here, we have an empty ; routine that just returns to the main loop. mclr_pin RETLW 0h ; In an actual application, this code would contain instructions for dealing ; with a watchdog-timer timeout during program execution. Here, we have an ; empty routine that just returns to the main loop. watch_fail RETLW 0h