PIC16F84電子遊戯(23)サブページ
最終更新日:2001年5月4日
マトリックス64(1ページ)へ (2ページ)へ (3ページ)へ

マトリックス64(電光掲示板)全ソースリスト公開
;**********************************************************************
;    Filename:	    matrix4.asm                                       *
;    Date:          2001/5/1                                        *
;    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

wait_data		EQU	0x10		;wait data
count_sub		EQU	0x11		;count sub data
count_sub2	EQU	0x12		;count sub2 data

taihi		EQU	0x13		;taihi data
moji_mode		EQU	0x14		;moji mode ram

count_data	EQU	0x15		;0.5sec keisoku count ram

led_data0		EQU	0x20		;LED DATA(0)
led_data1		EQU	0x21		;LED DATA(1)
led_data2		EQU	0x22		;LED DATA(2)
led_data3		EQU	0x23		;LED DATA(3)
led_data4		EQU	0x24		;LED DATA(4)
led_data5		EQU	0x25		;LED DATA(5)
led_data6		EQU	0x26		;LED DATA(6)
led_data7		EQU	0x27		;LED DATA(7)

tm0_setdata	EQU	63h		;255-156=99=63H  156*128=19.968msec
cnt_setdata	EQU	19h		;19.968*25=0.4992sec

moji_A		EQU	01h
moji_B		EQU	02h
moji_C		EQU	03h
moji_D		EQU	04h
moji_E		EQU	05h
moji_F		EQU	06h
moji_G		EQU	07h
moji_H		EQU	08h
moji_I		EQU	09h
moji_J		EQU	0ah
moji_K		EQU	0bh
moji_L		EQU	0ch
moji_M		EQU	0dh
moji_N		EQU	0eh
moji_O		EQU	0fh
moji_P		EQU	10h
moji_Q		EQU	11h
moji_R		EQU	12h
moji_S		EQU	13h
moji_T		EQU	14h
moji_U		EQU	15h
moji_V		EQU	16h
moji_W		EQU	17h
moji_X		EQU	18h
moji_Y		EQU	19h
moji_Z		EQU	1ah
moji_sp		EQU	1bh
moji_mk		EQU	1ch
moji_love		EQU	1dh
moji_1		EQU	1eh
moji_2		EQU	1fh
moji_3		EQU	20h
moji_4		EQU	21h
moji_5		EQU	22h
moji_6		EQU	23h
moji_7		EQU	24h
moji_8		EQU	25h
moji_9		EQU	26h
moji_0		EQU	27h
moji_co		EQU	28h
moji_kara		EQU	29h
;**********************************************************************
		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

		decfsz	count_data,1
		goto	int_end
time_up		movlw	cnt_setdata		
		movwf	count_data
		;--------------------------------
		incf	count_sub2,1	

int_next3		movf	count_sub2,0
		call	moji_set
		movwf	count_sub
		movf	count_sub,0
		skpz
		goto	int_next2
		call	count_init
		goto	int_next3
		;--------------------------------
int_next2		call	led_set_sub

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	00h		;port initial set
		movwf	PORTA
		movlw	0ffh
		movwf	PORTB

		movlw	01h
		movwf	moji_mode

		call	count_init
		movf	count_sub2,0
		call	moji_set
		movwf	count_sub
		call	led_set_sub

		call	timer0_set
		movlw	cnt_setdata
		movwf	count_data

main_loop
;-------------------------------------- key scan
sw1_key		btfsc	PORTA,3
		goto	next_key
		call	wait_1
		btfsc	PORTA,3
		goto	next_key
					;sw1 on
		call	moji_shift
		call	count_init
		movf	count_sub2,0
		call	moji_set
		movwf	count_sub
		
sw1_end		btfss	PORTA,3
		goto	sw1_end
