沼津高専 電子制御工学科

MIRS0702 LED制御ボード製造仕様書

MIRS0702-ELEC-0005

改訂記録

版数

作成日

作成者

承認

改訂内容

A01

2008.02.13

齋藤・藤田

平田

初版


 

目次

1. 回路図

2. 必要な部品

3. PICの制御プログラム

 

1.     回路図

LED制御用ボードの回路図を以下に示す。

 

2必要な部品

 

ユニバーサル基板×1

2pinコネクタ×1

3pinコネクタ×1

4pinコネクタ×2

18pinICソケット×1

抵抗R1(100Ω)×7

LED()×7

積層セラミックコンデンサC(104)×1

電解コンデンサC2(0.1uF 25V)×1

PIC16F84×1

 

LEDは注文時の不手際により型番が不明である。分かっているのは高輝度で順方向降下電圧が2Vということのみだ。今回は30mAの電流が流れるよう設計している。

 

 

 

3.PICの制御プログラム

 

PICの大方の仕様を示す。

ソフト側から3bitの信号(000111)が送られてくると、その信号に応じて各動作をする。

000:STOP(光らない)

001: Pattern 1(回転盤の回転時)                       LEDbitゆっくり点滅(大体1sec間隔)

010: Pattern 2(ポスト周回時)                            LEDbit普通の速さで点滅(大体0.5sec間隔)

011: Pattern 3(獲得動作時)                              LEDbit速く点滅(大体0.1sec間隔)

100: Pattern 4(通常走行時)                              →右端から1bitずつ点滅し左シフト、左端まで行ったら右シフト…を繰り返す

101: Pattern 5(例外動作時)                              →両端から1bitずつ点滅

110: Pattern 6(例外動作時)                              1bitおきの点滅

111: Pattern 7(ポスト獲得時、全プログラム終了時)          →素早くチカチカ

 

ちなみに、我々の回路はPICからの出力が’0’のとき点灯し’1’のとき消灯するように設計した。

即座にSTOP信号を検知できるよう、各Patternに’000’を検知するプログラムを織り込む。

また、ポスト周回を重ねるにつれ点滅の時間が短くなるようにする(ULTRAってやつ)

PICの制御プログラムを以下に示す。

 

                      INCLUDE"p16F84.inc"

                      LIST                P=16F84,R=DEC

STATUS           EQU                3

PORTA            EQU                5

PORTB            EQU                6

TRISB              EQU                H'86'

Memory            EQU                0x0C

CNT1               EQU                Memory+0

CNT2               EQU                Memory+1

CNT3               EQU                Memory+2

ULTRA             EQU                Memory+3

 

                     

                      CLRF               PORTA                        ;PORTAの初期化

                      BSF                 STATUS,5

                      CLRF               TRISB                         ;PORTBを全ポート出力に

                      BCF                STATUS,5

                      MOVLW            B'11111111'                  ;PORTBの初期化

                      MOVWF            PORTB

 

 

                      MOVLW            B'00010000'                  ;

                      MOVWF            ULTRA

 

 

CHK                BTFSC             PORTA,2                     ;STOP(000)を検出

                      GOTO              CaseXX1

                      BTFSC             PORTA,3

                      GOTO              CaseX10

                      BTFSC             PORTA,0

                      GOTO              PATT4

                      GOTO              STOP

 

CaseXX1          BTFSS             PORTA,3                     ;命令信号を判別

                      GOTO              CaseX01

                      GOTO              CaseX11

CaseX10          BTFSS             PORTA,0

                      GOTO              PATT2

                      GOTO              PATT6

CaseX01          BTFSS             PORTA,0

                      GOTO              PATT1

                      GOTO              PATT5

CaseX11          BTFSS             PORTA,0

                      GOTO              PATT3

                      GOTO              PATT7

 

 

 

 

PATT1                                                                     ; LEDbitゆっくり点滅(大体1sec間隔)

