;Power Cycler II v1.0 ;Copyright 2005, Nicholas A. Masluk ;Started August 8, 2005 ;DIP switch configurations ;Position Delay time (seconds) ;000 0.5 ;001 1 ;010 2 ;011 5 ;100 10 ;101 15 ;110 30 ;111 60 list p=12C508A include P12C508A.INC __CONFIG _MCLRE_OFF & _CP_ON & _WDT_ON & _IntRC_OSC ;leaving prescaler as-is (1:128), WDT has a period of 18 ms * 128 = 2.3 seconds CBLOCK 0x007 DLY_RPT ;0.5 second delay repeat, set by DIP switch configuration DLY0, DLY1, DLY2 ;registers for 0.5s delay loop ENDC ;I/O port connections DIP0 equ 0 ;DIP switch connections for timing of relay power cycle delay DIP1 equ 1 DIP2 equ 2 RESET equ 3 ;reset button CYCLE equ 4 ;power cycle button RELAY equ 5 ;relay output ;start of code org 0 movlw 0x0DF tris GPIO ;enable RELAY pin for output goto rset ;******** This is the only difference between Power Cycler and Power Cycler II ;Power Cycler II does not power cycle the peripherals upon power up, as it does not monitor power conditions, ;it only power cycles when it has been activated by it's push button, or an attached device on it's modular plug. pcycle btfss GPIO, RESET ;if reset is held, do not power cycle peripheral upon power up of this device, or power failure goto rset bsf GPIO, RELAY ;otherwise, turn on relay, switching off peripheral device movf GPIO, W ;read DIP switches andlw 0x007 ;which are only on the first 3 bits call dip_dly ;convert switch configuration into number of times to repeat 0.5 second delay movwf DLY_RPT ;loop 0.5s delay "DLY_RPT" times dlyloop call delay05 ;0.5 second delay xorlw 0x0FF ;check if loop has been killed due to reset btfsc STATUS, Z goto rset ;if so, restore power to peripheral, and wait for next power cycle decfsz DLY_RPT, F goto dlyloop btfsc GPIO, CYCLE ;check if mains power is restored (and cycle button released) before powering up peripheral goto $+5 btfss GPIO, RESET ;or power up peripheral regardless of power state (or cycle button state) goto rset ;if reset button is pressed clrwdt ;otherwise loop until power is back to normal, having already left goto $-5 ;power to peripheral off for designated time (so no further delay is needed) rset bcf GPIO, RELAY ;turn off relay, restoring power to peripheral clrwdt btfss GPIO, CYCLE ;loop, waiting for power failure or human power cycle of peripheral goto pcycle ;if power fails, or cycle button is pressed, power cycle peripheral goto $-3 ;end of main code ;start of dip_dly ;converts switch configuration into number of times 0.5 second delay is to be repeated ;pull-up resistors are used on pins, and "on" switches pull pins down to ground, so inputs are inverted dip_dly addwf PCL retlw 0x078 ;111 = 120 times, 60 seconds retlw 0x03C ;110 = 60 times, 30 seconds retlw 0x01E ;101 = 30 times, 15 seconds retlw 0x014 ;100 = 20 times, 10 seconds retlw 0x00A ;011 = 10 times, 5 seconds retlw 0x004 ;010 = 4 times, 2 seconds retlw 0x002 ;001 = 2 times, 1 second retlw 0x001 ;000 = 1 time, 0.5 seconds ;end of dip_dly ;start of delay05 ;0.5 second delay ;4MHz internal oscillator, 1MIPS delay05 movlw 0x006 ;500,161 cycle delay movwf DLY0 loop0 movlw 0x05B movwf DLY1 loop1 movlw 0x098 movwf DLY2 loop2 clrwdt btfss GPIO, RESET ;if reset button is pressed, quit loop retlw 0x0FF ;and notify reset has been pressed decfsz DLY2, F goto loop2 decfsz DLY1, F goto loop1 decfsz DLY0, F goto loop0 ;end of delay retlw 0x000 ;end of delay05 end