[PR]今日のニュースは
「Infoseek モバイル」

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

仮面ライダーシステム・その1の全ソースリスト公開
今回も難しいところはありません。駆動するLEDの数は多いですが、着信ランプなどの製作のLED駆動と同じです。
ソースリストを掲載しますので、参考にして下さい。
;**********************************************************************
;    Filename:      v32.asm                                           *
;    Date:          2001/10/7                                         *
;    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  RED1 LED
                                        ;led_data,1  GREEN1 LED
                                        ;led_data,2  RED2 LED
                                        ;led_data,3  GREEN2 LED
                                        ;led_data,4  DOUBLE RED1
                                        ;led_data,5  DOUBLE RED2
 
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
red1_count      EQU     0x19            ;RED1 LED count ram
green1_count    EQU     0x1a            ;GREEN1 LED count ram
red2_count      EQU     0x1b            ;RED2 LED count ram
green2_count    EQU     0x1c            ;GREEN2 LED count ram
dred1_count     EQU     0x1d            ;DOUBLE RED1 count ram
dred2_count     EQU     0x1e            ;DOUBLE RED2 count ram
 
red1_on         EQU     0x20            ;RED1 LED ON data ram
red1_off        EQU     0x21            ;RED1 LED OFF data ram
green1_on       EQU     0x22            ;GREEN1 LED ON data ram
green1_off      EQU     0x23            ;GREEN1 LED OFF data ram
red2_on         EQU     0x24            ;RED2 LED ON data ram
red2_off        EQU     0x25            ;RED2 LED OFF data ram
green2_on       EQU     0x26            ;GREEN2 LED ON data ram
green2_off      EQU     0x27            ;GREEN2 LED OFF data ram
dred1_on        EQU     0x28            ;DOUBLE RED1 ON data ram
dred1_off       EQU     0x29            ;DOUBLE RED1 OFF data ram
dred2_on        EQU     0x2a            ;DOUBLE RED2 ON data ram
dred2_off       EQU     0x2b            ;DOUBLE RED2 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    red1_leds
                call    led_change      
                call    led_set
                call    auto_clear
                ;----------------------- RED1
red1_leds       decfsz  red1_count,1
                goto    green1_leds
                btfsc   led_data,0      ;RED1 OFF?
                goto    red1_leds_2
red1_leds_3     bsf     led_data,0      ;RED1 ON
                movf    red1_on,0
                movwf   red1_count
                movf    red1_count,0
                btfsc   STATUS,2
                goto    red1_leds_2
                goto    green1_leds
red1_leds_2     bcf     led_data,0      ;RED1 OFF
                movf    red1_off,0
                movwf   red1_count
                movf    red1_count,0
                btfsc   STATUS,2
                goto    red1_leds_3             
                ;----------------------- GREEN1
green1_leds     decfsz  green1_count,1
                goto    next_leds
                btfsc   led_data,1      ;GREEN1 OFF?
                goto    green1_leds_2
green1_leds_3   bsf     led_data,1      ;GREEN1 ON
                movf    green1_on,0
                movwf   green1_count
                movf    green1_count,0
                btfsc   STATUS,2
                goto    green1_leds_2
                goto    next_leds
green1_leds_2   bcf     led_data,1      ;GREEN1 OFF
                movf    green1_off,0
                movwf   green1_count
                movf    green1_count,0
                btfsc   STATUS,2
                goto    green1_leds_3
                ;----------------------------------
next_leds
                ;----------------------- RED2
red2_leds       decfsz  red2_count,1
                goto    green2_leds
                btfsc   led_data,2      ;RED2 OFF?
                goto    red2_leds_2
red2_leds_3     bsf     led_data,2      ;RED2 ON
                movf    red2_on,0
                movwf   red2_count
                movf    red2_count,0
                btfsc   STATUS,2
                goto    red2_leds_2
                goto    green2_leds
red2_leds_2     bcf     led_data,2      ;RED2 OFF
                movf    red2_off,0
                movwf   red2_count
                movf    red2_count,0
                btfsc   STATUS,2
                goto    red2_leds_3             
                ;----------------------- GREEN2
