You are on page 1of 3

ORG 00H

INIT:
MOV R4,#99H
MOV R5,#99H
BEGIN:
FRONTSENSOR_POSITION:
MOV C,P1.0
JNC LOOP3
SJMP LEFTSENSOR_POSITION
LOOP3:
ACALL TURN_RIGHT
SETB P1.0
LEFTSENSOR_POSITION:
MOV C,P1.1
JNC LOOP2
SJMP RIGHTSENSOR_POSITION
LOOP2:
ACALL TURN_LEFT
SETB P1.1
RIGHTSENSOR_POSITION:
MOV C,P1.2
JNC LOOP1
SJMP BEGIIN
LOOP1:
ACALL TURN_RIGHT
SETB P1.2

BEGIIN:
ACALL NEXT_SENSING_POINT
SJMP FRONTSENSOR_POSITION
DELAY:
MOV B,#02FH
DELAYLOOP:
ACALL DELAY1
DJNZ B,DELAYLOOP
RET
BIGDELAY:
MOV B,#0FFH
BDELAYLOOP:
ACALL DELAY1
DJNZ B,BDELAYLOOP
RET
DELAY1:
MOV ACC,#0FFH
DELAYLOOP1:
DJNZ ACC,DELAYLOOP1
RET

; FUNCTIONS TO MOVE MOTORS
NEXT_SENSING_POINT: ; MOVES ROBOT FROM ONE SENSING POINT TO NEXT ONE
;TOTALY 28X4=112 STEPS ARE NEEDED TO MOVE 44CMS ON THE ARENA
MOV R0,#25
LOOP00: ACALL ROBOT_FARWORD

END OF ROBOT_FORWARD ROBOT_BACKWORD .LOOP22 RET ROBOT_FARWORD .A ANL B.#0FH ANL A.A MOV P0. IT NEEDS 11X2=33 STEPS TO EXACTLY ROTATE ROBOT 90` MOV R0. MOVES ROBOT LEFT EXACTLY 90` .#0FH ANL A. IT NEEDS 11X3=33 STEPS TO EXACTLY ROTATE ROBOT 90` MOV R0. HERE MOVE LEFT MOTOR ANTICLOCKWISE AND RIGHT MOTOR CLOCKWISE MOV A. MOVES ROBOT FORWARD ONE STEP BOTH MOTORS FORWARD .LOOP00 RET BACKWARD: .R4 RR A MOV R4.B ACALL DELAY RET .A MOV B. DJNZ R0.R4 RR A MOV R4.#44 LOOP22: ACALL ROBOT_RIGHT DJNZ R0.#44 LOOP11: ACALL ROBOT_LEFT DJNZ R0.A MOV A.#0F0H ORL B.LOOOP RET TURN_LEFT: .A MOV A.B ACALL DELAY ACALL DELAY RET .#0F0H ORL B.A MOV P0.LOOP11 RET TURN_RIGHT: . HERE MOVE LEFT MOTOR CLOCKWISE AND RIGHT MOTOR ANTICLOCKWISE MOV A.IT WILL MOVE THE ROBOT BACKWARD MOV R0.A ANL B.#30 LOOOP: ACALL ROBOT_BACKWORD DJNZ R0. MOVES ROBOT LEFT EXACTLY 90` .R5 RL A MOV R5. MOVES ROBOT FORWARD ONE STEP BOTH MOTORS FORWARD .R5 RL A MOV R5.A MOV B.

A ANL B. MOVES ROBOT FORWARD ONE STEP BOTH MOTORS FORWARD .R4 RL A MOV R4.#0FH ANL A..A MOV A. END OF ROBOT_RIGHT ROBOT_LEFT .B ACALL DELAY ACALL DELAY RET .R4 RR A MOV R4.A MOV A.R5 RL A MOV R5. HERE MOVE LEFT MOTOR ANTICLOCKWISE AND RIGHT MOTOR ANTICLOCKWISE MOV A.#0FH ANL A.A MOV B.A MOV B. END OF ROBOT_BACKWORD ROBOT_RIGHT .#0F0H ORL B. HERE MOVE LEFT MOTOR CLOCKWISE AND RIGHT MOTOR CLOCKWISE MOV A.R5 RR A MOV R5. MOVES ROBOT FORWARD ONE STEP BOTH MOTORS FORWARD .A MOV P0.A MOV P0.#0F0H ORL B.B ACALL DELAY ACALL DELAY RET . END OF ROBOT_LEFT .A ANL B.