next_key
;-------------------------------------- led disp
		movlw	00h
		movwf	PORTA
		movf	led_data0,0
		movwf	PORTB
		call	wait_1

		movlw	01h
		movwf	PORTA
		movf	led_data1,0
		movwf	PORTB
		call	wait_1

		movlw	02h
		movwf	PORTA
		movf	led_data2,0
		movwf	PORTB
		call	wait_1

		movlw	03h
		movwf	PORTA
		movf	led_data3,0
		movwf	PORTB
		call	wait_1

		movlw	04h
		movwf	PORTA
		movf	led_data4,0
		movwf	PORTB
		call	wait_1

		movlw	05h
		movwf	PORTA
		movf	led_data5,0
		movwf	PORTB
		call	wait_1

		movlw	06h
		movwf	PORTA
		movf	led_data6,0
		movwf	PORTB
		call	wait_1

		movlw	07h
		movwf	PORTA
		movf	led_data7,0
		movwf	PORTB
		call	wait_1
;---------------------------------------
main_next
		goto	main_loop
;-------------------------------------------------------------------------------
led_set_sub	movf	count_sub,0
		call	led_data_line0
		movwf	led_data0
		movf	count_sub,0
		call	led_data_line1
		movwf	led_data1
		movf	count_sub,0
		call	led_data_line2
		movwf	led_data2
		movf	count_sub,0
		call	led_data_line3
		movwf	led_data3
		movf	count_sub,0
		call	led_data_line4
		movwf	led_data4
		movf	count_sub,0
		call	led_data_line5
		movwf	led_data5
		movf	count_sub,0
		call	led_data_line6
		movwf	led_data6
		movf	count_sub,0
		call	led_data_line7
		movwf	led_data7
		return
;-------------------------------------------------------------------------------
count_init	movlw	00h
		movwf	count_sub2
		return
;-------------------------------------------------------------------------------
moji_shift	btfss	moji_mode,3
		goto	moji_shift2
		movlw	01h
		movwf	moji_mode
		return
moji_shift2	rlf	moji_mode,1
		bcf	moji_mode,0
		return		
;-------------------------------------------------------------------------------
moji_set		btfsc	moji_mode,0
		goto	moji_set0
		btfsc	moji_mode,1
		goto	moji_set1
		btfsc	moji_mode,2
		goto	moji_set2
		goto	moji_set3
;-------------------------------------------------------------------------------
moji_set0		movwf	taihi
		movlw	low(moji0)
		addwf	taihi,1
		movlw	high(moji0)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
moji0		retlw	moji_I
		retlw	moji_love
		retlw	moji_Y
		retlw	moji_O
		retlw	moji_U
		retlw	moji_mk
		retlw	moji_sp
		retlw	00h
;-------------------------------------------------------------------------------
moji_set1		movwf	taihi
		movlw	low(moji1)
		addwf	taihi,1
		movlw	high(moji1)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
moji1		retlw	moji_N
		retlw	moji_O
		retlw	moji_N
		retlw	moji_C
		retlw	moji_H
		retlw	moji_A
		retlw	moji_N
		retlw	moji_S
		retlw	moji_O
		retlw	moji_F
		retlw	moji_T
		retlw	moji_sp
		retlw	00h
;-------------------------------------------------------------------------------
moji_set2		movwf	taihi
		movlw	low(moji2)
		addwf	taihi,1
		movlw	high(moji2)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
moji2		retlw	moji_0
		retlw	moji_1
		retlw	moji_2
		retlw	moji_3
		retlw	moji_4
		retlw	moji_5
		retlw	moji_6
		retlw	moji_7
		retlw	moji_8
		retlw	moji_9
		retlw	moji_sp
		retlw	00h
;-------------------------------------------------------------------------------
moji_set3		movwf	taihi
		movlw	low(moji3)
		addwf	taihi,1
		movlw	high(moji3)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
moji3		retlw	moji_O
		retlw	moji_P
		retlw	moji_E
		retlw	moji_N
		retlw	moji_mk
		retlw	moji_A
		retlw	moji_M
		retlw	moji_9
		retlw	moji_co
		retlw	moji_2
		retlw	moji_7
		retlw	moji_kara
		retlw	moji_P
		retlw	moji_M
		retlw	moji_1
		retlw	moji_0
		retlw	moji_co
		retlw	moji_5
		retlw	moji_8
		retlw	moji_sp
		retlw	00h								
;-------------------------------------------------------------------------------
led_data_line0	movwf	taihi
		movlw	low(table0)
		addwf	taihi,1
		movlw	high(table0)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
