Off timer program of 30 or 60 minutes for PIC12F629

The television, I was using everyday, did not work the "OFF Timer". So, I made the OFF Timer by using the PIC12F629 and the solid-state relay (SSR).

The program of PIC12F629 is used assembler.

Off timer used PIC12F629

Because it had come to manage to use the PIC microcomputer, the off timer that was able to be used also for the television by holding the study of PIC concurrently was made.

It made with PIC microcomputer PIC12F629 by using the kit of solid-state relay (SSR) of Akizuki Electronic commerce.

I used the Tera-Pad editor of free software and made the program of the assembler of PIC. MPLAB IDE Ver.7.4 of the Microchip Co. and writing the PIC program handled AKI-PIC programmer Ver.4 the PIC development tool by Akizuki Electronic commerce.

Of course, you can use the air conditioner or the television or the radio, the radio-cassette, if you change the cooling fin bigger.

How to use this program. (assembler program of an off timer)

Please make the assembler program file name timer30_60.asm etc. , preserve in the editor etc. , and use it.

Off timer program for 30 or 60 minutes.

; Filename:	timer30_60.asm
; Date:2007.06.02
; File Version:	1.0
; OFF Timer 30_60 min.
; Author:		D.Ishikawa
; Files required:
	list	p=12f629		;list directive to define processor
	#include	<>	; processor specific variable definitions

	errorlevel	-302	;suppress message 302 from list file


	__IDLOCS 0x0100 ;Ver 1.00

#define	OUT_LED	GPIO,1	;
#define	OUT_TMR	GPIO,2	;
#define	IN_P	GPIO,3	;
#define	ON_TIME	d'30'	;

w_temp EQU 0x20 ; variable used for context saving 
status_temp EQU 0x21 ; variable used for context saving

CNT1	EQU	0x22
CNT2	EQU	0x23
CNT3	EQU	0x24
CNT4	EQU	0x25
;initialize eeprom locations
	ORG	0x2100
	DE	"OFF Timer_30_60min."

	ORG	0x000		; processor reset vector
	goto	main		;go to beginning of program

	ORG	0x004		;interrupt vector location
	movwf	w_temp		;save off current W register contents
	movf	STATUS,w	;move status register into W register
	movwf	status_temp	; save off contents of STATUS register

;isr code can go here or be located as a call subroutine elsewhere

	movf	status_temp,w	; retrieve copy of STATUS register
	movwf	STATUS		;restore pre-isr STATUS register contents
	swapf	w_temp,f
	swapf	w_temp,w	;restore pre-isr W register contents
	retfie			;return from interrupt

;these first 4 instructions are not required if the internal oscillator is not used

	call	0x3FF		;retrieve factory calibration value
	bsf	STATUS,RP0	;set file register bank to 1 
	movwf	OSCCAL		;update register with factory cal value 
	bcf	STATUS,RP0	;set file register bank to 0

;remaining code goes here

	bcf	STATUS,RP0	;set file register bank to 0
	bcf	STATUS,RP1	;set file register bank to 0

	clrf	INTCON		;

	clrf	GPIO		;

	bsf	STATUS,RP0	;
	clrf	TRISIO		;
	bsf	TRISIO,3	;

	clrf	IOC		;
	movlw	b'10000000'	;
	movwf	OPTION_REG	;

	bcf	STATUS,RP0	;

	bcf	OUT_LED		;
	bcf	OUT_TMR		;

	btfsc	IN_P		;
	goto	_60MIN		;

	bsf	OUT_TMR		;
	call	DLY_30
OFF_30	bcf	OUT_TMR		;
	goto	OFF_30

	bsf	OUT_TMR		;
	call	DLY_60_30
	call	DLY_30
OFF_60	bcf	OUT_TMR		;
	goto	OFF_60

;Delay Routine

DLY_30			;
	movlw	ON_TIME		;1*30=30min
	movwf	CNT4
DLY_6			;60S
	movlw	d'60'		;1*60=60S
	movwf	CNT3
DLY_5	;1S	;0.5*2=1S
	bsf	OUT_LED		;
	call	DLY_500
	bcf	OUT_LED		;
	call	DLY_500

	decfsz	CNT3,f
	goto	DLY_5
	decfsz	CNT4,f
	goto	DLY_6

DLY_60_30			;
	movlw	ON_TIME		;1*30=30min
	movwf	CNT4
DLY_4			;60S
	movlw	d'30'		;2*30=60S
	movwf	CNT3
DLY_3			;2S ;0.5*4=2S
	bsf	OUT_LED		;
	call	DLY_500
	call	DLY_500
	bcf	OUT_LED		;
	call	DLY_500
	call	DLY_500

	decfsz	CNT3,f
	goto	DLY_3
	decfsz	CNT4,f
	goto	DLY_4

DLY_500			;500mS
	movlw	d'250'		;2mS*250=500mS
	movwf	CNT2
DLY_2			;2mS	DLY_2 loop
	movlw	d'249'	;	(1)	1cycle=1 micro S
	movwf	CNT1	;	(1)
	nop		;	(1)
	nop		;	(1)
	nop		;	(1)
	nop		;	(1)
DLY_1		;  DLY_1 loop
	nop	;	 1	 1
	nop	;	 1	 1
	nop	;	 1	 1
	nop	;	 1	 1
	nop	;	 1	 1
	decfsz	CNT1,f	;1	 2
	goto	DLY_1	;2
	decfsz	CNT2,f	;	 1
	goto	DLY_2	;	(2)

	END	;directive 'end of program'