PIC16F84電子遊戯(61)サブページ
最終更新日:2002年2月9日
仮面ライダーシステム・その6(1ページ)へ (2ページ)へ (3ページ)へ

仮面ライダーシステム・その6の全ソースリスト
;**********************************************************************
;    Filename:      shadow.asm                                           *
;    Date:          2002/1/20                                         *
;    File Version:                                                    *
;**********************************************************************
 
         list      p=16F84             ; list directive to define processor
         #include <p16F84.inc>         ; processor specific variable definitions
         LIST
; P16F84.INC  Standard Header File, Version 2.00    Microchip Technology, Inc.
         LIST
  
         __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  EYE1 LED
                                        ;led_data,1  EYE2 LED
                                        ;led_data,2  BELT1 LED
                                        ;led_data,3  BELT2 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
wait_data2	EQU	0x18		;wait data2 ram
eye1_count      EQU     0x19            ;EYE1 LED count ram
eye2_count	EQU     0x1a            ;EYE2 LED count ram
belt1_count     EQU     0x1b            ;BELT1 LED count ram
belt2_count	EQU     0x1c            ;BELT2 LED count ram

shift_data	EQU	0x1e		;COLOR change
 
eye1_on		EQU     0x20            ;EYE1 LED ON data ram
eye1_off	EQU     0x21            ;EYE1 LED OFF data ram
eye2_on		EQU     0x22            ;EYE2 LED ON data ram
eye2_off	EQU     0x23            ;EYE2 LED OFF data ram
belt1_on	EQU     0x24            ;BELT1 LED ON data ram
belt1_off	EQU     0x25            ;BELT1 LED OFF data ram
belt2_on	EQU     0x26            ;BELT2 LED ON data ram
belt2_off	EQU     0x27            ;BELT2 LED OFF data ram
 
int_count1      EQU     0x2d            ;int count1
int_count2      EQU     0x2e            ;int count2
int_count3      EQU     0x2f            ;int count3
 
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
                addwf   int_count1,1
                btfss   STATUS,0
                goto    int_next2
                movlw   01h
                addwf   int_count2,1
                btfsc   STATUS,0
                incf    int_count3,1
                ;---------------------------------
int_next2
                movlw   01h             ;LED mode auto shori
                addwf   acount1,1
                btfsc   STATUS,0
                incf    acount2,1
                btfss   acount2,0       ;
                goto    eye1_leds
                call    led_change      
                call    led_set
                call    auto_clear
                ;----------------------- EYE1
eye1_leds	decfsz  eye1_count,1
                goto    eye2_leds
                btfsc   led_data,0      ;EYE1 OFF?
                goto    eye1_leds_2
eye1_leds_3	bsf     led_data,0      ;EYE1 ON
                movf    eye1_on,0
                movwf   eye1_count
                movf    eye1_count,0
                btfsc   STATUS,2
                goto    eye1_leds_2
                goto    eye2_leds
eye1_leds_2	bcf     led_data,0      ;EYE1 OFF
                movf    eye1_off,0
                movwf   eye1_count
                movf    eye1_count,0
                btfsc   STATUS,2
                goto    eye1_leds_3             
                ;----------------------- EYE2
eye2_leds	decfsz  eye2_count,1
                goto    belt1_leds
                btfsc   led_data,1      ;EYE2 OFF?
                goto    eye2_leds_2
eye2_leds_3	bsf     led_data,1      ;EYE2 ON
                movf    eye2_on,0
                movwf   eye2_count
                movf    eye2_count,0
                btfsc   STATUS,2
                goto    eye2_leds_2
                goto    belt1_leds
eye2_leds_2	bcf     led_data,1      ;EYE2 OFF
                movf    eye2_off,0
                movwf   eye2_count
                movf    eye2_count,0
                btfsc   STATUS,2
                goto    eye2_leds_3
                ;----------------------- BELT1
belt1_leds      decfsz  belt1_count,1
                goto    belt2_leds
                btfsc   led_data,2      ;BELT1 OFF?
                goto    belt1_leds_2
belt1_leds_3    bsf     led_data,2      ;BELT1 ON
                movf    belt1_on,0
                movwf   belt1_count
                movf    belt1_count,0
                btfsc   STATUS,2
                goto    belt1_leds_2
                goto    belt2_leds
belt1_leds_2    bcf     led_data,2      ;BELT1 OFF
                movf    belt1_off,0
                movwf   belt1_count
                movf    belt1_count,0
                btfsc   STATUS,2
                goto    belt1_leds_3             
                ;----------------------- BELT2
belt2_leds      decfsz  belt2_count,1
                goto    next_leds_2
                btfsc   led_data,3      ;BELT2 OFF?
                goto    belt2_leds_2
