Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Please check the following source code...

Status
Not open for further replies.

BhoomikaSheth

Newbie level 4
Newbie level 4
Joined
Aug 6, 2011
Messages
7
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,350
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_STOP:DJNZ R1,LOOP

STOP:
SETB R_MO1
SETB R_MO2
SETB L_MO1
SETB L_MO2

HERE_STOP:AJMP HERE_STOP

END
 

These kind of instructions wont work...
Code:
MOV R2,#004H
MOV P2,#000H
Because, for immediate data, '0' should be appended after # only when hex letter is used(A...F)
If you are using Keil A51, I dont think you require to define System Register. They are already defined in MCS51 architecture.

NOTE:- When you are using P0 port in O/P mode, please connect 10K Pull up to it. Otherwise, you will blow of the controller.
 
Hello..
My teacher asked me to write a program for line following robot again in a simpler and a easy way USING 2051MICRORONTROLLER. So I tried... and this is what I have formed.... Can anyone please tell me IF I am wrong anywhere or if I need to change my program anyhow??

ORG 00H
LJMP START

ORG 30H
START: MOV P1.6,#1B ; CONFIG P1.6 AS I/P PIN
MOV C,P1.6 ; I HAVE CONNECTED A S/W HERE TO START THE ROBOT
JC STOP
MOV P3,#3CH ;4 SENSOR INPUTS ARE CONNECTED AT P3.5,P3.4,P3.3 AND P3.2
MOV P1,#00H ;CONFIG AS O/P PORT
CLR A
AGAIN: MOV A,P3
ANL A,#14H ; CHECK IF FRONT ON BACK SENSOR ARE ON
JB P3.3,CHECK_LEFT ; CHECK IF LEFT SIDE SENSOR IS ON
JB P3.5,CHECK_RIGHT ; CHECK IF RIGHT SIDE SENSOR IS ON
CJNE A,#14H,STOP ; CHECK IF FRONT ON BACK SENSOR ARE ON
SETB P1.0 ; ENABLE 1 OF L293D MOTOR DRIVER IC
SETB P1.1 ;ENABLE 2 OF L293D MOTOR DRIVER IC
SETB P1.2 ;ROTATE RIGHT MOTOR IN CLOCKWISE DIRECTION
CLR P1.3 ;ROTATE RIGHT MOTOR IN CLOCKWISE DIRECTION
SETB P1.4 ;ROTATE LEFT MOTOR IN CLOCKWISE DIRECTION
CLR P1.3 ;ROTATE LEFT MOTOR IN CLOCKWISE DIRECTION
AJMP AGAIN

CHECK_LEFT:
MOV A,P3
ANL A, #08H
CJNE A,#08H,AGAIN ;RECHECK IF LEFT SIDE SENSOR IS ON
SETB P1.0 ; ENABLE 1 OF L293D MOTOR DRIVER IC
SETB P1.1 ;ENABLE 2 OF L293D MOTOR DRIVER IC
SETB P1.2 ;ROTATE RIGHT MOTOR IN CLOCKWISE DIRECTION
CLR P1.3 ;ROTATE RIGHT MOTOR IN CLOCKWISE DIRECTION
CLR P1.4 ;ROTATE LEFT MOTOR IN ANTICLOCKWISE DIRECTION
SETB P1.3 ;ROTATE LEFT MOTOR IN ANTICLOCKWISE DIRECTION
ACALL DELAY
AJMP AGAIN

CHECK_RIGHT:
MOV A,P3
ANL A, #20H
CJNE A,#20H,AGAIN ;RECHECK IF LEFT SIDE SENSOR IS ON
SETB P1.0 ; ENABLE 1 OF L293D MOTOR DRIVER IC
SETB P1.1 ;ENABLE 2 OF L293D MOTOR DRIVER IC
CLR P1.2 ;ROTATE RIGHT MOTOR IN ANTICLOCKWISE DIRECTION
SETB P1.3 ;ROTATE RIGHT MOTOR IN ANTICLOCKWISE DIRECTION
SETB P1.4 ;ROTATE LEFT MOTOR IN CLOCKWISE DIRECTION
CLR P1.3 ;ROTATE LEFT MOTOR IN CLOCKWISE DIRECTION
ACALL DELAY
AJMP AGAIN

DELAY:
CLR TF0
MOV R0,#14H
L1: MOV TL0,#00H
MOV TH0, #4CH
SETB TR0
L2: JNB TF0,L2
CLR TR0
CLR TF0
DJNZ R0,L1
RET

STOP:
MOV A,P3
ANL A, #3CH
CJNE A,#00H,AGAIN ; RE-RCHECK IF ANY SENSOR ON
SETB P1.2 ; STOP RIGHT MOTOR
SETB P1.3 ; STOP RIGHT MOTOR
SETB P1.4 ; STOP LEFT MOTOR
SETB P1.5 ; STOP LEFT MOTOR
END
 

pls help .... will moving one wheel in clockwise direction and other in anti clockwise direction actually turn the robot??
 

If you move one wheel in clockwise direction, keep the other one off; don't move that in anti-clockwise direction. Then your robot should turn.
 
I've been looking at this without seeing 8051 for 10 years in practicalness, so I am intriqued!! I have read through your code a few times and all looks cool but I'd make a couple of changes if it were mine, but only for duiscussion purposes.,,,,,,

[only a suggestion :)]
I see you have references to motor enable L_EN pins, but nothing in the code for using them... I would maybe rather than changing direction-of-turn on the motor, you should just disable one, bit less stress on the gears and motor and stuff... Its probably only a couple of lines of code to say ouput "the sensor input" for left straight onto the enable line for right motor, and the opposite for right... It'll work like PWM at the speed your code'll be running too, superb!

I've been thinking about (but never made till now) a similar thing using 2 PNP transistors since the age of about 10 and its sort of developed in my head following with the technology I'm looking at!!! My next plan (for my "1st stepper motor robot 16f877'd up" is to have ultrasound so it maps its environment, but not this week!!!)

[/only a suggestion :)]

Best regards
NEAL
 
thank you.... thanks a lot for all your valuable suggestions.... it really means a lot...
 
Did it work mate? Post a vid eh!!
:)
NEAL
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top