ON1                 CLRF               PORTB                        ;LED ON

                      CALL               DEL1

 

                      BTFSC             PORTA,2                     ;STOP(000)を検出

                      GOTO              OFF1

                      BTFSC             PORTA,3

                      GOTO              OFF1

                      BTFSC             PORTA,0

                      GOTO              OFF1

                      GOTO              STOP

 

OFF1               MOVLW            B'11111111'                  ;LED OFF

                      MOVWF            PORTB

                      CALL               DEL1

 

                      BTFSC             PORTA,2                     ;STOP(000)を検出

                      GOTO              ON1

                      BTFSC             PORTA,3

                      GOTO              ON1

                      BTFSC             PORTA,0

                      GOTO              ON1

                      GOTO              STOP

 

                      GOTO              PATT1

 

 

PATT2             RRF                 ULTRA,1                      ; LEDbit普通の速さで点滅(大体0.5sec間隔)

 

ON2                 CLRF               PORTB                        ;LED ON

                      CALL               DEL05

          

                      BTFSC             PORTA,2                     ;STOP(000)を検出

                      GOTO              OFF2

                      BTFSC             PORTA,3

                      GOTO              OFF2

                      BTFSC             PORTA,0

                      GOTO              OFF2

                      GOTO              STOP

          

OFF2               MOVLW            B'11111111'                  ;LED OFF

                      MOVWF            PORTB

                      CALL               DEL05

 

                      BTFSC             PORTA,2                     ;STOP(000)を検出

                      GOTO              ON2

                      BTFSC             PORTA,3

                      GOTO              ON2

                      BTFSC             PORTA,0

                      GOTO              ON2

                      GOTO              STOP

 

                      GOTO              ON2

 

 

PATT3                                                                     ; LEDbit速く点滅(大体0.1sec間隔)

ON3                 CLRF               PORTB                        ;LED ON

                      CALL               DEL025

 

                      BTFSC             PORTA,2                     ;STOP(000)を検出

                      GOTO              OFF3

                      BTFSC             PORTA,3

                      GOTO              OFF3

                      BTFSC             PORTA,0

                      GOTO              OFF3

                      GOTO              STOP

          

OFF3               MOVLW            B'11111111'                  ;LED OFF

                      MOVWF            PORTB

                      CALL               DEL025

                     

                      BTFSC             PORTA,2                     ;STOP(000)を検出

                      GOTO              ON3

                      BTFSC             PORTA,3

                      GOTO              ON3

                      BTFSC             PORTA,0

                      GOTO              ON3

                      GOTO              STOP

 

                      GOTO              ON3

 

 

PATT4                                                                     ; 右端から1bitずつ点滅し左シフト、左端まで行ったら右シフト…を繰り返す

BCF                STATUS,0                    ;キャリーフラグの初期化

                      MOVLW            B'11111110'

                      MOVWF            PORTB

                      CALL               DEL025

LEFT               MOVLW            7                                ;カウンタの初期値7を設定

                      MOVWF            CNT1

LOOPL            RLF                 PORTB,1                     ;左シフト

                      CALL               DEL025

          

                      BTFSC             PORTA,2                     ;STOP(000)を検出

                      GOTO              HONDA

                      BTFSC             PORTA,3

                      GOTO              HONDA

                      BTFSC             PORTA,0

                      GOTO              HONDA

                      GOTO              STOP

          

HONDA            DECFSZ           CNT1,1                        ;カウンタが0になるまで左シフト、0になったら右シフトへ

                      GOTO              LOOPL

RIGHT              MOVLW            7                                ;カウンタの初期値7を設定

                      MOVWF            CNT1

LOOPR            RRF                 PORTB,1                     ;右シフト

                      CALL               DEL025

 

                      BTFSC             PORTA,2                     ;STOP(000)を検出

                      GOTO              YAMAHA

                      BTFSC             PORTA,3

                      GOTO              YAMAHA

                      BTFSC             PORTA,0

                      GOTO              YAMAHA

                      GOTO              STOP

          

