PIC16F84電子遊戯(20)
最終更新日:2001年4月15日
ミラクルライト特別編(1ページ)へ (2ページ)

ミラクルライト特別編の全ソースリスト公開
ミラクルライト特別編の全ソースリストです。長くてすいません。まだまだ未熟な点も多いので皆さんで改造して下さい。
;**********************************************************************
;    Filename:      miracle2.asm                                       *
;    Date:          2001/4/4                                        *
;    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

led_data                EQU     0x11            ;LED set data
                                        ;led_data,0  RED LED
                                        ;led_data,1  GREEN LED
                                        ;led_data,2  BLUE LED

wait_data               EQU     0x12            ;wait data ram

auto_count1     EQU     0x13            ;auto count 1 ram
auto_count2     EQU     0x14            ;auto count 2 ram
auto_sub                EQU     0x15            ;auto sub ram
auto_sub2               EQU     0x16            ;auto sub 2 ram

red_count               EQU     0x19            ;RED LED count ram
green_count     EQU     0x1a            ;GREE LED count ram
blue_count      EQU     0x1b            ;BLUE LED count ram

red_on          EQU     0x20            ;RED LED ON data ram
red_off         EQU     0x21            ;RED LED OFF data ram
green_on                EQU     0x22            ;GREEN LED ON data ram
green_off               EQU     0x23            ;GREEN LED OFF data ram
blue_on         EQU     0x24            ;BLUE LED ON data ram
blue_off                EQU     0x25            ;BLUE LED OFF data ram

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   auto_sub,1
                btfsc   STATUS,0
                incf    auto_sub2
                btfss   auto_sub2,5
                goto    red_leds
                call    led_next
                movlw   00h
                movwf   auto_sub
                movwf   auto_sub2
                ;----------------------- RED
red_leds                decfsz  red_count,1
                goto    green_leds
                btfsc   led_data,0      ;RED OFF?
                goto    red_leds_2
red_leds_3      bsf     led_data,0      ;RED ON
                movf    red_on,0
                movwf   red_count
                movf    red_count,0
                btfsc   STATUS,2
                goto    red_leds_2
                goto    green_leds
red_leds_2      bcf     led_data,0      ;RED OFF
                movf    red_off,0
                movwf   red_count
                movf    red_count,0
                btfsc   STATUS,2
                goto    red_leds_3              

                ;----------------------- GREEN
green_leds      decfsz  green_count,1
                goto    blue_leds
                btfsc   led_data,1      ;GREEN OFF?
                goto    green_leds_2
green_leds_3    bsf     led_data,1      ;GREEN ON
                movf    green_on,0
                movwf   green_count
                movf    green_count,0
                btfsc   STATUS,2
                goto    green_leds_2
                goto    blue_leds
green_leds_2    bcf     led_data,1      ;GREEN OFF
                movf    green_off,0
                movwf   green_count
                movf    green_count,0
                btfsc   STATUS,2
                goto    green_leds_3

                ;---------------------- BLUE
blue_leds               decfsz  blue_count,1
                goto    next_leds
                btfsc   led_data,2      ;BLUE OFF?
                goto    blue_leds_2
blue_leds_3     bsf     led_data,2      ;BLUE ON
                movf    blue_on,0
                movwf   blue_count
                movf    blue_count,0
                btfsc   STATUS,2
                goto    blue_leds_2
                goto    next_leds
blue_leds_2     bcf     led_data,2      ;BLUE OFF
                movf    blue_off,0
                movwf   blue_count
                movf    blue_count,0
                btfsc   STATUS,2
                goto    blue_leds_3
                ;----------------------------------

next_leds
                ;----------------------------------

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

                call    timer0_set

                movlw   01h
                movwf   auto_count2
                movwf   auto_count1

                movlw   00h
                movwf   auto_sub
                movwf   auto_sub2

                movlw   00h
                movwf   led_data        ;RED OFF,GREEN OFF,BLUE OFF
                call    set_0_red
                call    set_0_green
                call    set_0_blue
                movf    red_on,0
                movwf   red_count       ;RED count data set
                movf    green_on,0
                movwf   green_count     ;GREEN count data set
                movf    blue_on,0
                movwf   blue_count      ;BLUE count data set

main_loop

;-------------------------------------- led tentou              
                movf    led_data,0
                movwf   PORTB

                goto    main_loop
;-------------------------------------------------------------------------------
wait_1          
                movlw   0ffh
                movwf   wait_data
wait_2
                decfsz  wait_data,1
                goto    wait_2
                return
