振動スイッチを活用 振動(傾き)を検出 ボールが移動 a)オン時 b)オフ時 オンからオフ時の観察 処理の流れ(フローチャート) 振動スィッチの オン/オフ状態を 調べる LOOP0 MOVLW D'20' MOVWF KAISU MOVLW D'0' MOVWF HENKA CHECK1 BTFSC PORTA,5 GOTO CHECK2 CALL WAIT1 BTFSC PORTA,5 INCF HENKA,1 GOTO CHECK9 CHECK2 CALL WAIT1 BTFSS PORTA,5 INCF HENKA,1 CHECK9 DECFSZ KAISU,1 GOTO CHECK1 LOOP0 MOVLW MOVWF MOVLW MOVWF CHECK1 BTFSC GOTO CALL BTFSC INCF GOTO CHECK2 CALL BTFSS INCF CHECK9 D'20' KAISU D'0' HENKA PORTA,5 CHECK2 WAIT1 PORTA,5 HENKA,1 CHECK9 WAIT1 PORTA,5 HENKA,1 LOOP0 MOVLW D'20' MOVWF KAISU MOVLW D'0' MOVWF HENKA CHECK1 BTFSC GPIO,4 命令語1 GOTO MOVLW CHECK2 X CALL WAIT1 BTFSC機能:Xの値をWレジスタに記憶 GPIO,4 INCF HENKA,1 「W=X」 GOTO CHECK9 CHECK2 CALL WAIT1 BTFSS PORTA,5 INCF HENKA,1 CHECK9 LOOP0 MOVLW D'20' MOVWF KAISU MOVLW D'0' MOVWF HENKA CHECK1 BTFSC GPIO,4 命令語2 GOTO MOVWF CHECK2 X CALL WAIT1 BTFSC機能:Wの値をXレジスタに記憶 GPIO,4 INCF HENKA,1 「X=W」 GOTO CHECK9 CHECK2 CALL WAIT1 BTFSS PORTA,5 INCF HENKA,1 CHECK9 LOOP0 MOVLW MOVWF MOVLW MOVWF CHECK1 BTFSC GOTO CALL BTFSC INCF GOTO CHECK2 CALL BTFSS INCF CHECK9 D'20' KAISU D'0' HENKA PORTA,5 CHECK2 WAIT1 PORTA,5 HENKA,1 CHECK9 WAIT1 PORTA,5 HENKA,1 命令語3 BTFSC X, N LOOP0 MOVLW D'20' 機能:XレジスタのNビットを調べ、 MOVWF KAISU MOVLW0(クリア)ならば次の命令をスキップ D'0' MOVWF HENKA CHECK1 BTFSC PORTA,5 GOTO CHECK2 CALL WAIT1 BTFSC PORTA,5 INCF HENKA,1 GOTO CHECK9 CHECK2 CALL WAIT1 BTFSS PORTA,5 INCF HENKA,1 CHECK9 命令語4 GOTO ラベル LOOP0 MOVLW D'20' 機能:指定のラベル行へジャンプ MOVWF KAISU MOVLW (処理を移行) D'0' MOVWF HENKA CHECK1 BTFSC PORTA,5 GOTO CHECK2 CALL WAIT1 BTFSC PORTA,5 INCF HENKA,1 GOTO CHECK9 CHECK2 CALL WAIT1 BTFSS PORTA,5 INCF HENKA,1 CHECK9 LOOP0 MOVLW MOVWF MOVLW MOVWF CHECK1 BTFSC GOTO CALL BTFSC INCF GOTO CHECK2 CALL BTFSS INCF CHECK9 D'20' KAISU D'0' HENKA PORTA,5 CHECK2 WAIT1 PORTA,5 HENKA,1 CHECK9 WAIT1 PORTA,5 HENKA,1 命令語5 CALL ラベル LOOP0 MOVLW D'20' 機能:指定ラベルのサブルーチンを MOVWF KAISU MOVLW呼び出す(終了後は次の命令に戻る) D'0' MOVWF HENKA CHECK1 BTFSC PORTA,5 GOTO CHECK2 CALL WAIT1 BTFSC PORTA,5 INCF HENKA,1 GOTO CHECK9 CHECK2 CALL WAIT1 BTFSS PORTA,5 INCF HENKA,1 CHECK9 命令語6 INCF X, 1 LOOP0 MOVLW D'20' 機能:レジスタXの値を+1する MOVWF KAISU MOVLW D'0' MOVWF HENKA CHECK1 BTFSC PORTA,5 GOTO CHECK2 CALL WAIT1 BTFSC PORTA,5 INCF HENKA,1 GOTO CHECK9 CHECK2 CALL WAIT1 BTFSS PORTA,5 INCF HENKA,1 CHECK9 MOVWF KAISU MOVLW D'0' MOVWF HENKA CHECK1 BTFSC PORTA,5 GOTO CHECK2 CALL WAIT1 BTFSC PORTA,5 INCF HENKA,1 GOTO CHECK9 CHECK2 CALL WAIT1 BTFSS PORTA,5 INCF HENKA,1 CHECK9 DECFSZ KAISU,1 GOTO CHECK1 MOVWF 命令語7 KAISU MOVLWBTFSS D'0' X, N MOVWF HENKA CHECK1 機能:XレジスタのNビットを調べ、 BTFSC GPIO,4 1(セット)ならば次の命令をスキップ GOTO CHECK2 CALL WAIT1 BTFSC PORTA,5 INCF HENKA,1 GOTO CHECK9 CHECK2 CALL WAIT1 BTFSS PORTA,5 INCF HENKA,1 CHECK9 DECFSZ KAISU,1 GOTO CHECK1 MOVLW D'0' MOVWF HENKA CHECK1 BTFSC PORTA,5 GOTO CHECK2 CALL WAIT1 BTFSC PORTA,5 INCF HENKA,1 GOTO CHECK9 CHECK2 CALL WAIT1 BTFSS PORTA,5 INCF HENKA,1 CHECK9 DECFSZ KAISU,1 GOTO CHECK1 MOVLW 命令語8 D'0' MOVWF HENKAX, 1 DECFSZ CHECK1 機能:Xレジスタの値を-1し、 BTFSC GPIO,4 GOTO CHECK2 CALL 0(ゼロ)ならば次の命令をスキップ WAIT1 BTFSC PORTA,5 INCF HENKA,1 GOTO CHECK9 CHECK2 CALL WAIT1 BTFSS PORTA,5 INCF HENKA,1 CHECK9 DECFSZ KAISU,1 GOTO CHECK1 LOOP0 MOVLW D'20' MOVWF KAISU MOVLW D'0' MOVWF HENKA CHECK1 BTFSC PORTA,5 GOTO CHECK2 CALL WAIT1 BTFSC PORTA,5 INCF HENKA,1 GOTO CHECK9 CHECK2 CALL WAIT1 BTFSS PORTA,5 INCF HENKA,1 CHECK9 DECFSZ KAISU,1 GOTO CHECK1
© Copyright 2024 ExpyDoc