PIC16F84電子遊戯(64)サブページ
最終更新日:2002年3月9日
ミッキーマウス・音声録音再生ユニット(1ページ)へ (2ページ)へ (3ページ)へ

ミッキーマウス・音声録音再生ユニットの全ソースリスト
;**********************************************************************
;    Filename:	    mickey.asm                                       *
;    Date:          2002/2/4                                        *
;    File Version:                                                    *
;**********************************************************************

	list      p=16F84             ; list directive to define processor
	#include <p16F84.inc>         ; processor specific variable definitions

	__CONFIG   _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC

;***** VARIABLE DEFINITIONS
w_temp        EQU     0x0C        ; variable used for context saving 
status_temp   EQU     0x0D        ; variable used for context saving

led_data	EQU	0x11		;LED set data
					;led_data,0  TENTOU LED

acount1		EQU	0x13		;LED auto count ram1
acount2		EQU	0x14		;LED auto count ram2 

wait_data	EQU	0x15		;wait data ram

color_count	EQU	0x16		;color count ram
taihi		EQU	0x17		;taihi data

tentou_count	EQU	0x19		;TENTOU LED count ram

color_mickey	EQU	0x1A		;Mickey LED color

push_key	EQU	0x1e		;push key
					;push_key,0 REC_KEY
					;push_key,1 PLAY_KEY

tentou_on	EQU	0x20		;RED LED ON data ram
tentou_off	EQU	0x21		;RED LED OFF data ram

tm0_setdata	EQU	0f3h		;FFH-F3H=12 12*16=192usec
;**********************************************************************
		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
		;---------------------------------------------------------------
		bcf	INTCON,T0IF
		movlw	tm0_setdata
		movwf	TMR0
		;---------------------------------
		movlw	01h		;LED mode auto shori
		addwf	acount1,1
		btfsc	STATUS,0
		incf	acount2,1
		btfss	acount2,0	;
		goto	tentou_leds
		call	led_change	
		call	led_set
		call	auto_clear
		;----------------------- LED
tentou_leds	decfsz	tentou_count,1
		goto	next_leds
		btfsc	led_data,0	;LED OFF?
		goto	tentou_leds_2
tentou_leds_3	bsf	led_data,0	;LED ON
		movf	tentou_on,0
		movwf	tentou_count
		movf	tentou_count,0
		btfsc	STATUS,2
		goto	tentou_leds_2
		goto	next_leds
tentou_leds_2	bcf	led_data,0	;LED OFF
		movf	tentou_off,0
		movwf	tentou_count
		movf	tentou_count,0
		btfsc	STATUS,2
		goto	tentou_leds_3		
		;----------------------------------
next_leds
		;----------------------------------
int_end
		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
;--------------------------------------------------------------------------
main
		call	port_set
		movlw	0ffh
		movwf	PORTA
		movlw	0ffh
		movwf	PORTB

		call	timer0_set

		movlw	1Ch
		movwf	color_count
		call	auto_clear

		movlw	07h
		movwf	color_mickey

		movlw	00h
		movwf	led_data	;LED OFF
		call	set_lo_leds
		movf	tentou_on,0
		movwf	tentou_count	;LED count data set

main_sleep
		bcf	INTCON,GIE
		nop
		bcf	INTCON,T0IE
		nop
		bcf	INTCON,T0IF
		nop
		bcf	INTCON,RBIF
		nop
		bsf	INTCON,RBIE
		nop
		movlw	0ffh
		movwf	PORTB
		movlw	00h
		movwf	push_key
		nop
		sleep
		nop
		bcf	INTCON,RBIE
		nop
		bsf	INTCON,GIE
		nop
		bsf	INTCON,T0IE
		nop
;---------------------------------------
		call	mickey_change
;--------------------------------------- REMOTE INPUT
		btfsc	PORTB,7
		goto	main_key1
		bsf	push_key,1
		goto	main_key2r