;-------------------------------------------------------------------------------
set_0_red               movlw   00h
                movwf   red_on
                movlw   70h
                movwf   red_off
                return
set_1_red               movlw   10h
                movwf   red_on
                movlw   60h
                movwf   red_off
                return
set_2_red               movlw   20h
                movwf   red_on
                movlw   50h
                movwf   red_off
                return
set_3_red               movlw   30h
                movwf   red_on
                movlw   40h
                movwf   red_off
                return
set_4_red               movlw   40h
                movwf   red_on
                movlw   30h
                movwf   red_off
                return
set_5_red               movlw   50h
                movwf   red_on
                movlw   20h
                movwf   red_off
                return
set_6_red               movlw   60h
                movwf   red_on
                movlw   10h
                movwf   red_off
                return
set_7_red               movlw   70h
                movwf   red_on
                movlw   00h
                movwf   red_off
                return
;-------------------------------------------------------------------------------
set_0_green     movlw   00h
                movwf   green_on
                movlw   70h
                movwf   green_off
                return
set_1_green     movlw   10h
                movwf   green_on
                movlw   60h
                movwf   green_off
                return
set_2_green     movlw   20h
                movwf   green_on
                movlw   50h
                movwf   green_off
                return
set_3_green     movlw   30h
                movwf   green_on
                movlw   40h
                movwf   green_off
                return
set_4_green     movlw   40h
                movwf   green_on
                movlw   30h
                movwf   green_off
                return
set_5_green     movlw   50h
                movwf   green_on
                movlw   20h
                movwf   green_off
                return
set_6_green     movlw   60h
                movwf   green_on
                movlw   10h
                movwf   green_off
                return
set_7_green     movlw   70h
                movwf   green_on
                movlw   00h
                movwf   green_off
                return
;-------------------------------------------------------------------------------
set_0_blue      movlw   00h
                movwf   blue_on
                movlw   70h
                movwf   blue_off
                return
set_1_blue      movlw   10h
                movwf   blue_on
                movlw   60h
                movwf   blue_off
                return
set_2_blue      movlw   20h
                movwf   blue_on
                movlw   50h
                movwf   blue_off
                return
set_3_blue      movlw   30h
                movwf   blue_on
                movlw   40h
                movwf   blue_off
                return
set_4_blue      movlw   40h
                movwf   blue_on
                movlw   30h
                movwf   blue_off
                return
set_5_blue      movlw   50h
                movwf   blue_on
                movlw   20h
                movwf   blue_off
                return
set_6_blue      movlw   60h
                movwf   blue_on
                movlw   10h
                movwf   blue_off
                return
set_7_blue      movlw   70h
                movwf   blue_on
                movlw   00h
                movwf   blue_off
                return
;-------------------------------------------------------------------------------
led_next                btfss   auto_count2,7
                goto    led_next2
                btfss   auto_count1,7
                goto    led_next3
                movlw   01h
                movwf   auto_count2
                movwf   auto_count1
led_nexte               call    led_set
                return
led_next3               rlf     auto_count1,1
                bcf     auto_count1,0
                movlw   01h
                movwf   auto_count2
                goto    led_nexte
led_next2               rlf     auto_count2,1
                bcf     auto_count2,0
                goto    led_nexte
;-------------------------------------------------------------------------------
led_set         btfsc   auto_count1,0
                goto    led_set0
                btfsc   auto_count1,1
                goto    led_set1
                btfsc   auto_count1,2
                goto    led_set2
                btfsc   auto_count1,3
                goto    led_set3
                btfsc   auto_count1,4
                goto    led_set4
                btfsc   auto_count1,5
                goto    led_set5
                btfsc   auto_count1,6
                goto    led_set6
                btfsc   auto_count1,7
                goto    led_set7
                return
led_set0                call    led_sub0
                return
led_set1                call    led_sub1
                return
led_set2                call    led_sub2
                return
led_set3                call    led_sub3
                return
led_set4                call    led_sub4
                return
led_set5                call    led_sub5
                return
led_set6                call    led_sub6
                return
led_set7                call    led_sub7
                return

led_sub0                btfsc   auto_count2,0
                goto    led_sub00
                btfsc   auto_count2,1
                goto    led_sub01
                btfsc   auto_count2,2
                goto    led_sub02
                btfsc   auto_count2,3
                goto    led_sub03
                btfsc   auto_count2,4
                goto    led_sub04
                btfsc   auto_count2,5
                goto    led_sub05
                btfsc   auto_count2,6
                goto    led_sub06
                btfsc   auto_count2,7
                goto    led_sub07
                return
led_sub00               call    set_0_red
led_sub00e      call    set_0_green
                call    set_0_blue
                return