green2_leds     decfsz  green2_count,1
                goto    next_leds_2
                btfsc   led_data,3      ;GREEN2 OFF?
                goto    green2_leds_2
green2_leds_3   bsf     led_data,3      ;GREEN2 ON
                movf    green2_on,0
                movwf   green2_count
                movf    green2_count,0
                btfsc   STATUS,2
                goto    green2_leds_2
                goto    next_leds_2
green2_leds_2   bcf     led_data,3      ;GREEN2 OFF
                movf    green2_off,0
                movwf   green2_count
                movf    green2_count,0
                btfsc   STATUS,2
                goto    green2_leds_3
                ;----------------------------------
next_leds_2
                ;----------------------- DOUBLE RED1
dred1_leds      decfsz  dred1_count,1
                goto    dred2_leds
                btfsc   led_data,4      ;DRED1 OFF?
                goto    dred1_leds_2
dred1_leds_3    bsf     led_data,4      ;DRED1 ON
                movf    dred1_on,0
                movwf   dred1_count
                movf    dred1_count,0
                btfsc   STATUS,2
                goto    dred1_leds_2
                goto    dred2_leds
dred1_leds_2    bcf     led_data,4      ;DRED1 OFF
                movf    dred1_off,0
                movwf   dred1_count
                movf    dred1_count,0
                btfsc   STATUS,2
                goto    dred1_leds_3            
                ;----------------------- DOUBLE RED2
dred2_leds      decfsz  dred2_count,1
                goto    next_leds_3
                btfsc   led_data,5      ;DRED1 OFF?
                goto    dred2_leds_2
dred2_leds_3    bsf     led_data,5      ;DRED1 ON
                movf    dred2_on,0
                movwf   dred2_count
                movf    dred2_count,0
                btfsc   STATUS,2
                goto    dred2_leds_2
                goto    next_leds_3
dred2_leds_2    bcf     led_data,5      ;DRED1 OFF
                movf    dred2_off,0
                movwf   dred2_count
                movf    dred2_count,0
                btfsc   STATUS,2
                goto    dred2_leds_3            
                ;----------------------------------
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   0cfh
                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    red1_on,0
                movwf   red1_count      ;RED1 count data set
                movf    green1_on,0
                movwf   green1_count    ;GREEN1 count data set
                movf    red2_on,0
                movwf   red2_count      ;RED2 count data set
                movf    green2_on,0
                movwf   green2_count    ;GREEN2 count data set
                movf    dred1_on,0
                movwf   dred1_count     ;DOUBLE RED1 count data set
                movf    dred2_on,0
                movwf   dred2_count     ;DOUBLE RED2 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   0cfh
                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
;--------------------------------------
red1_led
                btfss   led_data,0
                goto    red1_led_off
                bcf     PORTB,1
                nop
                goto    green1_led
red1_led_off
                bsf     PORTB,1
                nop
green1_led
                btfss   led_data,1
                goto    green1_led_off
                bcf     PORTB,0
                nop
                goto    main_next
green1_led_off
                bsf     PORTB,0
                nop
;---------------------------------------
main_next
;---------------------------------------
red2_led
                btfss   led_data,2
                goto    red2_led_off
                bcf     PORTB,3
                nop
                goto    green2_led
red2_led_off
                bsf     PORTB,3
                nop
green2_led
                btfss   led_data,3
                goto    green2_led_off
                bcf     PORTB,2
                nop
                goto    main_next_2
green2_led_off
                bsf     PORTB,2
                nop
;--------------------------------------
main_next_2
;--------------------------------------
dred1_led
                btfss   led_data,4
                goto    dred1_led_off
                bsf     PORTB,4
                nop
                goto    dred2_led
dred1_led_off
                bcf     PORTB,4
                nop
dred2_led
                btfss   led_data,5
                goto    dred2_led_off
                bsf     PORTB,5
                nop
                goto    main_next_3
dred2_led_off
                bcf     PORTB,5
                nop