;--------------------------------------- REC KEY
main_key1
		btfsc	PORTB,5
		goto	main_key2		
		call	wait_1
		btfsc	PORTB,5
		goto	main_key2
		bsf	push_key,0
main_key1p	btfss	PORTB,5
		goto	main_key1p
		bcf	PORTA,1		;PD L
		nop
		bcf	PORTA,2		;REC MODE
		nop
		bcf	PORTA,0		;CE L(REC START)
		nop
		bsf	PORTA,0		;CE H
		goto	main_loop
;--------------------------------------- PLAY KEY	
main_key2
		btfsc	PORTB,6
		goto	main_key3
		call	wait_1
		btfsc	PORTB,6
		goto	main_key3
		bsf	push_key,1
main_key2p	btfss	PORTB,6
		goto	main_key2p
main_key2r	bcf	PORTA,1		;PD L
		nop
		bsf	PORTA,2		;PLAY MODE
		nop
		bcf	PORTA,0		;CE L(PLAY START)
		nop
		bsf	PORTA,0		;CE H
		goto	main_loop
;---------------------------------------
main_key3
;--------------------------------------
main_loop
		btfsc	push_key,0
		goto	rec_led
		btfsc	push_key,1
		goto	play_led
;--------------------------------------
		goto	main_sleep
;--------------------------------------
rec_led
		btfss	led_data,0
		goto	rec_led_off
		bcf	PORTB,4
		nop
		goto	main_next
rec_led_off
		bsf	PORTB,4
		nop
		goto	main_next
;--------------------------------------
play_led
		btfss	led_data,0
		goto	play_led_off
		bcf	PORTB,4
		nop
		goto	main_next
play_led_off
		bsf	PORTB,4
		nop
		goto	main_next
;---------------------------------------
main_next
		btfss	color_mickey,0
		goto	blue_off
		bcf	PORTB,1
		nop
		bcf	PORTB,2
		nop
		goto	main_next2
blue_off
		bsf	PORTB,1
		nop
		bsf	PORTB,2
		nop
		goto	main_next2
main_next2
		btfss	color_mickey,1
		goto	red_off
		bcf	PORTB,3
		nop
		goto	main_next3
red_off
		bsf	PORTB,3
		nop
		goto	main_next3
main_next3
		btfss	color_mickey,2
		goto	green_off
		bcf	PORTB,0
		nop
		goto	main_next4
green_off
		bsf	PORTB,0
		nop
		goto	main_next4
;---------------------------------------
main_next4

;--------------------------------------- REC KEY
main_key4
		btfsc	PORTB,5
		goto	main_key5		
		call	wait_1
		btfsc	PORTB,5
		goto	main_key5
		btfss	push_key,0
		goto	main_key5
		bcf	push_key,0
main_key4p	btfss	PORTB,5
		goto	main_key4p
		goto	main_nexte1s
;--------------------------------------- PLAY KEY	
main_key5
		btfsc	PORTB,6
		goto	main_key6
		call	wait_1
		btfsc	PORTB,6
		goto	main_key6
		btfss	push_key,1
		goto	main_key6
		bcf	push_key,1
main_key5p	btfss	PORTB,6
		goto	main_key5p		
		goto	main_nexte2s
;---------------------------------------
main_key6
;---------------------------------------
main_nexte
		btfsc	PORTA,3		;EOM=L
		goto	main_loop
;---------------------------------------
main_nexte1
		btfss	push_key,0
		goto	main_nexte2
main_nexte1s
		bcf	PORTA,0		;CE L(REC STOP)
		nop
		bsf	PORTA,0		;CE H
		nop
		bsf	PORTA,1		;PD H
		goto	main_sleep
;--------------------------------------
main_nexte2
		btfss	push_key,1
		goto	main_nexte3
main_nexte2s
		bcf	PORTA,0		;CE L(PLAY STOP)
		nop
		bsf	PORTA,0		;CE H
		nop
		bsf	PORTA,1		;PD H
		goto	main_sleep
;--------------------------------------
main_nexte3
		goto	main_sleep
