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

仮面ライダーシステム・その3の全ソースリスト公開
;**********************************************************************
;    Filename:      agito.asm                                           *
;    Date:          2001/11/10                                         *
;    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  ATAMA LED
                                        ;led_data,1  BELT LED
                                        ;led_data,2  RIGHT LED
                                        ;led_data,3  LEFT 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
atama_count     EQU     0x19            ;ATAMA LED count ram
belt_count	EQU     0x1a            ;BELT LED count ram
right_count     EQU     0x1b            ;RIGHT LED count ram
left_count	EQU     0x1c            ;LEFT LED count ram
 
atama_on	EQU     0x20            ;ATAMA LED ON data ram
atama_off	EQU     0x21            ;ATAMA LED OFF data ram
belt_on		EQU     0x22            ;BELT LED ON data ram
belt_off	EQU     0x23            ;BELT LED OFF data ram
right_on	EQU     0x24            ;RIGHT LED ON data ram
right_off	EQU     0x25            ;RIGHT LED OFF data ram
left_on		EQU     0x26            ;LEFT LED ON data ram
left_off	EQU     0x27            ;LEFT 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    atama_leds
                call    led_change      
                call    led_set
                call    auto_clear
                ;----------------------- ATAMA
atama_leds	decfsz  atama_count,1
                goto    belt_leds
                btfsc   led_data,0      ;ATAMA OFF?
                goto    atama_leds_2
atama_leds_3	bsf     led_data,0      ;ATAMA ON
                movf    atama_on,0
                movwf   atama_count
                movf    atama_count,0
                btfsc   STATUS,2
                goto    atama_leds_2
                goto    belt_leds
atama_leds_2	bcf     led_data,0      ;ATAMA OFF
                movf    atama_off,0
                movwf   atama_count
                movf    atama_count,0
                btfsc   STATUS,2
                goto    atama_leds_3             
                ;----------------------- BELT
belt_leds	decfsz  belt_count,1
                goto    next_leds
                btfsc   led_data,1      ;BELT OFF?
                goto    belt_leds_2
belt_leds_3	bsf     led_data,1      ;BELT ON
                movf    belt_on,0
                movwf   belt_count
                movf    belt_count,0
                btfsc   STATUS,2
                goto    belt_leds_2
                goto    next_leds
belt_leds_2	bcf     led_data,1      ;BELT OFF
                movf    belt_off,0
                movwf   belt_count
                movf    belt_count,0
                btfsc   STATUS,2
                goto    belt_leds_3
                ;----------------------------------
next_leds
                ;----------------------- RIGHT
right_leds      decfsz  right_count,1
                goto    left_leds
                btfsc   led_data,2      ;RIGHT OFF?
                goto    right_leds_2
right_leds_3    bsf     led_data,2      ;RIGHT ON
                movf    right_on,0
                movwf   right_count
                movf    right_count,0
                btfsc   STATUS,2
                goto    right_leds_2
                goto    left_leds
right_leds_2    bcf     led_data,2      ;RIGHT OFF
                movf    right_off,0
                movwf   right_count
                movf    right_count,0
                btfsc   STATUS,2
                goto    right_leds_3             
                ;----------------------- LEFT
left_leds       decfsz  left_count,1
                goto    next_leds_2
                btfsc   led_data,3      ;LEFT OFF?
                goto    left_leds_2
left_leds_3     bsf     led_data,3      ;LEFT ON
                movf    left_on,0
                movwf   left_count
                movf    left_count,0
                btfsc   STATUS,2
                goto    left_leds_2
                goto    next_leds_2
left_leds_2     bcf     led_data,3      ;LEFT OFF
                movf    left_off,0
                movwf   left_count
                movf    left_count,0
                btfsc   STATUS,2
                goto    left_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   0c0h
                movwf   PORTB
 
                call    timer0_set
 
                movlw   1Ch
                movwf   color_count
                call    auto_clear
 
                movlw   00h
                movwf   led_data        ;LED ALL OFF
                call    set_lo_leds
                movf    atama_on,0
                movwf   atama_count     ;ATAMA count data set
                movf    belt_on,0
                movwf   belt_count	;BELT count data set
                movf    right_on,0
                movwf   right_count     ;RIGHT count data set
                movf    left_on,0
                movwf   left_count	;LEFT 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   0c0h
                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
;--------------------------------------
atama_led
                btfss   led_data,0
                goto    atama_led_off
                bsf     PORTB,0
                nop
                goto    belt_led
atama_led_off
                bcf     PORTB,0
                nop