;--------------------------------------
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_red1
                movwf   red1_on
                sublw	70h
                movwf   red1_off
 
                call    set_on_green1
                movwf   green1_on
                sublw	70h
                movwf   green1_off
 
                call    set_on_red2
                movwf   red2_on
                sublw	70h
                movwf   red2_off
 
                call    set_on_green2
                movwf   green2_on
                sublw	70h
                movwf   green2_off
 
                call    set_on_dred1
                movwf   dred1_on
                sublw	70h
                movwf   dred1_off
 
                call    set_on_dred2
                movwf   dred2_on
                sublw	70h
                movwf   dred2_off
                 
                return
;--------------------------------------------------------------------------------
icnt_clear      movlw   00h
                movwf   int_count1
                movwf   int_count2
                movwf   int_count3
                return
;--------------------------------------------------------------------------------
set_on_red1     movf    color_count,0
                movwf   taihi
                movlw   low(red1_on_table)
                addwf   taihi,1
                movlw   high(red1_on_table)
                movwf   PCLATH
                addcf   PCLATH,1
                movf    taihi,0
                movwf   PCL
red1_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_on_green1   movf    color_count,0
                movwf   taihi
                movlw   low(green1_on_table)
                addwf   taihi,1
                movlw   high(green1_on_table)
                movwf   PCLATH
                addcf   PCLATH,1
                movf    taihi,0
                movwf   PCL
green1_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_on_red2     movf    color_count,0
                movwf   taihi
                movlw   low(red2_on_table)
                addwf   taihi,1
                movlw   high(red2_on_table)
                movwf   PCLATH
                addcf   PCLATH,1
                movf    taihi,0
                movwf   PCL
red2_on_table   retlw   70h
                retlw   10h
                retlw   30h
                retlw   50h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   60h
                retlw   40h
                retlw   20h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   10h
                retlw   30h
                retlw   50h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   60h
                retlw   40h
                retlw   20h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
;--------------------------------------------------------------------------------
set_on_green2   movf    color_count,0
                movwf   taihi
                movlw   low(green2_on_table)
                addwf   taihi,1
                movlw   high(green2_on_table)
                movwf   PCLATH
                addcf   PCLATH,1
                movf    taihi,0
                movwf   PCL
green2_on_table retlw   70h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   20h
                retlw   40h
                retlw   60h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   50h
                retlw   30h
                retlw   10h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   20h
                retlw   40h
                retlw   60h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   50h
                retlw   30h
                retlw   10h
;-------------------------------------------------------------------------------
set_on_dred1    movf    color_count,0
                movwf   taihi
                movlw   low(dred1_on_table)
                addwf   taihi,1
                movlw   high(dred1_on_table)
                movwf   PCLATH
                addcf   PCLATH,1
                movf    taihi,0
                movwf   PCL
dred1_on_table  retlw   70h
                retlw   10h
                retlw   30h
                retlw   50h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   60h
                retlw   40h
                retlw   20h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   10h
                retlw   30h
                retlw   50h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   60h
                retlw   40h
                retlw   20h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
;--------------------------------------------------------------------------------
set_on_dred2    movf    color_count,0
                movwf   taihi
                movlw   low(dred2_on_table)
                addwf   taihi,1
                movlw   high(dred2_on_table)
                movwf   PCLATH
                addcf   PCLATH,1
                movf    taihi,0
                movwf   PCL
dred2_on_table  retlw   70h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   20h
                retlw   40h
                retlw   60h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   50h
                retlw   30h
                retlw   10h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   00h
                retlw   20h
                retlw   40h
                retlw   60h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   70h
                retlw   50h
                retlw   30h
                retlw   10h
;-------------------------------------------------------------------------------
set_lo_leds     movlw   00h
                movwf   red1_on
                movwf   green1_on
                movwf   red2_on
                movwf   green2_on
                movwf   dred1_on
                movwf   dred2_on
 
                movlw   70h
                movwf   red1_off
                movwf   green1_off
                movwf   red2_off
                movwf   green2_off
                movwf   dred1_off
                movwf   dred2_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'
