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

仮面ライダーシステム・その5の全ソースリスト
;**********************************************************************
;    Filename:      tiger.asm                                           *
;    Date:          2001/12/8                                         *
;    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  EYE LED
                                        ;led_data,1  BLUE LED
                                        ;led_data,2  GREEN LED
                                        ;led_data,3  RED 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
eye_count 	EQU     0x19            ;EYE LED count ram
blue_count	EQU     0x1a            ;BLUE LED count ram
green_count     EQU     0x1b            ;GREEN LED count ram
red_count	EQU     0x1c            ;RED LED count ram

shift_data	EQU	0x1e		;COLOR change
 
eye_on		EQU     0x20            ;EYE LED ON data ram
eye_off		EQU     0x21            ;EYE LED OFF data ram
blue_on		EQU     0x22            ;BLUE LED ON data ram
blue_off	EQU     0x23            ;BLUE LED OFF data ram
green_on	EQU     0x24            ;GREEN LED ON data ram
green_off	EQU     0x25            ;GREEN LED OFF data ram
red_on		EQU     0x26            ;RED LED ON data ram
red_off		EQU     0x27            ;RED 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    eye_leds
                call    led_change      
                call    led_set
                call    auto_clear
                ;----------------------- EYE
eye_leds	decfsz  eye_count,1
                goto    blue_leds
                btfsc   led_data,0      ;ATAMA OFF?
                goto    eye_leds_2
eye_leds_3	bsf     led_data,0      ;ATAMA ON
                movf    eye_on,0
                movwf   eye_count
                movf    eye_count,0
                btfsc   STATUS,2
                goto    eye_leds_2
                goto    blue_leds
eye_leds_2	bcf     led_data,0      ;ATAMA OFF
                movf    eye_off,0
                movwf   eye_count
                movf    eye_count,0
                btfsc   STATUS,2
                goto    eye_leds_3             
                ;----------------------- BLUE
blue_leds	decfsz  blue_count,1
                goto    green_leds
                btfsc   led_data,1      ;BLUE OFF?
                goto    blue_leds_2
blue_leds_3	bsf     led_data,1      ;BLUE ON
                movf    blue_on,0
                movwf   blue_count
                movf    blue_count,0
                btfsc   STATUS,2
                goto    blue_leds_2
                goto    green_leds
blue_leds_2	bcf     led_data,1      ;BLUE OFF
                movf    blue_off,0
                movwf   blue_count
                movf    blue_count,0
                btfsc   STATUS,2
                goto    blue_leds_3
                ;----------------------- GREEN
green_leds      decfsz  green_count,1
                goto    red_leds
                btfsc   led_data,2      ;GREEN OFF?
                goto    green_leds_2
green_leds_3    bsf     led_data,2      ;GREEN ON
                movf    green_on,0
                movwf   green_count
                movf    green_count,0
                btfsc   STATUS,2
                goto    green_leds_2
                goto    red_leds
green_leds_2    bcf     led_data,2      ;GREEN OFF
                movf    green_off,0
                movwf   green_count
                movf    green_count,0
                btfsc   STATUS,2
                goto    green_leds_3             
                ;----------------------- RED
red_leds       	decfsz  red_count,1
                goto    next_leds_2
                btfsc   led_data,3      ;RED OFF?
                goto    red_leds_2
red_leds_3	bsf     led_data,3      ;RED ON
                movf    red_on,0
                movwf   red_count
                movf    red_count,0
                btfsc   STATUS,2
                goto    red_leds_2
                goto    next_leds_2
red_leds_2 	bcf     led_data,3      ;RED OFF
                movf    red_off,0
                movwf   red_count
                movf    red_count,0
                btfsc   STATUS,2
                goto    red_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    eye_on,0
                movwf   eye_count	;EYE count data set
                movf    blue_on,0
                movwf   blue_count	;BLUE count data set
                movf    green_on,0
                movwf   green_count     ;GREEN count data set
                movf    red_on,0
                movwf   red_count	;RED 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	eye_led
		call	wait_1
		call	wait_1
		btfsc	PORTB,5
		goto	eye_led
		call	shift_change
main_keyp
		btfss	PORTB,5
		goto	main_keyp
;--------------------------------------
eye_led
                btfss   led_data,0
                goto    eye_led_off
                bsf     PORTB,0
                nop
                goto    blue_led
eye_led_off
                bcf     PORTB,0
                nop
;--------------------------------------
blue_led
                btfss   led_data,1
                goto    blue_led_off
                bsf     PORTB,1
                nop
                goto    green_led
blue_led_off
                bcf     PORTB,1
                nop
;---------------------------------------
green_led
                btfss   led_data,2
                goto    green_led_off
                bsf     PORTB,2
                nop
                goto    red_led