led_sub01               call    set_1_red
                goto    led_sub00e
led_sub02               call    set_2_red
                goto    led_sub00e
led_sub03               call    set_3_red
                goto    led_sub00e
led_sub04               call    set_4_red
                goto    led_sub00e
led_sub05               call    set_5_red
                goto    led_sub00e
led_sub06               call    set_6_red
                goto    led_sub00e
led_sub07               call    set_7_red
                goto    led_sub00e

led_sub1                btfsc   auto_count2,0
                goto    led_sub10
                btfsc   auto_count2,1
                goto    led_sub11
                btfsc   auto_count2,2
                goto    led_sub12
                btfsc   auto_count2,3
                goto    led_sub13
                btfsc   auto_count2,4
                goto    led_sub14
                btfsc   auto_count2,5
                goto    led_sub15
                btfsc   auto_count2,6
                goto    led_sub16
                btfsc   auto_count2,7
                goto    led_sub17
                return
led_sub10               call    set_0_green
led_sub10e      call    set_7_red
                call    set_0_blue
                return
led_sub11               call    set_1_green
                goto    led_sub10e
led_sub12               call    set_2_green
                goto    led_sub10e
led_sub13               call    set_3_green
                goto    led_sub10e
led_sub14               call    set_4_green
                goto    led_sub10e
led_sub15               call    set_5_green
                goto    led_sub10e
led_sub16               call    set_6_green
                goto    led_sub10e
led_sub17               call    set_7_green
                goto    led_sub10e

led_sub2                btfsc   auto_count2,0
                goto    led_sub20
                btfsc   auto_count2,1
                goto    led_sub21
                btfsc   auto_count2,2
                goto    led_sub22
                btfsc   auto_count2,3
                goto    led_sub23
                btfsc   auto_count2,4
                goto    led_sub24
                btfsc   auto_count2,5
                goto    led_sub25
                btfsc   auto_count2,6
                goto    led_sub26
                btfsc   auto_count2,7
                goto    led_sub27
                return
led_sub20               call    set_7_red
led_sub20e      call    set_7_green
                call    set_0_blue
                return
led_sub21               call    set_6_red
                goto    led_sub20e
led_sub22               call    set_5_red
                goto    led_sub20e
led_sub23               call    set_4_red
                goto    led_sub20e
led_sub24               call    set_3_red
                goto    led_sub20e
led_sub25               call    set_2_red
                goto    led_sub20e
led_sub26               call    set_1_red
                goto    led_sub20e
led_sub27               call    set_0_red
                goto    led_sub20e

led_sub3                btfsc   auto_count2,0
                goto    led_sub30
                btfsc   auto_count2,1
                goto    led_sub31
                btfsc   auto_count2,2
                goto    led_sub32
                btfsc   auto_count2,3
                goto    led_sub33
                btfsc   auto_count2,4
                goto    led_sub34
                btfsc   auto_count2,5
                goto    led_sub35
                btfsc   auto_count2,6
                goto    led_sub36
                btfsc   auto_count2,7
                goto    led_sub37
                return
led_sub30               call    set_0_blue
led_sub30e      call    set_7_green
                call    set_0_red
                return
led_sub31               call    set_1_blue
                goto    led_sub30e
led_sub32               call    set_2_blue
                goto    led_sub30e
led_sub33               call    set_3_blue
                goto    led_sub30e
led_sub34               call    set_4_blue
                goto    led_sub30e
led_sub35               call    set_5_blue
                goto    led_sub30e
led_sub36               call    set_6_blue
                goto    led_sub30e
led_sub37               call    set_7_blue
                goto    led_sub30e

led_sub4                btfsc   auto_count2,0
                goto    led_sub40
                btfsc   auto_count2,1
                goto    led_sub41
                btfsc   auto_count2,2
                goto    led_sub42
                btfsc   auto_count2,3
                goto    led_sub43
                btfsc   auto_count2,4
                goto    led_sub44
                btfsc   auto_count2,5
                goto    led_sub45
                btfsc   auto_count2,6
                goto    led_sub46
                btfsc   auto_count2,7
                goto    led_sub47
                return
led_sub40       call    set_7_green
led_sub40e      call    set_7_blue
                call    set_0_red
                return
led_sub41       call    set_6_green
                goto    led_sub40e
led_sub42       call    set_5_green
                goto    led_sub40e
led_sub43       call    set_4_green
                goto    led_sub40e
led_sub44       call    set_3_green
                goto    led_sub40e
led_sub45       call    set_2_green
                goto    led_sub40e