table0		retlw	00h		;
		retlw	03h		;A
		retlw	00h		;B
		retlw	81h		;C
		retlw	00h		;D
		retlw	00h		;E
		retlw	00h		;F
		retlw	81h		;G
		retlw	00h		;H
		retlw	0ffh		;I
		retlw	9fh		;J
		retlw	00h		;K
		retlw	00h		;L
		retlw	00h		;M
		retlw	00h		;N
		retlw	81h		;O
		retlw	00h		;P
		retlw	81h		;Q
		retlw	00h		;R
		retlw	0b9h		;S
		retlw	0feh		;T
		retlw	80h		;U
		retlw	0f8h		;V
		retlw	80h		;W
		retlw	3ch		;X
		retlw	0f8		;Y
		retlw	3eh		;Z
		retlw	0ffh		;
		retlw	3fh		;!
		retlw	0e1h		;love
		retlw	0ffh		;1
		retlw	39h		;2
		retlw	99h		;3
		retlw	0c7h		;4
		retlw	90h		;5
		retlw	81h		;6
		retlw	0f8h		;7
		retlw	99h		;8
		retlw	0b1h		;9
		retlw	81h		;0
		retlw	0ffh		;:
		retlw	0e7h		;~
;-------------------------------------------------------------------------------
led_data_line1	movwf	taihi
		movlw	low(table1)
		addwf	taihi,1
		movlw	high(table1)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
table1		retlw	00h		;
		retlw	01h		;A
		retlw	00h		;B
		retlw	00h		;C
		retlw	00h		;D
		retlw	00h		;E
		retlw	00h		;F
		retlw	00h		;G
		retlw	00h		;H
		retlw	0ffh		;I
		retlw	1fh		;J
		retlw	00h		;K
		retlw	00h		;L
		retlw	00h		;M
		retlw	00h		;N
		retlw	00h		;O
		retlw	00h		;P
		retlw	00h		;Q
		retlw	00h		;R
		retlw	30h		;S
		retlw	0feh		;T
		retlw	00h		;U
		retlw	0e0h		;V
		retlw	00h		;W
		retlw	18h		;X
		retlw	0f0h		;Y
		retlw	1eh		;Z
		retlw	0ffh		;
		retlw	3fh		;!
		retlw	0c0h		;love
		retlw	0ffh		;1
		retlw	18h		;2
		retlw	18h		;3
		retlw	0c1h		;4
		retlw	10h		;5
		retlw	00h		;6
		retlw	0f8h		;7
		retlw	00h		;8
		retlw	20h		;9
		retlw	00h		;0
		retlw	0ffh		;:
		retlw	0f3h		;~
;-------------------------------------------------------------------------------
led_data_line2	movwf	taihi
		movlw	low(table2)
		addwf	taihi,1
		movlw	high(table2)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
table2		retlw	00h		;
		retlw	0cch		;A
		retlw	66h		;B
		retlw	3ch		;C
		retlw	7eh		;D
		retlw	66h		;E
		retlw	0e6h		;F
		retlw	3ch		;G
		retlw	0e7h		;H
		retlw	7eh		;I
		retlw	3fh		;J
		retlw	0e7h		;K
		retlw	7fh		;L
		retlw	0f9h		;M
		retlw	0f1h		;N
		retlw	3ch		;O
		retlw	0e6h		;P
		retlw	3ch		;Q
		retlw	0e6h		;R
		retlw	60h		;S
		retlw	0feh		;T
		retlw	3fh		;U
		retlw	83h		;V
		retlw	1fh		;W
		retlw	81h		;X
		retlw	0e3h		;Y
		retlw	0eh		;Z
		retlw	0ffh		;
		retlw	0cfh		;!
		retlw	80h		;love
		retlw	7ch		;1
		retlw	1ch		;2
		retlw	7eh		;3
		retlw	0d8h		;4
		retlw	76h		;5
		retlw	66h		;6
		retlw	0feh		;7
		retlw	66h		;8
		retlw	66h		;9
		retlw	3ch		;0
		retlw	0ffh		;:
		retlw	0f3h		;~