green_led_off
                bcf     PORTB,2
                nop
;---------------------------------------
red_led
                btfss   led_data,3
                goto    red_led_off
                bsf     PORTB,3
                nop
                goto    main_next_2
red_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,6
		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_eye
                movwf   eye_on
                sublw	70h
                movwf   eye_off

		btfsc	shift_data,0
		goto	led_set1
		btfsc	shift_data,1
		goto	led_set2
		btfsc	shift_data,2
		goto	led_set3
		btfsc	shift_data,3
		goto	led_set4
		btfsc	shift_data,4
		goto	led_set5
		btfsc	shift_data,5
		goto	led_set6
		goto	led_set7
 
led_set1        call    set_on_blue
                movwf   blue_on
                sublw	70h
                movwf   blue_off
                call    set_on_green
                movwf   green_on
                sublw	70h
                movwf   green_off
                call    set_on_red
                movwf   red_on
                sublw	70h
                movwf   red_off
                return

led_set2        call    set_on_blue
                movwf   green_on
                sublw	70h
                movwf   green_off
                call    set_on_green
                movwf   red_on
                sublw	70h
                movwf   red_off
                call    set_on_red
                movwf   blue_on
                sublw	70h
                movwf   blue_off
                return

led_set3        call    set_on_blue
                movwf   red_on
                sublw	70h
                movwf   red_off
                call    set_on_green
                movwf   blue_on
                sublw	70h
                movwf   blue_off
                call    set_on_red
                movwf   green_on
                sublw	70h
                movwf   green_off
                return

led_set4        call    set_on_blue
                movwf   blue_on
                sublw	70h
                movwf   blue_off
                call    set_on_green
                movwf   red_on
                sublw	70h
                movwf   red_off
                call    set_on_red
                movwf   green_on
                sublw	70h
                movwf   green_off
                return

led_set5        call    set_on_blue
                movwf   green_on
                sublw	70h
                movwf   green_off
                call    set_on_green
                movwf   blue_on
                sublw	70h
                movwf   blue_off
                call    set_on_red
                movwf   red_on
                sublw	70h
                movwf   red_off
                return

led_set6        call    set_on_blue
                movwf   red_on
                sublw	70h
                movwf   red_off
                call    set_on_green
                movwf   green_on
                sublw	70h
                movwf   green_off
                call    set_on_red
                movwf   blue_on
                sublw	70h
                movwf   blue_off
                return

led_set7        call    set_on_blue
                movwf   red_on
                sublw	70h
                movwf   red_off
                call    set_on_blue
                movwf   green_on
                sublw	70h
                movwf   green_off
                call    set_on_blue
                movwf   blue_on
                sublw	70h
                movwf   blue_off
                return

;--------------------------------------------------------------------------------
icnt_clear      movlw   00h
                movwf   int_count1
                movwf   int_count2
                movwf   int_count3
                return
;--------------------------------------------------------------------------------
set_on_eye	movf    color_count,0
                movwf   taihi
                movlw   low(eye_on_table)
                addwf   taihi,1
                movlw   high(eye_on_table)
                movwf   PCLATH
                addcf   PCLATH,1
                movf    taihi,0
                movwf   PCL
eye_on_table 	retlw   70h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   60h
                retlw   60h
                retlw   60h
                retlw   50h
                retlw   50h
                retlw   50h
                retlw   40h
                retlw   40h
                retlw   30h
                retlw   30h
                retlw   20h
                retlw   20h
                retlw   30h
                retlw   30h
                retlw   40h
                retlw   40h
                retlw   50h
                retlw   50h
                retlw   50h
                retlw   60h
                retlw   60h
                retlw   60h
                retlw   70h
                retlw   70h
                retlw   70h
;--------------------------------------------------------------------------------
set_on_blue	movf    color_count,0
                movwf   taihi
                movlw   low(blue_on_table)
                addwf   taihi,1
                movlw   high(blue_on_table)
                movwf   PCLATH
                addcf   PCLATH,1
                movf    taihi,0
                movwf   PCL
blue_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_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   10h
                retlw   20h
                retlw   20h
                retlw   30h
                retlw   30h
                retlw   40h
                retlw   30h
                retlw   30h
                retlw   20h
                retlw   20h
                retlw   10h
                retlw   10h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
;--------------------------------------------------------------------------------
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   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
;-------------------------------------------------------------------------------
set_lo_leds     movlw   00h
                movwf   eye_on
                movwf   blue_on
                movwf   green_on
                movwf   red_on
 
                movlw   70h
                movwf   eye_off
                movwf   blue_off
                movwf   green_off
                movwf   red_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