belt2_leds_3    bsf     led_data,3      ;BELT2 ON
                movf    belt2_on,0
                movwf   belt2_count
                movf    belt2_count,0
                btfsc   STATUS,2
                goto    belt2_leds_2
                goto    next_leds_2
belt2_leds_2    bcf     led_data,3      ;BELT2 OFF
                movf    belt2_off,0
                movwf   belt2_count
                movf    belt2_count,0
                btfsc   STATUS,2
                goto    belt2_leds_3
                ;----------------------------------
next_leds_2

                ;----------------------------------
next_leds_3
                ;----------------------------------
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
                movwf   PORTA
                movlw   0e0h
                movwf   PORTB
 
                call    timer0_set
 
                movlw   1Ch
                movwf   color_count
                call    auto_clear

		movlw	01h
		movwf	shift_data
 
                movlw   00h
                movwf   led_data        ;LED ALL OFF
                call    set_lo_leds
                movf    eye1_on,0
                movwf   eye1_count 	;EYE1 count data set
                movf    eye2_on,0
                movwf   eye2_count	;EYE2 count data set
                movf    belt1_on,0
                movwf   belt1_count     ;BELT1 count data set
                movf    belt2_on,0
                movwf   belt2_count	;BELT2 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
                call    icnt_clear
                movlw   0e0h
                movwf   PORTB
                nop
                sleep
                nop
                bcf     INTCON,RBIE
                nop
                bsf     INTCON,GIE
                nop
                bsf     INTCON,T0IE
                nop
		call	out1_out
;--------------------------------------
main_loop
                btfsc   int_count3,1
                goto    main_sleep2
;--------------------------------------
main_key
		btfsc	PORTB,5
		goto	eye1_led
		call	wait_1
		call	wait_1
		btfsc	PORTB,5
		goto	eye1_led
		call	shift_change
main_keyp
		btfss	PORTB,5
		goto	main_keyp
;--------------------------------------
eye1_led
                btfss   led_data,0
                goto    eye1_led_off
                bsf     PORTB,0
                nop
                goto    eye2_led
eye1_led_off
                bcf     PORTB,0
                nop
eye2_led
                btfss   led_data,1
                goto    eye2_led_off
                bsf     PORTB,1
                nop
                goto    belt1_led
eye2_led_off
                bcf     PORTB,1
                nop
;---------------------------------------
belt1_led
                btfss   led_data,2
                goto    belt1_led_off
                bsf     PORTB,2
                nop
                goto    belt2_led
belt1_led_off
                bcf     PORTB,2
                nop
belt2_led
                btfss   led_data,3
                goto    belt2_led_off
                bsf     PORTB,3
                nop
                goto    main_next_2
belt2_led_off
                bcf     PORTB,3
                nop
;--------------------------------------
main_next_2
;--------------------------------------
main_next_3
                goto    main_loop
;--------------------------------------
main_sleep2
		call	out2_out
		goto	main_sleep
;-------------------------------------------------------------------------------
out1_out
		bsf	PORTA,0
		nop
		call	wait_1
		call	wait_1
		call	wait_1
		bcf	PORTA,0
		nop
		return
out2_out
		bsf	PORTA,1
		nop
		call	wait_1
		call	wait_1
		call	wait_1
		bcf	PORTA,1
		nop
		return
;-------------------------------------------------------------------------------
wait_1          
                movlw   0ffh
                movwf   wait_data
wait_2
                nop
                decfsz  wait_data,1
                goto    wait_2
                return
;-------------------------------------------------------------------------------
shift_change
		btfss	shift_data,3
		goto	shift_change2
		movlw	01h
		movwf	shift_data
		return
shift_change2
		bcf	STATUS,0
		rlf	shift_data,1
		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_eye1
                movwf   eye1_on
                sublw	70h
                movwf   eye1_off
 
                call    set_on_eye2
                movwf   eye2_on
                sublw	70h
                movwf   eye2_off

                call    set_on_belt2
                movwf   belt2_on
                sublw	70h
                movwf   belt2_off

		btfsc	shift_data,0
		goto	led_set1
		btfsc	shift_data,1
		goto	led_set2
		btfsc	shift_data,2
		goto	led_set3
		goto	led_set4

led_set1
	        call    set_on_belt10
                movwf   belt1_on
                sublw	70h
                movwf   belt1_off
                return

led_set2
	        call    set_on_belt11
                movwf   belt1_on
                sublw	70h
                movwf   belt1_off
                return

led_set3
	        call    set_on_belt12
                movwf   belt1_on
                sublw	70h
                movwf   belt1_off
                return

led_set4
	        call    set_on_belt13
                movwf   belt1_on
                sublw	70h
                movwf   belt1_off
                return

