PIC16F84電子遊戯(39)
最終更新日:2001年8月29日
電子メッセンジャー「バルちゃん」(1ページ)へ (2ページ)へ (3ページ)へ (4ページ)

電子メッセンジャー「バルちゃん」の全ソースリスト公開
;**********************************************************************
;    Filename:	    valtan.asm                                       *
;    Date:          2001/8/20                                        *
;    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  RED LED
					;led_data,1  GREEN 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

red_count		EQU	0x19		;RED LED count ram
green_count	EQU	0x1a		;GREEN LED count ram

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

red_on		EQU	0x20		;RED LED ON data ram
red_off		EQU	0x21		;RED LED OFF data ram
green_on		EQU	0x22		;GREEN LED ON data ram
green_off		EQU	0x23		;GREEN 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	red_leds
		call	led_change	
		call	led_set
		call	auto_clear
		;----------------------- RED
red_leds		decfsz	red_count,1
		goto	green_leds
		btfsc	led_data,0	;RED OFF?
		goto	red_leds_2
red_leds_3	bsf	led_data,0	;RED ON
		movf	red_on,0
		movwf	red_count
		movf	red_count,0
		btfsc	STATUS,2
		goto	red_leds_2
		goto	green_leds
red_leds_2	bcf	led_data,0	;RED OFF
		movf	red_off,0
		movwf	red_count
		movf	red_count,0
		btfsc	STATUS,2
		goto	red_leds_3		

		;----------------------- GREEN
green_leds	decfsz	green_count,1
		goto	next_leds
		btfsc	led_data,1	;GREEN OFF?
		goto	green_leds_2
green_leds_3	bsf	led_data,1	;GREEN ON
		movf	green_on,0
		movwf	green_count
		movf	green_count,0
		btfsc	STATUS,2
		goto	green_leds_2
		goto	next_leds
green_leds_2	bcf	led_data,1	;GREEN OFF
		movf	green_off,0
		movwf	green_count
		movf	green_count,0
		btfsc	STATUS,2
		goto	green_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	0efh
		movwf	PORTB

		call	timer0_set

		movlw	1Ch
		movwf	color_count
		call	auto_clear

		movlw	00h
		movwf	led_data	;RED OFF,GREEN OFF
		call	set_lo_leds
		movf	red_on,0
		movwf	red_count	;RED count data set
		movf	green_on,0
		movwf	green_count	;GREEN 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	0efh
		movwf	PORTB
		movlw	00h
		movwf	push_key
		nop
		sleep
		nop
		bcf	INTCON,RBIE
		nop
		bsf	INTCON,GIE
		nop
		bsf	INTCON,T0IE
		nop
;--------------------------------------- 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
		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	blue_led
		btfsc	push_key,1
		goto	red_led
;--------------------------------------
		goto	main_sleep
;--------------------------------------
blue_led
		btfss	led_data,0
		goto	blue_led_next
		bsf	PORTB,4
		nop
		goto	main_next
blue_led_next
		btfss	led_data,1
		goto	blue_led_off
		bsf	PORTB,4
		nop
		goto	main_next
blue_led_off
		bcf	PORTB,4
		nop
		goto	main_next
;--------------------------------------
red_led
		btfss	led_data,0
		goto	red_led_off
		bcf	PORTB,1
		nop
		bcf	PORTB,3
		nop
		goto	green_led
red_led_off
		bsf	PORTB,1
		nop
		bsf	PORTB,3
		nop
green_led
		btfss	led_data,1
		goto	green_led_off
		bcf	PORTB,0
		nop
		bcf	PORTB,2
		nop
		goto	main_next
green_led_off
		bsf	PORTB,0
		nop
		bsf	PORTB,2
		nop
;---------------------------------------
main_next
;--------------------------------------- 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
;-------------------------------------------------------------------------------
led_set		call	set_on_red
		movwf	red_on
		call	set_off_red
		movwf	red_off

		call	set_on_green
		movwf	green_on
		call	set_off_green
		movwf	green_off
		
		return
;--------------------------------------------------------------------------------
set_on_red	movf	color_count,0
		movwf	taihi
		movlw	low(red_on_table)
		addwf	taihi,1
		movlw	high(red_on_table)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
red_on_table	retlw	70h
		retlw	00h
		retlw	10h
		retlw	20h
		retlw	30h
		retlw	40h
		retlw	50h
		retlw	60h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	60h
		retlw	50h
		retlw	40h
		retlw	30h
		retlw	20h
		retlw	10h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	00h

set_off_red	movf	color_count,0
		movwf	taihi
		movlw	low(red_off_table)
		addwf	taihi,1
		movlw	high(red_off_table)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