YAMAHA          DECFSZ           CNT1,1                        ; ;カウンタが0になるまで右シフト、0になったら左シフトへ

                      GOTO              LOOPR

                      GOTO              LEFT

 

          

 

PATT5                                                                     ; 両端から1bitずつ点滅

UNO                MOVLW            B'10111110'

                      MOVWF            PORTB

                      CALL               DEL025

 

                      BTFSC             PORTA,2                     ;STOP(000)を検出

                      GOTO              DUE

                      BTFSC             PORTA,3

                      GOTO              DUE

                      BTFSC             PORTA,0

                      GOTO              DUE

                      GOTO              STOP

 

DUE                 MOVLW            B'11011101'

                      MOVWF            PORTB

                      CALL               DEL025

 

                      BTFSC             PORTA,2                     ;STOP(000)を検出

                      GOTO              TRE

                      BTFSC             PORTA,3

                      GOTO              TRE

                      BTFSC             PORTA,0

                      GOTO              TRE

                      GOTO              STOP

 

TRE                 MOVLW            B'11101011'

                      MOVWF            PORTB

                      CALL               DEL025

 

                      BTFSC             PORTA,2                     ;STOP(000)を検出

                      GOTO              QUATTRO

                      BTFSC             PORTA,3

                      GOTO              QUATTRO

                      BTFSC             PORTA,0

                      GOTO              QUATTRO

                      GOTO              STOP

 

QUATTRO        MOVLW            B'11110111'

                      MOVWF            PORTB

                      CALL               DEL025

 

                      BTFSC             PORTA,2                     ;STOP(000)を検出

                      GOTO              UNO

                      BTFSC             PORTA,3

                      GOTO              UNO

                      BTFSC             PORTA,0

                      GOTO              UNO

                      GOTO              STOP

 

                      GOTO              PATT5

 

 

PATT6                                                                     ; 1bitおきの点滅

HOP                MOVLW            B'01010101'

                      MOVWF            PORTB

                      CALL               DEL025

 

                      BTFSC             PORTA,2                     ;STOP(000)を検出

                      GOTO              STEP

                      BTFSC             PORTA,3

                      GOTO              STEP

                      BTFSC             PORTA,0

                      GOTO              STEP

                      GOTO              STOP

          

STEP               MOVLW            B'10101010'

                      MOVWF            PORTB

                      CALL               DEL025

          

                      BTFSC             PORTA,2                     ;STOP(000)を検出

                      GOTO              JUMP

                      BTFSC             PORTA,3

                      GOTO              JUMP

                      BTFSC             PORTA,0

                      GOTO              JUMP

                      GOTO              STOP

 

JUMP              GOTO              HOP

 

 

PATT7                                                                     ; 忙しく点滅

Moi1                MOVLW            B'10001000'     

                      MOVWF            PORTB

                      CALL               DEL01

                      MOVLW            B'11111111'

                      MOVWF            PORTB

                      CALL               DEL005

 

                      BTFSC             PORTA,2                     ;STOP(000)を検出

                      GOTO              Moi2

                      BTFSC             PORTA,3

                      GOTO              Moi2

                      BTFSC             PORTA,0

                      GOTO              Moi2

                      GOTO              STOP

 

Moi2                MOVLW            B'10010100'

                      MOVWF            PORTB

                      CALL               DEL01

                      MOVLW            B'11111111'

                      MOVWF            PORTB

                      CALL               DEL005

 

                      BTFSC             PORTA,2                     ;STOP(000)を検出

                      GOTO              Moi3

                      BTFSC             PORTA,3

                      GOTO              Moi3

                      BTFSC             PORTA,0

                      GOTO              Moi3

                      GOTO              STOP

          

Moi3                MOVLW            B'10100010'

                      MOVWF            PORTB

                      CALL               DEL01

                      MOVLW            B'11111111'

                      MOVWF            PORTB

                      CALL               DEL005

          

                      BTFSC             PORTA,2                     ;STOP(000)を検出

                      GOTO              Moi4

                      BTFSC             PORTA,3

                      GOTO              Moi4

                      BTFSC             PORTA,0

                      GOTO              Moi4

                      GOTO              STOP

 