仮面ライダーシステム・その1の全HEXコード
HEXコードです。メモ帳などのテキストエディタにコピー&ペーストしてファイルすればPICに書き込めるデータに出来ます。
:02000000862850
:080008008C0003088D000B11B0
:10001000F33081000130AD07031C12280130AE0718
:100020000318AF0A013093070318940A141C1B2805
:10003000FE200521FA20990B2C28111826281114CE
:10004000200899001908031926282C2811102108C6
:100050009900190803191F289A0B3D289118372871
:10006000911422089A001A08031937283D28911084
:1000700023089A001A08031930289B0B4E281119DF
:100080004828111524089B001B08031948284E28EE
:10009000111125089B001B08031941289C0B5F28A0
:1000A00091195928911526089C001C0803195928F4
:1000B0005F28911127089C001C08031952289D0BEA
:1000C0007028111A6A28111628089D001D080319A6
:1000D0006A287028111229089D001D080319632839
:1000E0009E0B8128911A7B2891162A089E001E08D3
:1000F00003197B28812891122B089E001E080319E2
:1001000074280D0883008C0E0C0E09001C22003090
:100110008500CF30860025221C309600FA20003062
:1001200091000D222008990022089A0024089B00C3
:1001300026089C0028089D002A089E008B130000BA
:100140008B1200000B1100000B1000008B1500003B
:100150001E21CF3086000000630000008B110000DC
:100160008B1700008B160000E420AF18E228111C4A
:10017000BC2886100000BE2886140000911CC328ED
:1001800006100000C52806140000111DCA2886119B
:100190000000CC2886150000911DD1280611000012
:1001A000D32806150000111ED82806160000DA28EC
:1001B00006120000911EDF2886160000E128861234
:1001C0000000B528EC209E2805140000F420F4203F
:1001D000F42005100000080085140000F420F4202D
:1001E000F420851000000800FF3095000000950BFA
:1001F000F6280800003093009400080096030319C5
:10020000022908001C30960008002321A000703C41
:10021000A1004A21A200703CA3007121A400703CFF
:10022000A5009821A600703CA700BF21A800703C43
:10023000A900E621AA00703CAB0008000030AD0028
:10024000AE00AF000800160897002D309707013068
:100250008A0003188A0A17088200703400341034A8
:10026000203430344034503460347034703470345E
:1002700070347034703470347034603450344034BE
:10028000303420341034003400340034003400346E
:1002900000340034160897005430970701308A0064
:1002A00003188A0A170882007034003400340034BE
:1002B000003400340034003400341034203430343E
:1002C000403450346034703470347034703470346E
:1002D00070347034703460345034403430342034EE
:1002E0001034160897007B30970701308A000318F6
:1002F0008A0A170882007034103430345034703455
:10030000703470347034603440342034003400343D
:10031000003400341034303450347034703470345D
:1003200070346034403420340034003400340034FD
:1003300016089700A230970701308A0003188A0A2E
:100340001708820070340034003400340034203444
:10035000403460347034703470347034503430341D
:10036000103400340034003400342034403460341D
:1003700070347034703470345034303410341608A3
:100380009700C930970701308A0003188A0A1708B6
:10039000820070341034303450347034703470341F
:1003A000703460344034203400340034003400347D
:1003B00010343034503470347034703470346034ED
:1003C00040342034003400340034003416089700E0
:1003D000F030970701308A0003188A0A1708820054
:1003E000703400340034003400342034403460343D
:1003F000703470347034703450343034103400340D
:1004000000340034003420344034603470347034AC
:10041000703470345034303410340030A000A200F6
:10042000A400A600A800AA007030A100A300A500A7
:10043000A700A900AB000800831685018601861776
:100440000000061700008312080083168330810025
:080450008312F3308100080063
:02400E00F13F80
:00000001FF
(V32.hex)
仮面ライダーシステム・その1の完成
仮面ライダーの雄姿を見て下さい。(前に見ました?)
ということで、仮面ライダーの光ものがチカチカするだけですが、楽しいですね。
(私だけでしょうか?)
さて今回のポイントとして今後製作する機器をつなぐという構想があります。
そのためのジャックを装着しておりますので、そこも見ておいてください。
φ3.5の通常のモノラルジャックです。これでV3が外部からコントロール可能になります。
ということで、V3に関する製作はここまでとしましょう。
私的には次の製作がすでに完了しており、ソフトの最終調整中です。
このV3につながる機器を出来るだけ早く公開したいと考えています。
これからも益々面白くなる「PIC16F84電子遊戯」をよろしくお願いいたします。

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

Copyright(c)2000-2001 nonchansoft