; ; *************************************************************************** ; *** Bubble Software Parallax to PIC Source Converter. Copyright 1999. *** ; *** http://www.picnpoke.com email: sales@picnpoke.com *** ; *************************************************************************** ; ; NAP period (in w) ; Puts the PIC to sleep for a short period of time. ; The length of the nap may be in the range of 0 to 7 and is passed ; to the subroutine in the w register. The length of nap (in seconds) is ; 2^w * 18 ms, as follows: ; w = 0: nap = 18 ms ; w = 1: nap = 36 ms ; w = 2: nap = 72 ms ; w = 3: nap = 144 ms ; w = 4: nap = 288 ms ; w = 5: nap = 576 ms ; w = 6: nap = 1152 ms ; w = 7: nap = 2304 ms ; The 18-ms value is very approximate. It is based on a supply ; voltage of 5 Vdc and an operating temperature of 77 degrees F. ; At higher temperatures and lower supply voltages, it can be much ; longer--even double--the nominal 18 ms. Likewise, at lower ; temperatures and higher supply voltages it can fall to half. ; Note that Nap uses one level of the call/return stack. ; 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 0 Nap IORLW d'8' ; Set option.3 to assign prescaler OPTION ; Lower 3 bits are prescale rate. SLEEP ; Go to sleep 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 | RETLW 0h ; | 0 | 0 | wdt wake: return. GOTO wdt_fail ; | 0 | 1 | wdt timeout: handle it. GOTO mclr_pin ; | 1 | 0 | mclr wake: handle it. GOTO main ; | 1 | 1 | pwr on: main. ; This code executes when power is first applied to the PIC (after start). ; It's a loop in which the PIC takes a 1.152-second nap, then inverts ; port rb. The result is that LEDs connected to RB flash at the rate of the ; nap period. main MOVLW d'6' ; Set up a 1152-ms nap. CALL Nap ; Snooze for >1 second. MOVLW d'255' ; Wake up and invert RB. XORWF 6h GOTO main ; Do it again. ; In an actual application, this code would contain instructions for dealing ; with a reset pulse waking the PIC out of its nap. 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. Here, we have an empty routine that just ; returns to the main loop. wdt_fail RETLW 0h end