Moi4                MOVLW            B'11000001'

                      MOVWF            PORTB

                      CALL               DEL01

                      MOVLW            B'11111111'

                      MOVWF            PORTB

                      CALL               DEL005

 

                      BTFSC             PORTA,2                     ;STOP(000)を検出

                      GOTO              Moi5

                      BTFSC             PORTA,3

                      GOTO              Moi5

                      BTFSC             PORTA,0

                      GOTO              Moi5

                      GOTO              STOP

 

Moi5                MOVLW            B'10000000'

                      MOVWF            PORTB

                      CALL               DEL01

                      MOVLW            B'11111111'

                      MOVWF            PORTB

                      CALL               DEL005

          

                      BTFSC             PORTA,2                     ;STOP(000)を検出

                      GOTO              MoiMoi

                      BTFSC             PORTA,3

                      GOTO              MoiMoi

                      BTFSC             PORTA,0

                      GOTO              MoiMoi

                      GOTO              STOP

 

MoiMoi             GOTO              PATT7

 

STOP              MOVLW            B'11111111'

                      MOVWF            PORTB

                      GOTO              CHK

 

 

 

 

 

 

DEL1                                                                       ;1DELAY

                      MOVLW            0A6H

                      MOVWF            CNT1

                      MOVLW            0A6H

                      MOVWF            CNT2

 

 

                      BTFSC             ULTRA,3                      ;既に周回したポスト数によって点滅の速さを決定

                      GOTO              OSOI1

                      BTFSC             ULTRA,2          

                      GOTO              OSOI1

                      BTFSC             ULTRA,1

                      GOTO              FUTSU1

                      BTFSC             ULTRA,0

                      GOTO              HAYAI1

                      GOTO              OSOI1

 

 

OSOI1              MOVLW            042H

                      MOVWF            CNT3

                      GOTO              FIRST1

FUTSU1           MOVLW            021H

                      MOVWF            CNT3

                      GOTO              FIRST1

HAYAI1            MOVLW            010H

                      MOVWF            CNT3

                      GOTO              FIRST1

 

FIRST1            DECFSZ           CNT1

                      GOTO              FIRST1

                      MOVLW            0A6H

                      MOVWF            CNT1

                      GOTO              SECOND1

SECOND1         DECFSZ           CNT2

                      GOTO              FIRST1

                      MOVLW            0A6H

                      MOVWF            CNT2

                      GOTO              THIRD1

THIRD1            DECFSZ           CNT3

                      GOTO              FIRST1

                      RETURN

 

 

DEL05                                                                      ;0.5DELAY

                      MOVLW            0A6H

                      MOVWF            CNT1

                      MOVLW            0A6H

                      MOVWF            CNT2

 

                      BTFSC             ULTRA,3          

                      GOTO              OSOI2

                      BTFSC             ULTRA,2          

                      GOTO              OSOI2

                      BTFSC             ULTRA,1

                      GOTO              FUTSU2

                      BTFSC             ULTRA,0

                      GOTO              HAYAI2

                      GOTO              OSOI2

 

OSOI2              MOVLW            020H

                      MOVWF            CNT3

                      GOTO              FIRST2

FUTSU2           MOVLW            010H

                      MOVWF            CNT3

                      GOTO              FIRST2

HAYAI2            MOVLW            005H

                      MOVWF            CNT3

                      GOTO              FIRST2

 

FIRST2            DECFSZ           CNT1

                      GOTO              FIRST2

                      MOVLW            0A6H

                      MOVWF            CNT1

                      GOTO              SECOND2

SECOND2         DECFSZ           CNT2

                      GOTO              FIRST2

                      MOVLW            0A6H

                      MOVWF            CNT2

                      GOTO              THIRD2