led_sub46       call    set_1_green
                goto    led_sub40e
led_sub47       call    set_0_green
                goto    led_sub40e

led_sub5                btfsc   auto_count2,0
                goto    led_sub50
                btfsc   auto_count2,1
                goto    led_sub51
                btfsc   auto_count2,2
                goto    led_sub52
                btfsc   auto_count2,3
                goto    led_sub53
                btfsc   auto_count2,4
                goto    led_sub54
                btfsc   auto_count2,5
                goto    led_sub55
                btfsc   auto_count2,6
                goto    led_sub56
                btfsc   auto_count2,7
                goto    led_sub57
                return
led_sub50               call    set_0_red
led_sub50e      call    set_0_green
                call    set_7_blue
                return
led_sub51               call    set_1_red
                goto    led_sub50e
led_sub52               call    set_2_red
                goto    led_sub50e
led_sub53               call    set_3_red
                goto    led_sub50e
led_sub54               call    set_4_red
                goto    led_sub50e
led_sub55               call    set_5_red
                goto    led_sub50e
led_sub56               call    set_6_red
                goto    led_sub50e
led_sub57               call    set_7_red
                goto    led_sub50e

led_sub6                btfsc   auto_count2,0
                goto    led_sub60
                btfsc   auto_count2,1
                goto    led_sub61
                btfsc   auto_count2,2
                goto    led_sub62
                btfsc   auto_count2,3
                goto    led_sub63
                btfsc   auto_count2,4
                goto    led_sub64
                btfsc   auto_count2,5
                goto    led_sub65
                btfsc   auto_count2,6
                goto    led_sub66
                btfsc   auto_count2,7
                goto    led_sub67
                return
led_sub60               call    set_0_green
led_sub60e      call    set_7_blue
                call    set_7_red
                return
led_sub61               call    set_1_green
                goto    led_sub60e
led_sub62               call    set_2_green
                goto    led_sub60e
led_sub63               call    set_3_green
                goto    led_sub60e
led_sub64               call    set_4_green
                goto    led_sub60e
led_sub65               call    set_5_green
                goto    led_sub60e
led_sub66               call    set_6_green
                goto    led_sub60e
led_sub67               call    set_7_green
                goto    led_sub60e

led_sub7                btfsc   auto_count2,0
                goto    led_sub70
                btfsc   auto_count2,1
                goto    led_sub71
                btfsc   auto_count2,2
                goto    led_sub72
                btfsc   auto_count2,3
                goto    led_sub73
                btfsc   auto_count2,4
                goto    led_sub74
                btfsc   auto_count2,5
                goto    led_sub75
                btfsc   auto_count2,6
                goto    led_sub76
                btfsc   auto_count2,7
                goto    led_sub77
                return
led_sub70               call    set_7_green
                call    set_7_blue
                call    set_7_red
                return
led_sub71               call    set_6_green
                call    set_6_blue
                call    set_6_red
                return
led_sub72               call    set_5_green
                call    set_5_blue
                call    set_5_red
                return
led_sub73               call    set_4_green
                call    set_4_blue
                call    set_4_red
                return
led_sub74               call    set_3_green
                call    set_3_blue
                call    set_3_red
                return
led_sub75               call    set_2_green
                call    set_2_blue
                call    set_2_red
                return
led_sub76               call    set_1_green
                call    set_1_blue
                call    set_1_red
                return
led_sub77               call    set_0_green
                call    set_0_blue
                call    set_0_red
                return
;-------------------------------------------------------------------------------
port_set                                ;RA0,RA1,RA2(OUT)
                                        ;RA3,RA4(IN)
                                        ;RB0,RB1,RB2,RB3,RB4,RB5,RB6,RB7(OUT)
                bsf     STATUS,RP0
                clrf    TRISA
                bsf     TRISA,3
                nop
                bsf     TRISA,4 
                clrf    TRISB
                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
                bsf     INTCON,T0IE
                bsf     INTCON,GIE
                return


                END                     ; directive 'end of program'
