BhoomikaSheth
Newbie level 4
I am trying to make a micro-controller 8051 based mini project on line follower robot. please could someone check my source code file and give me some suggestions or rather corrections to be made in this source code file.
SOURCE CODE:-
PROGRAM FOR LINE FOLLOWER
=======SYSTEMREGISTERS==============
P0 EQU 080H
P1 EQU 090H
P2 EQU 0A0H
P3 EQU 0B0H
TH1 EQU 08DH
TL1 EQU 08BH
TCON EQU 088H
TMOD EQU 089H
IE EQU 0A8H
SP EQU 081H
FLAG1 EQU 0D0H;
=======PORTPINDEFINITIONS========
SENSOR1EQU P1.0
SENSOR2EQU P1.1
LED_RED EQU P0.6
LED_GREEN EQU P0.7
L_EN EQU P0.2
R_EN EQU P0.4
L_MO1 EQU P0.1
L_MO2 EQU P0.0
R_MO1 EQU P0.3
R_MO2 EQU P0.5
; X X X X M X L R
; X X X X 1 X 0 0 - FWD – 03
; 0 1 - TR 01
; 1 0 - TL 02
; 00 STOP 00
;========== HERE THE MAIN PROGRAM STARTS==========
ORG 0000H
AJMP START
ORG 0050H
START: MOV R1,#0FFH
MOV R2,#004H
MOV P2,#000H
LOOP:MOV C,SENSOR1
MOV LED_RED,C
MOV C,SENSOR2
MOV LED_GREEN,C
MOV A,P1
ANL A,#003H
CJNE A,#000H,CHECK_LEFT ;////// GO FORWARD /////////
SETB R_MO1
CLR R_MO2
SETB L_MO1
CLR L_MO2
MOV R1,#0FFH
MOV R2,#004H
AJMP LOOP
CHECK_LEFT:
CJNE A,#001H,CHECK_RIGHT ;////// TURN LEFT ///////////
SETB R_MO1
CLR R_MO2
CLR L_MO1
SETB L_MO2
MOV R1,#0FFH
MOV R2,#004H
HERE_LEFT:
MOV A,P1
ANL A,#003H
CJNE A,#003H,LEFT_CONT
DJNZ R1,LEFT_CONT
DJNZ R2,LEFT_CONT
AJMP STOP
LEFT_CONT:
JB P1.0,HERE_LEFT
AJMP LOOP
CHECK_RIGHT:
CJNE A,#002H,CHECK_STOP;/////// TURN RIGHT ///////
CLR R_MO1
SETB R_MO2
SETB L_MO1
CLR L_MO2
MOV R1,#0FFH
MOV R2,#004H
HERE_RIGHT:
MOV A,P1
ANL A,#003H
CJNE A,#003H,RIGHT_CONT
DJNZ R1,LEFT_CONT
DJNZ R2,LEFT_CONT
AJMP STOP
RIGHT_CONT:
JB P1.1,HERE_RIGHT
AJMP LOOP
CHECK_STOPJNZ R1,LOOP
STOP:
SETB R_MO1
SETB R_MO2
SETB L_MO1
SETB L_MO2
HERE_STOP:AJMP HERE_STOP
END
SOURCE CODE:-
PROGRAM FOR LINE FOLLOWER
=======SYSTEMREGISTERS==============
P0 EQU 080H
P1 EQU 090H
P2 EQU 0A0H
P3 EQU 0B0H
TH1 EQU 08DH
TL1 EQU 08BH
TCON EQU 088H
TMOD EQU 089H
IE EQU 0A8H
SP EQU 081H
FLAG1 EQU 0D0H;
=======PORTPINDEFINITIONS========
SENSOR1EQU P1.0
SENSOR2EQU P1.1
LED_RED EQU P0.6
LED_GREEN EQU P0.7
L_EN EQU P0.2
R_EN EQU P0.4
L_MO1 EQU P0.1
L_MO2 EQU P0.0
R_MO1 EQU P0.3
R_MO2 EQU P0.5
; X X X X M X L R
; X X X X 1 X 0 0 - FWD – 03
; 0 1 - TR 01
; 1 0 - TL 02
; 00 STOP 00
;========== HERE THE MAIN PROGRAM STARTS==========
ORG 0000H
AJMP START
ORG 0050H
START: MOV R1,#0FFH
MOV R2,#004H
MOV P2,#000H
LOOP:MOV C,SENSOR1
MOV LED_RED,C
MOV C,SENSOR2
MOV LED_GREEN,C
MOV A,P1
ANL A,#003H
CJNE A,#000H,CHECK_LEFT ;////// GO FORWARD /////////
SETB R_MO1
CLR R_MO2
SETB L_MO1
CLR L_MO2
MOV R1,#0FFH
MOV R2,#004H
AJMP LOOP
CHECK_LEFT:
CJNE A,#001H,CHECK_RIGHT ;////// TURN LEFT ///////////
SETB R_MO1
CLR R_MO2
CLR L_MO1
SETB L_MO2
MOV R1,#0FFH
MOV R2,#004H
HERE_LEFT:
MOV A,P1
ANL A,#003H
CJNE A,#003H,LEFT_CONT
DJNZ R1,LEFT_CONT
DJNZ R2,LEFT_CONT
AJMP STOP
LEFT_CONT:
JB P1.0,HERE_LEFT
AJMP LOOP
CHECK_RIGHT:
CJNE A,#002H,CHECK_STOP;/////// TURN RIGHT ///////
CLR R_MO1
SETB R_MO2
SETB L_MO1
CLR L_MO2
MOV R1,#0FFH
MOV R2,#004H
HERE_RIGHT:
MOV A,P1
ANL A,#003H
CJNE A,#003H,RIGHT_CONT
DJNZ R1,LEFT_CONT
DJNZ R2,LEFT_CONT
AJMP STOP
RIGHT_CONT:
JB P1.1,HERE_RIGHT
AJMP LOOP
CHECK_STOPJNZ R1,LOOP
STOP:
SETB R_MO1
SETB R_MO2
SETB L_MO1
SETB L_MO2
HERE_STOP:AJMP HERE_STOP
END