;梵天丸を16F84Aで直接制御をする(2) ;赤外LED出力+受光モジュール検出による制御実験 ;クロックは8MHZ、赤外LEDは38KHZバースト発振 ;感度調整はバースト遅延時間によるがこまめな調整が必要 ;一関工業高等専門学校機械工学科 佐藤清忠 ; include 16f84.h .osc hs .pwrt on .wdt off .protect off ; org 0ch ; tm1 ds 1 tm2 ds 1 tm3 ds 1 ; t10 ds 1 t38 ds 1 mc ds 1 ; org 0 goto start ; start mov !ra,#10h mov !rb,#0h clr ra clr rb clr mc ; ;Lef LED 38khz pulse output X 10 times ; losc movlw 4 movwf t10 ; left movlw 0ffh movwf rb movlw 7 movwf t38 lth decfsz t38 goto lth ; movlw 0feh movwf rb movlw 7 movwf t38 ltl decfsz t38 goto ltl ; ln decfsz t10 goto left ; call tloss ; ; Left Refrecion Detect ; lrd btfss ra,4 ; goto lrd1 ; movlw 1 iorwf mc,1 goto lrd2 lrd1 movlw 0feh andwf mc,1 lrd2 movf mc,0 movwf ra call tloss call tloss call tloss call tloss ; ; Right ; rosc movlw 4 movwf t10 ; right movlw 0ffh movwf rb movlw 7 movwf t38 rth decfsz t38 goto rth ; movlw 0fdh movwf rb movlw 7 movwf t38 rtl decfsz t38 goto rtl ; rn decfsz t10 goto right ; call tloss ; ; Right Refrecion Detect ; rrd btfss ra,4 ; goto rrd1 ; movlw 2h iorwf mc,1 goto rrd2 rrd1 movlw 0fdh andwf mc,1 rrd2 movf mc,0 movwf ra call tloss call tloss call tloss call tloss ; goto losc ; ; ; time loss wait clr tm2 wait1 clr tm3 wait2 nop djnz tm3,wait2 djnz tm2,wait1 return ; tloss mov tm1,#100 ; 感度調整 tl1 nop djnz tm1,tl1 return ;