;------------------------------------------------
; AFRECODER  AFREC01 	ver. 1.0
;	CLOCK=XT(4.0MHz),  WDT=OFF
;------------------------------------------------
	LIST P=16F84
;------------------------------------------------
STATUS	EQU	03H
PORTA	EQU	05H
PORTB	EQU	06H
OPT	EQU	01H	;OPTION
TRISA	EQU	05H
TRISB	EQU	06H
C	EQU	0
RP0	EQU	5
TM1	EQU	21H
TM2	EQU	22H


;---------------------------------------------------
	ORG	0
	goto 	start
start	call 	init		;イニシャライズ、ポート設定
	btfsc	PORTB,5		;２/１６秒切替？
	goto	main1		;２秒分割録再モードへ
	call 	init2
	goto	main2		;１６秒録再モードへ
;---------------------------------------------------
main1	nop
	movf	PORTB,0
	iorlw	008h		;PLAY OFF
	movwf 	PORTA
	bsf	PORTA,3
	btfss	PORTB,3		;PLAY ?
	call	PLAY10
	btfss	PORTB,4		;REC ?
	call	REC10
	goto	main1
;------------------
PLAY10	bcf	PORTB,7
	call	TIM01
	bsf	PORTB,7	
	call	TIM10		;WAIT 1S
	call	TIM10		;WAIT 1S
	call	TIM03		;0.3S
	return
;------------------
REC10	bcf	PORTB,6
	call	TIM10
	call	TIM10
	bsf	PORTB,6
	return
;---------------------------------------------------
main2	nop
	movlw	008h		
	movwf 	PORTA
	bsf	PORTA,3
	btfss	PORTB,3		;PLAY ?
	call	PLAY16
	btfss	PORTB,4		;REC ?
	call	REC16
	goto	main2
;------------------
PLAY16	bcf	PORTB,7
	bsf	PORTB,0
	call	TIM01		;1.3mS
	bsf	PORTB,7	
	call	TIM40		;WAIT 4.0S
	call	TIM40		;WAIT 4.0S
	call	TIM40		;WAIT 4.0S
	call	TIM40		;WAIT 4.0S
	bcf	PORTB,0
	call	TIM40		;WAIT 4.0S
	return
;------------------
REC16	bcf	PORTB,6
	call	TIM40		;WAIT 4.0S
	call	TIM40		;WAIT 4.0S
	call	TIM40		;WAIT 4.0S
	call	TIM40		;WAIT 4.0S
	bsf	PORTB,6
	return
;---------------------------------------------------
init	bsf 	STATUS,RP0	;BANK-1  -----ポート設定------
	movlw 	b'11110000'
	movwf 	TRISA
	movlw 	b'00111111'
	movwf 	TRISB
	movlw 	b'00000000'
	movwf 	OPT
	bcf 	STATUS,RP0	;BANK-0
	movlw 	b'00001000'
	movwf 	PORTA
	movlw 	b'11000000'
	movwf 	PORTB
	return
;------------------
init2	bsf 	STATUS,RP0	;BANK-1  -----ポート設定------
	movlw 	b'00111110'
	movwf 	TRISB
	bcf 	STATUS,RP0	;BANK-0
	return
;------------------
TIM01	movlw   0f8h		;WAIT TIMER 1.3mS
	movwf   TM1
TIM02	nop
	nop
	decfsz  TM1
	goto 	TIM02
	return
;------------------
TIM03	movlw   0ffh		;WAIT TIMER 0.3S
	movwf   TM2
TIM031	call	TIM01
	decfsz  TM2
	goto 	TIM031
	return
;------------------
TIM10	movlw   0ffh		;WAIT TIMER 1.0S
	movwf   TM2
TIM11	call	TIM01
	call	TIM01
	call	TIM01
	decfsz  TM2
	goto 	TIM11
	return
;------------------
TIM40	movlw   0ffh		;WAIT TIMER 4.0S
	call	TIM10
	call	TIM10
	call	TIM10
	call	TIM10
	return
;------------------

	END