;-------------------------------------------------------------------------------
led_data_line3	movwf	taihi
		movlw	low(table3)
		addwf	taihi,1
		movlw	high(table3)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
table3		retlw	00h		;
		retlw	0cch		;A
		retlw	66h		;B
		retlw	7eh		;C
		retlw	7eh		;D
		retlw	66h		;E
		retlw	0e6h		;F
		retlw	7eh		;G
		retlw	0e7h		;H
		retlw	00h		;I
		retlw	7fh		;J
		retlw	0c3h		;K
		retlw	7fh		;L
		retlw	0e3h		;M
		retlw	0e3h		;N
		retlw	7eh		;O
		retlw	0e6h		;P
		retlw	7eh		;Q
		retlw	0c6h		;R
		retlw	66h		;S
		retlw	00h		;T
		retlw	7fh		;U
		retlw	0fh		;V
		retlw	83h		;W
		retlw	0c3h		;X
		retlw	07h		;Y
		retlw	46h		;Z
		retlw	0ffh		;
		retlw	0c3h		;!
		retlw	01h		;love
		retlw	00h		;1
		retlw	4eh		;2
		retlw	66h		;3
		retlw	0deh		;4
		retlw	76h		;5
		retlw	66h		;6
		retlw	0eh		;7
		retlw	66h		;8
		retlw	66h		;9
		retlw	6eh		;0
		retlw	99h		;:
		retlw	0e3h		;~
;-------------------------------------------------------------------------------
led_data_line4	movwf	taihi
		movlw	low(table4)
		addwf	taihi,1
		movlw	high(table4)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
table4		retlw	00h		;
		retlw	0cch		;A
		retlw	66h		;B
		retlw	7eh		;C
		retlw	7eh		;D
		retlw	66h		;E
		retlw	0e6h		;F
		retlw	66h		;G
		retlw	0e7h		;H
		retlw	00h		;I
		retlw	7eh		;J
		retlw	81h		;K
		retlw	7fh		;L
		retlw	0e3h		;M
		retlw	0c7h		;N
		retlw	7eh		;O
		retlw	0e6h		;P
		retlw	4eh		;Q
		retlw	86h		;R
		retlw	66h		;S
		retlw	00h		;T
		retlw	7fh		;U
		retlw	0fh		;V
		retlw	83h		;W
		retlw	0c3h		;X
		retlw	07h		;Y
		retlw	62h		;Z
		retlw	0ffh		;
		retlw	0e1h		;!
		retlw	01h		;love
		retlw	00h		;1
		retlw	4eh		;2
		retlw	66h		;3
		retlw	00h		;4
		retlw	76h		;5
		retlw	66h		;6
		retlw	06h		;7
		retlw	66h		;8
		retlw	66h		;9
		retlw	76h		;0
		retlw	99h		;:
		retlw	0c7h		;~
;-------------------------------------------------------------------------------
led_data_line5	movwf	taihi
		movlw	low(table5)
		addwf	taihi,1
		movlw	high(table5)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
table5		retlw	00h		;
		retlw	0cch		;A
		retlw	00h		;B
		retlw	3ch		;C
		retlw	3ch		;D
		retlw	66h		;E
		retlw	0e6h		;F
		retlw	24h		;G
		retlw	0e7h		;H
		retlw	7eh		;I
		retlw	3eh		;J
		retlw	18h		;K
		retlw	7fh		;L
		retlw	0f9h		;M
		retlw	8fh		;N
		retlw	3ch		;O
		retlw	0e6h		;P
		retlw	1ch		;Q
		retlw	06h		;R
		retlw	06h		;S
		retlw	0feh		;T
		retlw	3fh		;U
		retlw	83h		;V
		retlw	1fh		;W
		retlw	81h		;X
		retlw	0e3h		;Y
		retlw	70h		;Z
		retlw	0ffh		;
		retlw	0e0h		;!
		retlw	80h		;love
		retlw	7fh		;1
		retlw	64h		;2
		retlw	00h		;3
		retlw	00h		;4
		retlw	26h		;5
		retlw	66h		;6
		retlw	0e2h		;7
		retlw	66h		;8
		retlw	66h		;9
		retlw	3ch		;0
		retlw	0ffh		;:
		retlw	0cfh		;~