;--------------------------------------------------------------------------------
icnt_clear      movlw   00h
                movwf   int_count1
                movwf   int_count2
                movwf   int_count3
                return
;--------------------------------------------------------------------------------
set_on_eye1     movf    color_count,0
                movwf   taihi
                movlw   low(eye1_on_table)
                addwf   taihi,1
                movlw   high(eye1_on_table)
                movwf   PCLATH
                addcf   PCLATH,1
                movf    taihi,0
                movwf   PCL
eye1_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   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_on_eye2     movf    color_count,0
                movwf   taihi
                movlw   low(eye2_on_table)
                addwf   taihi,1
                movlw   high(eye2_on_table)
                movwf   PCLATH
                addcf   PCLATH,1
                movf    taihi,0
                movwf   PCL
eye2_on_table   retlw   70h
                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   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_belt2    movf    color_count,0
                movwf   taihi
                movlw   low(belt2_on_table)
                addwf   taihi,1
                movlw   high(belt2_on_table)
                movwf   PCLATH
                addcf   PCLATH,1
                movf    taihi,0
                movwf   PCL
belt2_on_table  retlw   70h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   50h
                retlw   20h
                retlw   00h
                retlw   20h
                retlw   50h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   50h
                retlw   20h
                retlw   00h
                retlw   20h
                retlw   50h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   50h
                retlw   20h
                retlw   00h
                retlw   20h
                retlw   50h
                retlw   70h
                retlw   70h
;--------------------------------------------------------------------------------
set_on_belt10
		movf    color_count,0
                movwf   taihi
                movlw   low(belt10_on_table)
                addwf   taihi,1
                movlw   high(belt10_on_table)
                movwf   PCLATH
                addcf   PCLATH,1
                movf    taihi,0
                movwf   PCL
belt10_on_table
		retlw   70h
                retlw   50h
                retlw   40h
                retlw   40h
                retlw   30h
                retlw   30h
                retlw   20h
                retlw   20h
                retlw   10h
                retlw   10h
                retlw   00h
                retlw   00h
                retlw   10h
                retlw   10h
                retlw   20h
                retlw   20h
                retlw   30h
                retlw   30h
                retlw   40h
                retlw   40h
                retlw   50h
                retlw   50h
                retlw   60h
                retlw   60h
                retlw   70h
                retlw   70h
                retlw   60h
                retlw   60h
                retlw   50h

set_on_belt11
		movf    color_count,0
                movwf   taihi
                movlw   low(belt11_on_table)
                addwf   taihi,1
                movlw   high(belt11_on_table)
                movwf   PCLATH
                addcf   PCLATH,1
                movf    taihi,0
                movwf   PCL
belt11_on_table
		retlw   70h
                retlw   70h
                retlw   40h
                retlw   00h
                retlw   70h
                retlw   40h
                retlw   00h
                retlw   70h
                retlw   40h
                retlw   00h
                retlw   70h
                retlw   40h
                retlw   00h
                retlw   70h
                retlw   40h
                retlw   00h
                retlw   70h
                retlw   40h
                retlw   00h
                retlw   70h
                retlw   40h
                retlw   00h
                retlw   70h
                retlw   40h
                retlw   00h
                retlw   70h
                retlw   40h
                retlw   00h
                retlw   00h

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

set_on_belt13
		movf    color_count,0
                movwf   taihi
                movlw   low(belt13_on_table)
                addwf   taihi,1
                movlw   high(belt13_on_table)
                movwf   PCLATH
                addcf   PCLATH,1
                movf    taihi,0
                movwf   PCL
belt13_on_table
		retlw   70h
                retlw   10h
                retlw   20h
                retlw   30h
                retlw   40h
                retlw   50h
                retlw   10h
                retlw   20h
                retlw   30h
                retlw   40h
                retlw   50h
                retlw   10h
                retlw   20h
                retlw   30h
                retlw   40h
                retlw   50h
                retlw   10h
                retlw   20h
                retlw   30h
                retlw   40h
                retlw   50h
                retlw   10h
                retlw   20h
                retlw   30h
                retlw   40h
                retlw   50h
                retlw   00h
                retlw   00h
                retlw   00h
;-------------------------------------------------------------------------------
set_lo_leds     movlw   00h
                movwf   eye1_on
                movwf   eye2_on
                movwf   belt1_on
                movwf   belt2_on
 
                movlw   70h
                movwf   eye1_off
                movwf   eye2_off
                movwf   belt1_off
                movwf   belt2_off

                return
;-------------------------------------------------------------------------------
port_set                                ;RA0,RA1,RA2,RA3,RA4(OUT)
                                        ;RB0,RB1,RB2,RB3,RB4(OUT)
                                        ;RB5,RB6,RB7(IN)
                bsf     STATUS,RP0
                clrf    TRISA
                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