;TJACO'S DESIGN GRAVEYARD: WWW.GEOCITIES.COM/TJACODESIGN ;
;22 JULY 2002 ;
;CERBERES : MINI ROBOT WITH IR EYES ;
;USES PIC16F84 µCONTROLLER ;
;WRITTEN IN MICROCHIP ASSEMBLY USE MPASM ASSEMBLER FROM MPLAB ;
;MPLAB CAN BE DOWNLOADED FROM WWW.MICROCHIP.COM ;
;***SET UP THE CONTANTS & VARIABLES****
LIST P=16F84
ERRORLEVEL -302 ;SUPPRESS BANK SELECTION MESSAGES
STATUS EQU H'03' ;STATUS REGISTER
TRISB EQU H'86' ;TRISB REGISTER FOR SETUP OF PORTB
PORTB EQU H'06' ;PORTB REGISTER TO DRIVE PORT B
COUNT1 EQU H'0C' ;COUNT VARIABLE 1 IS IN GENERAL PURPOSE REG 08H
COUNT2 EQU H'0D' ;COUNT VARIABLE 2 IS IN GENERAL PURPOSE REG 09H
;***SET UP PORT B IN & OUTPUT****
BSF STATUS,5 ;SWITCH TO BANK0 TO SET UP PORT B
MOVLW B'11110000' ;RB7,6,5,4 IS INPUT
MOVWF TRISB ;RB3,2,1,0 IS OUTPUT
BCF STATUS,5 ;SWITCH BACK TO BANK0 TO USE PORT B
;***MAIN PROGRAM****
START MOVLW B'00000101' ;MAKE RB0&2 HIGH: MOVE FORWARD start of main loop
MOVWF PORTB ; turn both motors on forwards
MOVLW H'FE' ;RESET COUNT1 TO 254
MOVWF COUNT1 ;
MOVLW H'FE' ;RESET COUNT2 TO 254
MOVWF COUNT2 ; ; now check if either sensor is activated
BTFSS PORTB,5 ;CHECK RB5 (INPUT); IF IT IS LOW is sensor left low, if not test for sensor right
CALL BACKL ;THEN EXECUTE BACKLEFT ROUTINE if so turn both motors backwards
BTFSS PORTB,6 ;CHECK RB6 (INPUT); IF IT IS LOW is sensor right low
CALL BACKR ;EXECUTE BACKRIGHT ROUTINE if so turn both motors backwards
; nothing sensed so go forwards again
GOTO START ;RETURN TO LABEL START goto main loop
;***BACKLEFT ROUTINE**** backleft
BACKL MOVLW B'00001010' ;MAKE RB1&3 HIGH: MOVE BACKWARD turn both motors backwards
MOVWF PORTB ; for the delay time of around 1/4 second ?
CALL DELAY ;'
; CALL DELAY ; EXTRA BACK OFF DELAY TIME - remove ';' to activate
MOVLW B'00001001' ;MAKE RB2&3 HIGH: ROTATE LEFT now turn left motor backwards and right motor forwards
MOVWF PORTB ; do that for the delay time
CALL DELAY ; return to main loop
RETURN
;***BACKRIGHT ROUTINE**** back right
BACKR MOVLW B'00001010' ;MAKE RB1&3 HIGH: MOVE BACKWARD as for back left but motors in the opposite direction
MOVWF PORTB ;
CALL DELAY ;
; CALL DELAY ; EXTRA BACK OFF DELAY TIME - remove ';' to activate
MOVLW B'00000110' ;MAKE RB2&3 HIGH: ROTATE RIGHT
MOVWF PORTB ;
CALL DELAY ;
RETURN
DELAY MOVLW H'EE' ;RESET ALL COUNTER VARIABLES this is the delay routine
MOVWF COUNT1 ; it depends on the timing for R5 and C3 , estimated at around 1/4 second
MOVLW H'99'
MOVWF COUNT2
LOOP1 CLRWDT ;RESET THE WATCHDOG TIMER
DECFSZ COUNT1,1 ;this is a delay loop
GOTO LOOP1 ;tuned to make Cerberes
DECFSZ COUNT2,1 ;turn about 90 degrees
GOTO LOOP1
RETURN ; end of delay routine
END;