;-------------------------------------------------------------------------------
led_data_line6	movwf	taihi
		movlw	low(table6)
		addwf	taihi,1
		movlw	high(table6)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
table6		retlw	00h		;
		retlw	01h		;A
		retlw	00h		;B
		retlw	18h		;C
		retlw	00h		;D
		retlw	66h		;E
		retlw	0e6h		;F
		retlw	04h		;G
		retlw	00h		;H
		retlw	0ffh		;I
		retlw	00h		;J
		retlw	3ch		;K
		retlw	7fh		;L
		retlw	00h		;M
		retlw	00h		;N
		retlw	00h		;O
		retlw	0e0h		;P
		retlw	00h		;Q
		retlw	20h		;R
		retlw	0ch		;S
		retlw	0feh		;T
		retlw	00h		;U
		retlw	0e0h		;V
		retlw	00h		;W
		retlw	18h		;X
		retlw	0f0h		;Y
		retlw	78h		;Z
		retlw	0ffh		;
		retlw	0f0h		;!
		retlw	0c0h		;love
		retlw	0ffh		;1
		retlw	60h		;2
		retlw	00h		;3
		retlw	0dfh		;4
		retlw	06h		;5
		retlw	04h		;6
		retlw	0f0h		;7
		retlw	00h		;8
		retlw	00h		;9
		retlw	00h		;0
		retlw	0ffh		;:
		retlw	0cfh		;~
;-------------------------------------------------------------------------------
led_data_line7	movwf	taihi
		movlw	low(table7)
		addwf	taihi,1
		movlw	high(table7)
		movwf	PCLATH
		addcf	PCLATH,1
		movf	taihi,0
		movwf	PCL
table7		retlw	00h		;
		retlw	03h		;A
		retlw	99h		;B
		retlw	99h		;C
		retlw	81h		;D
		retlw	7eh		;E
		retlw	0feh		;F
		retlw	8dh		;G
		retlw	00h		;H
		retlw	0ffh		;I
		retlw	80h		;J
		retlw	7eh		;K
		retlw	7fh		;L
		retlw	00h		;M
		retlw	00h		;N
		retlw	81h		;O
		retlw	0f1h		;P
		retlw	81h		;Q
		retlw	71h		;R
		retlw	9dh		;S
		retlw	0feh		;T
		retlw	80h		;U
		retlw	0f8h		;V
		retlw	80h		;W
		retlw	3ch		;X
		retlw	0f8h		;Y
		retlw	7ch		;Z
		retlw	0ffh		;
		retlw	0f8h		;!
		retlw	0e1h		;love
		retlw	0ffh		;1
		retlw	71h		;2
		retlw	99h		;3
		retlw	0dfh		;4
		retlw	8eh		;5
		retlw	8dh		;6
		retlw	0f8h		;7
		retlw	99h		;8
		retlw	81h		;9
		retlw	81h		;0
		retlw	0ffh		;:
		retlw	0e7h		;~
;-------------------------------------------------------------------------------
wait_1		
		movlw	0ffh
		movwf	wait_data
wait_2
		decfsz	wait_data,1
		goto	wait_2
		return
;-------------------------------------------------------------------------------
port_set				;RA0,RA1,RA2,RA4(OUT)
					;RA3(IN)
					;RB0,RB1,RB2,RB3,RB4,RB5,RB6,RB7(OUT)
		bsf	STATUS,RP0
		clrf	TRISA
		bsf	TRISA,3
		nop
		clrf	TRISB
		bcf	STATUS,RP0
		return
;-------------------------------------------------------------------------------
timer0_set
		bsf	STATUS,RP0
		movlw	086h		;(1)PORTB NOT PULLUP
					;(0)INTEDG
					;(0)TOCS
					;(0)TOSE
					;(0)PSA
					;(110)1/128
		movwf	OPTION_REG
		bcf	STATUS,RP0
		
		movlw	tm0_setdata
		movwf	TMR0
		bsf	INTCON,T0IE
		bsf	INTCON,GIE
		return
;-----------------------------------------------------------------------------
		END                     ; directive 'end of program'
(3ページ)へ戻る

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