THIRD2            DECFSZ           CNT3

                      GOTO              FIRST2

                      RETURN

 

 

DEL025                                                         ;0.25DELAY

                      MOVLW            0A6H

                      MOVWF            CNT1

                      MOVWF            CNT2

 

                      BTFSC             ULTRA,3          

                      GOTO              OSOI3

                      BTFSC             ULTRA,2          

                      GOTO              OSOI3

                      BTFSC             ULTRA,1

                      GOTO              FUTSU3

                      BTFSC             ULTRA,0

                      GOTO              HAYAI3

                      GOTO              OSOI3

 

OSOI3              MOVLW            010H

                      MOVWF            CNT3

                      GOTO              FIRST3

FUTSU3           MOVLW            005H

                      MOVWF            CNT3

                      GOTO              FIRST3

HAYAI3            MOVLW            002H

                      MOVWF            CNT3

                      GOTO              FIRST3

 

FIRST3            DECFSZ           CNT1

                      GOTO              FIRST3

                      MOVLW            0A6H

                      MOVWF            CNT1

                      GOTO              SECOND3

SECOND3         DECFSZ           CNT2

                      GOTO              FIRST3

                      MOVLW            0A6H

                      MOVWF            CNT2

                      GOTO              THIRD3

THIRD3            DECFSZ           CNT3

                      GOTO              FIRST3

                      RETURN

 

DEL01                                                                      ;0.1DELAY

                      MOVLW            0A6H

                      MOVWF            CNT1

                      MOVLW            0A6H

                      MOVWF            CNT2

 

                      BTFSC             ULTRA,3          

                      GOTO              OSOI4

                      BTFSC             ULTRA,2          

                      GOTO              OSOI4

                      BTFSC             ULTRA,1

                      GOTO              FUTSU4

                      BTFSC             ULTRA,0

                      GOTO              HAYAI4

                      GOTO              OSOI4

 

OSOI4              MOVLW            004H

                      MOVWF            CNT3

                      GOTO              FIRST4

FUTSU4           MOVLW            002H

                      MOVWF            CNT3

                      GOTO              FIRST4

HAYAI4            MOVLW            001H

                      MOVWF            CNT3

                      GOTO              FIRST4

 

FIRST4            DECFSZ           CNT1

                      GOTO              FIRST4

                      MOVLW            0A6H

                      MOVWF            CNT1

                      GOTO              SECOND4

SECOND4         DECFSZ           CNT2

                      GOTO              FIRST4

                      MOVLW            0A6H

                      MOVWF            CNT2

                      GOTO              THIRD4

THIRD4            DECFSZ           CNT3

                      GOTO              FIRST4

                      RETURN

 

DEL005                                                                    ;0.05DELAY

                      MOVLW            0A6H

                      MOVWF            CNT1

                      MOVLW            0A6H

                      MOVWF            CNT2

 

                      BTFSC             ULTRA,3          

                      GOTO              OSOI5

                      BTFSC             ULTRA,2          

                      GOTO              OSOI5

                      BTFSC             ULTRA,1

                      GOTO              FUTSU5

                      BTFSC             ULTRA,0

                      GOTO              HAYAI5

                      GOTO              OSOI5

 

OSOI5              MOVLW            003H

                      MOVWF            CNT3

                      GOTO              FIRST5

FUTSU5           MOVLW            002H

                      MOVWF            CNT3

                      GOTO              FIRST5

HAYAI5            MOVLW            001H

                      MOVWF            CNT3

                      GOTO              FIRST5

 

FIRST5            DECFSZ           CNT1

                      GOTO              FIRST5

                      MOVLW            0A6H

                      MOVWF            CNT1

                      GOTO              SECOND5

SECOND5         DECFSZ           CNT2

                      GOTO              FIRST5

                      MOVLW            0A6H

                      MOVWF            CNT2

                      GOTO              THIRD5

THIRD5            DECFSZ           CNT3

                      GOTO              FIRST5

                      RETURN

                     

 

           END