;-------------------------------------------------------------------------------
wait_1		
		movlw	0ffh
		movwf	wait_data
wait_2
		nop
		decfsz	wait_data,1
		goto	wait_2
		return
;-------------------------------------------------------------------------------
auto_clear	movlw	00h
		movwf	acount1		;LED auto count clear
		movwf	acount2
		return
;-------------------------------------------------------------------------------
led_change	decf	color_count,1
		btfsc	STATUS,2
		goto	led_change2
		return
led_change2	movlw	1Ch
		movwf	color_count
		return	
;-------------------------------------------------------------------------------
mickey_change
		decf	color_mickey
		btfsc	STATUS,2
		goto	mickey_change2
		return
mickey_change2
		movlw	07h
		movwf	color_mickey
		return
;-------------------------------------------------------------------------------
led_set		btfsc	push_key,0
		goto	rec_led_set
		btfsc	push_key,1
		goto	play_led_set
		return	

rec_led_set
		call	set_on_led1
		movwf	tentou_on
		sublw	70h
		movwf	tentou_off
		return
play_led_set
		call	set_on_led2
		movwf	tentou_on
		sublw	70h
		movwf	tentou_off
		return
;--------------------------------------------------------------------------------
set_on_led2	movf	color_count,0
		movwf	taihi
		movlw	low(led2_on_table)
		addwf	taihi,1
		movlw	high(led2_on_table)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
led2_on_table	retlw	70h
		retlw	00h
		retlw	10h
		retlw	20h
		retlw	30h
		retlw	40h
		retlw	50h
		retlw	60h
		retlw	70h
		retlw	60h
		retlw	50h
		retlw	40h
		retlw	30h
		retlw	20h
		retlw	10h
		retlw	00h
		retlw	10h
		retlw	20h
		retlw	30h
		retlw	40h
		retlw	50h
		retlw	60h
		retlw	70h
		retlw	60h
		retlw	50h
		retlw	40h
		retlw	30h
		retlw	20h
		retlw	10h

set_on_led1	movf	color_count,0
		movwf	taihi
		movlw	low(led1_on_table)
		addwf	taihi,1
		movlw	high(led1_on_table)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
led1_on_table	retlw	70h
		retlw	00h
		retlw	30h
		retlw	70h
		retlw	00h
		retlw	30h
		retlw	70h
		retlw	00h
		retlw	30h
		retlw	70h
		retlw	00h
		retlw	30h
		retlw	70h
		retlw	00h
		retlw	30h
		retlw	70h
		retlw	00h
		retlw	30h
		retlw	70h
		retlw	00h
		retlw	30h
		retlw	70h
		retlw	00h
		retlw	30h
		retlw	70h
		retlw	00h
		retlw	30h
		retlw	70h
		retlw	00h
;-------------------------------------------------------------------------------
set_lo_leds	movlw	00h
		movwf	tentou_on

		movlw	70h
		movwf	tentou_off
		return
;-------------------------------------------------------------------------------
port_set				;RA0,RA1,RA2,RA4(OUT)
					;RA3(IN)				
					;RB0,RB1,RB2,RB3,RB4(OUT)
					;RB5,RB6,RB7(IN)
		bsf	STATUS,RP0
		clrf	TRISA
		bsf	TRISA,3
		nop
		clrf	TRISB
		bsf	TRISB,7
		nop
		bsf	TRISB,6
		nop
		bsf	TRISB,5
		nop
		bcf	STATUS,RP0
		return

timer0_set

		bsf	STATUS,RP0
		movlw	083h		;(1)PORTB NOT PULLUP
					;(0)INTEDG
					;(0)TOCS
					;(0)TOSE
					;(0)PSA
					;(011)1/16
		movwf	OPTION_REG
		bcf	STATUS,RP0
		
		movlw	tm0_setdata
		movwf	TMR0
		return


		END                     ; directive 'end of program'

不明点などあればメールお願いいたします。nonchansoft@nifty.com