belt_led
                btfss   led_data,1
                goto    belt_led_off
                bsf     PORTB,1
                nop
                goto    main_next
belt_led_off
                bcf     PORTB,1
                nop
;---------------------------------------
main_next
;---------------------------------------
right_led
                btfss   led_data,2
                goto    right_led_off
                bsf     PORTB,2
                nop
                goto    left_led
right_led_off
                bcf     PORTB,2
                nop
left_led
                btfss   led_data,3
                goto    left_led_off
                bsf     PORTB,3
                nop
                goto    main_next_2
left_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
;-------------------------------------------------------------------------------
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_atama
                movwf   atama_on
                sublw	70h
                movwf   atama_off
 
                call    set_on_belt
                movwf   belt_on
                sublw	70h
                movwf   belt_off
 
                call    set_on_right
                movwf   right_on
                sublw	70h
                movwf   right_off
 
                call    set_on_left
                movwf   left_on
                sublw	70h
                movwf   left_off
                 
                return
;--------------------------------------------------------------------------------
icnt_clear      movlw   00h
                movwf   int_count1
                movwf   int_count2
                movwf   int_count3
                return
;--------------------------------------------------------------------------------
set_on_atama    movf    color_count,0
                movwf   taihi
                movlw   low(atama_on_table)
                addwf   taihi,1
                movlw   high(atama_on_table)
                movwf   PCLATH
                addcf   PCLATH,1
                movf    taihi,0
                movwf   PCL
atama_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_belt     movf    color_count,0
                movwf   taihi
                movlw   low(belt_on_table)
                addwf   taihi,1
                movlw   high(belt_on_table)
                movwf   PCLATH
                addcf   PCLATH,1
                movf    taihi,0
                movwf   PCL
belt_on_table   retlw   70h
                retlw   00h
                retlw   20h
                retlw   40h
                retlw   70h
                retlw   00h
                retlw   20h
                retlw   40h
                retlw   70h
                retlw   00h
                retlw   20h
                retlw   40h
                retlw   70h
                retlw   00h
                retlw   20h
                retlw   40h
                retlw   70h
                retlw   00h
                retlw   20h
                retlw   40h
                retlw   70h
                retlw   00h
                retlw   20h
                retlw   40h
                retlw   70h
                retlw   00h
                retlw   20h
                retlw   40h
                retlw   70h
;-------------------------------------------------------------------------------
set_on_right    movf    color_count,0
                movwf   taihi
                movlw   low(right_on_table)
                addwf   taihi,1
                movlw   high(right_on_table)
                movwf   PCLATH
                addcf   PCLATH,1
                movf    taihi,0
                movwf   PCL
right_on_table  retlw   70h
                retlw   00h
                retlw   10h
                retlw   30h
                retlw   50h
                retlw   70h
                retlw   50h
                retlw   30h
                retlw   10h
                retlw   00h
                retlw   10h
                retlw   30h
                retlw   50h
                retlw   70h
                retlw   50h
                retlw   30h
                retlw   10h
                retlw   00h
                retlw   10h
                retlw   30h
                retlw   50h
                retlw   70h
                retlw   50h
                retlw   30h
                retlw   10h
                retlw   00h
                retlw   10h
                retlw   30h
                retlw   50h
;--------------------------------------------------------------------------------
set_on_left     movf    color_count,0
                movwf   taihi
                movlw   low(left_on_table)
                addwf   taihi,1
                movlw   high(left_on_table)
                movwf   PCLATH
                addcf   PCLATH,1
                movf    taihi,0
                movwf   PCL
left_on_table   retlw   70h
                retlw   70h
                retlw   50h
                retlw   30h
                retlw   10h
                retlw   00h
                retlw   10h
                retlw   30h
                retlw   50h
                retlw   70h
                retlw   50h
                retlw   30h
                retlw   10h
                retlw   00h
                retlw   10h
                retlw   30h
                retlw   50h
                retlw   70h
                retlw   50h
                retlw   30h
                retlw   10h
                retlw   00h
                retlw   10h
                retlw   30h
                retlw   50h
                retlw   70h
                retlw   50h
                retlw   30h
                retlw   10h
;-------------------------------------------------------------------------------
set_lo_leds     movlw   00h
                movwf   atama_on
                movwf   belt_on
                movwf   right_on
                movwf   left_on
 
                movlw   70h
                movwf   atama_off
                movwf   belt_off
                movwf   right_off
                movwf   left_off

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

Copyright(c)2000-2001 nonchansoft