red_off_table	retlw	00h
		retlw	70h
		retlw	60h
		retlw	50h
		retlw	40h
		retlw	30h
		retlw	20h
		retlw	10h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	10h
		retlw	20h
		retlw	30h
		retlw	40h
		retlw	50h
		retlw	60h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	70h
;--------------------------------------------------------------------------------
set_on_green	movf	color_count,0
		movwf	taihi
		movlw	low(green_on_table)
		addwf	taihi,1
		movlw	high(green_on_table)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
green_on_table	retlw	70h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	10h
		retlw	20h
		retlw	30h
		retlw	40h
		retlw	50h
		retlw	60h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	60h
		retlw	50h
		retlw	40h
		retlw	30h
		retlw	20h
		retlw	10h

set_off_green	movf	color_count,0
		movwf	taihi
		movlw	low(green_off_table)
		addwf	taihi,1
		movlw	high(green_off_table)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
green_off_table	retlw	00h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	70h
		retlw	60h
		retlw	50h
		retlw	40h
		retlw	30h
		retlw	20h
		retlw	10h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	00h
		retlw	10h
		retlw	20h
		retlw	30h
		retlw	40h
		retlw	50h
		retlw	60h

;-------------------------------------------------------------------------------
set_lo_leds	movlw	00h
		movwf	red_on
		movwf	green_on

		movlw	70h
		movwf	red_off
		movwf	green_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'
電子メッセンジャー「バルちゃん」の全HEXコード
:020000003A289C
:080008008C0003088D000B11B0
:10001000F3308100013093070318940A141C13284D
:10002000DC20E320D820990B242811181E28111455
:1000300020089900190803191E28242811102108E6
:1000400099001908031917289A0B352891182F2899
:10005000911422089A001A0803192F2835289110A4
:1000600023089A001A08031928280D0883008C0E0B
:100070000C0E09008F21FF308500EF3086009C2197
:100080001C309600D820003091008821200899006B
:1000900022089A008B1300008B1200000B11000045
:1000A0000B1000008B150000EF30860000309E0022
:1000B0000000630000008B1100008B1700008B16FE
:1000C0000000861A7128D220861A71281E14861EF6
:1000D00067288510000005110000051000000514B8
:1000E0008128061B8128D220061B81289E14061F0A
:1000F0007728851000000515000005100000051484
:1001000081281E1886289E1893284A28111C8B289F
:1001100006160000A928911C902806160000A928A0
:1001200006120000A928111C9A28861000008611CA
:1001300000009E288614000086150000911CA5284A
:100140000610000006110000A9280614000006157C
:100150000000861AB428D220861AB4281E1CB4289F
:100160001E10861EB128C328061BBF28D220061BDE
:10017000BF289E1CBF289E10061FBC28CB288519AF
:1001800081281E1CC92805100000051400008514D4
:100190004A289E1CD1280510000005140000851473
:1001A0004A284A28FF3095000000950BD428080003
:1001B000003093009400080096030319E02808001B
:1001C0001C3096000800EC20A0001321A1003A2169
:1001D000A2006121A300080016089700F6309707D7
:1001E00000308A0003188A0A17088200703400342D
:1001F000103420343034403450346034703470342F
:1002000070347034703470347034703460345034FE
:10021000403430342034103400340034003400349E
:10022000003400340034160897001D309707013061
:100230008A0003188A0A1708820000347034603478
:10024000503440343034203410340034003400341E
:10025000003400340034003400341034203430349E
:1002600040345034603470347034703470347034CE
:1002700070347034160897004430970701308A00B4
:1002800003188A0A170882007034003400340034DE
:10029000003400340034003400341034203430345E
:1002A000403450346034703470347034703470348E
:1002B000703470347034603450344034303420340E
:1002C0001034160897006B30970701308A00031826
:1002D0008A0A170882000034703470347034703425
:1002E000703470347034703460345034403430348E
:1002F000203410340034003400340034003400342E
:1003000000340034103420343034403450346034FD
:100310000030A000A2007030A100A30008008316E6
:10032000850185150000860186170000061700006C
:100330008616000083120800831683308100831222
:06034000F330810008000B
:02400E00F13F80
:00000001FF
電子メッセンジャー「バルちゃん」の完成
それではバル**星人の雄姿をごらん下さい。録音中は青色LEDのイルミネーションが不気味(?)に光ります。
バル**星人の目の光り具合はどうでしょうか。緑色から黄色、そして赤色に不気味に変化する目をお楽しみください。
さていかがでしたか?我が家ではこの「バルちゃん」が大人気です。思ったより音質が良いのにびっくりです。
また、目の光り方をもっと研究してみるのも面白いかもしれません。
さあ、次はどんな製作をしようかな?
これからも益々面白くなる「PIC16F84電子遊戯」をよろしくお願いいたします。

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

Copyright(c)2000-2001 nonchansoft