ミラクルライト特別編の全HEXコード
HEXコードです。メモ帳などのテキストエディタにコピー&ペーストしてファイルすればPICに書き込めるデータに出来ます。
:020000004C288A
:080008008C0003088D000B11B0
:10001000F3308100013095070318960A961E1428C4
:10002000E320003095009600990B252811181F2811
:10003000111420089900190803191F2825281110E8
:10004000210899001908031918289A0B36289118C5
:100050003028911422089A001A08031930283628EB
:10006000911023089A001A08031929289B0B472886
:1000700011194128111524089B001B080319412858
:100080004728111125089B001B0803193A280D0861
:1000900083008C0E0C0E09003B22FF3085000030DF
:1000A00086004322013094009300003095009600B2
:1000B000003091006B209320BB202008990022087B
:1000C0009A0024089B00110886006328FF309200E4
:1000D000920B682808000030A0007030A1000800D2
:1000E0001030A0006030A10008002030A000503087
:1000F000A10008003030A0004030A10008004030CE
:10010000A0003030A10008005030A0002030A10035
:1001100008006030A0001030A10008007030A0007E
:100120000030A10008000030A2007030A3000800D9
:100130001030A2006030A30008002030A200503030
:10014000A30008003030A2004030A3000800403077
:10015000A2003030A30008005030A2002030A300DD
:1001600008006030A2001030A30008007030A20028
:100170000030A30008000030A4007030A500080083
:100180001030A4006030A50008002030A4005030DA
:10019000A50008003030A4004030A5000800403021
:1001A000A4003030A50008005030A4002030A50085
:1001B00008006030A4001030A50008007030A400D2
:1001C0000030A5000800941FF128931FEC2801308F
:1001D00094009300F4200800930D13100130940054
:1001E000EA28940D1410EA281318052993180729F2
:1001F0001319092993190B29131A0D29931A0F2979
:10020000131B1129931B13290800152108003821FD
:1002100008005B2108007E210800A1210800C421FC
:100220000800E72108000A2208001418262994185B
:100230002A2914192C2994192E29141A3029941AB0
:100240003229141B3429941B362908006B20932073
:10025000BB20080070202729752027297A2027290C
:100260007F20272984202729892027298E202729B4
:100270001418492994184D2914194F2994195129F2
:10028000141A5329941A5529141B5729941B5929B8
:10029000080093208E20BB20080098204A299D202A
:1002A0004A29A2204A29A7204A29AC204A29B1205C
:1002B0004A29B6204A2914186C299418702914194F
:1002C000722994197429141A7629941A7829141BFE
:1002D0007A29941B7C2908008E20B620BB200800B8
:1002E00089206D2984206D297F206D297A206D2930
:1002F00075206D2970206D296B206D2914188F29A8
:10030000941893291419952994199729141A99293D
:10031000941A9B29141B9D29941B9F290800BB201C
:10032000B6206B200800C0209029C5209029CA2043
:100330009029CF209029D4209029D9209029DE20FF
:1003400090291418B2299418B6291419B8299419A7
:10035000BA29141ABC29941ABE29141BC029941B4B
:10036000C2290800B620DE206B200800B120B32986
:10037000AC20B329A720B329A220B3299D20B329FB
:100380009820B3299320B3291418D5299418D92972
:100390001419DB299419DD29141ADF29941AE1298B
:1003A000141BE329941BE52908006B209320DE2011
:1003B00008007020D6297520D6297A20D6297F20DA
:1003C000D6298420D6298920D6298E20D62914180A
:1003D000F8299418FC291419FE299419002A141AD2
:1003E000022A941A042A141B062A941B082A0800BD
:1003F0009320DE208E2008009820F9299D20F929DD
:10040000A220F929A720F929AC20F929B120F9293E
:10041000B620F92914181B2A94181F2A1419232A04
:100420009419272A141A2B2A941A2F2A141B332AB8
:10043000941B372A0800B620DE208E200800B12049
:10044000D92089200800AC20D42084200800A720CF
:10045000CF207F200800A220CA207A2008009D20FB
:10046000C520752008009820C02070200800932027
:10047000BB206B200800831685018515000005163A
:100480008601831208008316833081008312F330C3
:0804900081008B168B17080098
:02400E00F13F80
:00000001FF
(miracle2.hex)
ミラクルライト特別編の
ソースリストの赤い部分が割り込み処理、青い部分がメイン処理です。
後半の黒い部分が各種サブルーチンです。
割り込み処理
STATUSレジスタ退避
色変更時間処理
赤LED処理
緑LED処理
青LED処理
STATUSレジスタ復帰
メイン処理
初期設定
LED処理
ミラクルライト特別編の完成
(赤>黄>緑>水>青>紫>白への連続変化)
約2分弱で色の変化は1周します。あとは「ぼーーっと」眺めて下さい。
電源回路を工夫して車載用なんかにすると楽しいと思います。
(ミラクルライト特別編の中身と超高密度実装の全貌)
ということで、「ミラクルライト特別編」大完成です。
ハンディタイプに作製しましたので、どこでも持ち運びOKですね。
これからもどんどん楽しくなる「PIC16F84電子遊戯」をよろしくお願いいたします。

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