assembly code for line following robot, 89C2051,89C2051

The complete assembly code is as below


INCLUDE 89C2051.mc

'Defining constants
Forward EQU 67h
RightBack EQU 51h
LeftBack EQU 4Ah

    ORG 0000h

AJMP Main

    ORG 0030h

Main: 
     MOV P1,#00h                                'Disable Motor Driver
     MOV P3,#0FFh                              'Set P3 as input port to read sensor o/p 
     SETB P1.6                         'Make P1.6 to which switch is connected
                                                                 'an i/p
Start:
     JNB P1.6,Finish                               'Stop if switch at P1.6 is pressed
     MOV P1,#Forward
     CALL Delay                                      'Produce 0.05s delay
     JNB P3.2,R_Back                           'If Right Sensor at P3.2 is activated
                                                                 'bring right wheel back
Next: 
     MOV P1,#Forward
     CALL Delay
     JNB P3.3,L_Back                           'If Left Sensor at P3.3 is activated

                                                                 'bring left wheel back                 
Back:
     AJMP Start                                      'Repeat above operation

Finish:
     MOV P1,#00h                                'Disable Motor Driver

Again:
     SJMP Again                    'Loop forever

R_Back:
     MOV P1,#RightBack
     JNB P3.2,R_Back                           'Repeat if Right Sensor is still activated
     SJMP Next  

L_Back:
     MOV P1,#LeftBack
     JNB P3.3,L_Back                           'Repeat if Left Sensor is still activated
     SJMP Back

Delay:                                                    'Produces approx 0.05s delay
     MOV R0,#255
Time1: 
     MOV R1,#255
Time2:
     DJNZ R1,Time2
     DJNZ R0,Time1
     RET


    END

No comments:

Post a Comment

its cool