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.

simply 8051 program any handsome would help?

Status
Not open for further replies.

johnny01hk

Junior Member level 1
Joined
Apr 8, 2010
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,432
I was done a program.
The concept as below:
I will have two input into the IC (P2.0 and P2.1),
The input will be a digital signal.

When P2.0 Input signal is 1.
Then Will have output, It may be P1.1,
And it will output 5second times 5V signal to the motor.

In other ways, The P2.1 will be the same,
But the output is P1.2 .

But It is not work.

And I want 5second delay of the process.
So that what is my program problem and how to correct it?




-----------------------------------------
ORG 00H
JMP START

ORG 100h
START: SETB P2.0 ;Motion detector Input
SETB P2.1 ;Metal detector Input

JB P2.0, $ ;If Motion detector Input 1
JMP X ;Go to X

JB P2.1, $ ;If Metal detector Input 1
JMP Z ;Go to Z


Z: SETB P1.2
CLR P1.3
MOV R4,#2 ; set delay for 60s ..
MOV R3,#166
MOV R2,#223
MOV R1,#117
RET

X: SETB P1.3
MOV R4,#2 ; set delay for 60s ..
MOV R3,#166
MOV R2,#223
MOV R1,#117
RET


END


--------------------------------------------------
A51 MACRO ASSEMBLER V1.13
COPYRIGHT MANLEY ELECTRONICS CO., LTD. 2001-2006
ASSEMBLY COMPLETE. 0 WARNING(S), 0 ERROR(S)
 

Take a look at this modified code and try to visualise how it may work ..

Code:
ORG 00H 
	JMP	START 

ORG 100h
 
START:
	SETB	P2.0		;Motion detector Input 
	SETB	P2.1		;Metal detector Input
	CLR	P1.0
	CLR	P1.1 
Loop:
	JNB	P2.0, X
	JNB	P2.1, Z
	SJMP	Loop

; = = = = = = = = = = = = = =

X:
	SETB	P1.0  
	LCALL Delay		;Call Delay
	SJMP	START 

Z:
	SETB	P1.1 
	LCALL Delay		;Call Delay
	SJMP	START

; = = = = = = = = = = = = = =

Delay:
	MOV	R4,#2		; set delay for 60s
	MOV	R3,#166 
	MOV	R2,#223 
	MOV	R1,#117 
TT1:
	DJNZ	R1,TT1 
	DJNZ	R2,TT1 
	DJNZ	R3,TT1 
	DJNZ	R4,TT1 
RET

END

Is that the way you wanted it to work?

Rgds,
IanP
:|
 

    johnny01hk

    Points: 2
    Helpful Answer Positive Rating
IanP said:
Take a look at this modified code and try to visualise how it may work ..

Code:
ORG 00H 
	JMP	START 

ORG 100h
 
START:
	SETB	P2.0		;Motion detector Input 
	SETB	P2.1		;Metal detector Input
	CLR	P1.0
	CLR	P1.1 
Loop:
	JNB	P2.0, X
	JNB	P2.1, Z
	SJMP	Loop

; = = = = = = = = = = = = = =

X:
	SETB	P1.0  
	LCALL Delay		;Call Delay
	SJMP	START 

Z:
	SETB	P1.1 
	LCALL Delay		;Call Delay
	SJMP	START

; = = = = = = = = = = = = = =

Delay:
	MOV	R4,#2		; set delay for 60s
	MOV	R3,#166 
	MOV	R2,#223 
	MOV	R1,#117 
TT1:
	DJNZ	R1,TT1 
	DJNZ	R2,TT1 
	DJNZ	R3,TT1 
	DJNZ	R4,TT1 
RET

END

Is that the way you wanted it to work?

Rgds,
IanP
:|

Thx for your help!
It sound very great,
But If I want to change the delay time for 5second,
How to correct it?
 

Just play with the delay subroutine ..
Here are two additional (slightly different) examples for 0.5s and 1s:
Code:
;---------------------------Delay----- 

1s_DELAY: 
MOV 	R2, #50 ;~1s 
S1:
MOV	R3, #200 
S2:
MOV	R4, #200 
DJNZ	R4, $ 
DJNZ	R3, S2 
DJNZ	R2, S1 
RET 


0_5s_DELAY: 
MOV	R2, #50 ;~0.5s
S11:
MOV	R3, #250 
S22:
MOV	R4, #250 
DJNZ	R4, $ 
DJNZ	R3, S22 
DJNZ	R2, S11 
RET 

;---------------------

For example, call 1s sub 5 times ..

Also, keep in mind that these delay subs are valid for 11,0592MHz clock ..
If you use different crystal the delays will be longer/shorter ..

Rgds,
IanP
:D
 

    johnny01hk

    Points: 2
    Helpful Answer Positive Rating
IanP said:
Just play with the delay subroutine ..
Here are two additional (slightly different) examples for 0.5s and 1s:
Code:
;---------------------------Delay----- 

1s_DELAY: 
MOV 	R2, #50 ;~1s 
S1:
MOV	R3, #200 
S2:
MOV	R4, #200 
DJNZ	R4, $ 
DJNZ	R3, S2 
DJNZ	R2, S1 
RET 


0_5s_DELAY: 
MOV	R2, #50 ;~0.5s
S11:
MOV	R3, #250 
S22:
MOV	R4, #250 
DJNZ	R4, $ 
DJNZ	R3, S22 
DJNZ	R2, S11 
RET 

;---------------------

For example, call 1s sub 5 times ..

Also, keep in mind that these delay subs are valid for 11,0592MHz clock ..
If you use different crystal the delays will be longer/shorter ..

Rgds,
IanP
:D

Thank you very much for your help!!
I am very grateful to have you help me to correct my bad program.

You good then my teacher!
My teacher always said you need to solve by youself,
So that I so worry about that,
Cos I am strong on program.

And my dead line is on 10 May 2010...
And I still have some part not finnish..

So thx you very very much!
My loverly teacher,haha:D

By the ways, I add the delay subroutine on the program as below:
It is right?


ORG 00H
JMP START

ORG 100h

START:
SETB P2.0 ;Motion detector Input
SETB P2.1 ;Metal detector Input
CLR P1.0
CLR P1.1
Loop:
JNB P2.0, X
JNB P2.1, Z
SJMP Loop

; = = = = = = = = = = = = = =

X:
SETB P1.0
LCALL Delay ;Call Delay
SJMP START

Z:
SETB P1.1
LCALL Delay ;Call Delay
SJMP START

; = = = = = = = = = = = = = =

Delay:
MOV R2, #50 ;~1s
S1:
MOV R3, #200
S2:
MOV R4, #200
DJNZ R4, $
DJNZ R3, S2
DJNZ R2, S1
RET

TT1:
DJNZ R1,TT1
DJNZ R2,TT1
DJNZ R3,TT1
DJNZ R4,TT1
RET

END
 

Yes it works. Thank you. How can I modify the program to turn on the motors simultaneously?
 

Clean the code by removing this stuff:

TT1:
DJNZ R1,TT1
DJNZ R2,TT1
DJNZ R3,TT1
DJNZ R4,TT1
RET

It's a left-over from the previous version of the delay subroutine ..

Rgds,
IanP
:|


You good then my teacher!
My teacher always said you need to solve by youself,
So that I so worry about that,
Cos I am strong on program.

And my dead line is on 10 May 2010...
And I still have some part not finnish..

So thx you very very much!
My loverly teacher, haha
Simply nice [poem], mate ..

Added after 12 minutes:

macer_0001 said:
Yes it works. Thank you. How can I modify the program to turn on the motors simultaneously?
Set both pins in X and Z:
Code:
X: 
SETB P1.0
SETB P1.1
LCALL Delay ;Call Delay 
SJMP START 

Z:
SETB P1.0
SETB P1.1 
LCALL Delay ;Call Delay 
SJMP START

but then you don't need two separate cases, one will do ..

Code:
...

Loop: 
JNB P2.0, X 
JNB P2.1, X 
SJMP Loop

...

X: 
SETB P1.0
SETB P1.1
LCALL Delay ;Call Delay 
SJMP START

...
 

Ianp,

Thank you. Back to original idea but when the one of the pin triggered and activates one motor. then, the time is in the middle of delay(let's say about 2.5 seconds) the other pin triggers. what modification to turn on the other motor while the other motor turned on in a middle of the delay set?

macer
 

Sorry IanP,
I have change the progarm,
But still not work.

Because my Motion detector Input must output Logic 1,
When the Metal detector Input Logic 1,
the motion dectector still has Logic 1 too.

It show us, the output P 1.0 must output 5V,

So that I have add that CLR on X and Y on progarm.
But still not work.
In other ways, When metal dedector input Logic one,
the motor can not move(May be hurted for two p 1.0 and p1.1 output 5V)

So that how to solve this problem?:cry:

I want to the metal detector work and auto ignore the motion detector input one.

How to amend this progarm?

---------------------
ORG 00H
JMP START

ORG 100h

START:
SETB P2.0 ;Motion detector Input
SETB P2.1 ;Metal detector Input
CLR P1.0
CLR P1.1

Loop:
JNB P2.0, X
JNB P2.1, Z
SJMP Loop

; = = = = = = = = = = = = = =

X:
SETB P1.0
CLR P1.1
LCALL Delay ;Call Delay
SJMP START

Z:
SETB P1.1
CLR P1.0
LCALL Delay ;Call Delay
SJMP START

; = = = = = = = = = = = = = =

Delay:
MOV R2, #50 ;~1s
S1:
MOV R3, #200
S2:
MOV R4, #200
DJNZ R4, $
DJNZ R3, S2
DJNZ R2, S1
RET

END
 

It can be sorted out in many ways, but I’d like to see a proper truth table(s) that fully describe what should happen with outputs P1.0 and P1.1 when inputs are “H” or “L” ..
I’ve got the filling that we have to use an interrupt pin (/Int0 or /Int1) rather than a general purpose i/o (such as P2.0 or P2.1), however this will become clear after you supply the tables (or timing diagrams - see exaple below) ..

Rgds,
IanP
:|

https://en.wikipedia.org/wiki/Digital_timing_diagram
**broken link removed**
 

IanP said:
It can be sorted out in many ways, but I’d like to see a proper truth table(s) that fully describe what should happen with outputs P1.0 and P1.1 when inputs are “H” or “L” ..
I’ve got the filling that we have to use an interrupt pin (/Int0 or /Int1) rather than a general purpose i/o (such as P2.0 or P2.1), however this will become clear after you supply the tables (or timing diagrams - see exaple below) ..

Rgds,
IanP
:|

https://en.wikipedia.org/wiki/Digital_timing_diagram
**broken link removed**

Thx IanP,
I Think I can use NOR Gate to solve this problem at hardware before that output!
You are my great teacher!
Ths so much!
Johnny

Added after 9 minutes:

johnny01hk said:
IanP said:
It can be sorted out in many ways, but I’d like to see a proper truth table(s) that fully describe what should happen with outputs P1.0 and P1.1 when inputs are “H” or “L” ..
I’ve got the filling that we have to use an interrupt pin (/Int0 or /Int1) rather than a general purpose i/o (such as P2.0 or P2.1), however this will become clear after you supply the tables (or timing diagrams - see exaple below) ..

Rgds,
IanP
:|

https://en.wikipedia.org/wiki/Digital_timing_diagram
**broken link removed**

Thx IanP,
I Think I can use NOR Gate to solve this problem at hardware before that output!
You are my great teacher!
Ths so much!
Johnny

The truth table as below:

X Y Out
00 0
01 0
10 1
11 0

Which gate can help me make this Logic output?

Johnny
 

Your truth table tells that Z = X and [notY] .. see attached picture .. but if you provided timing diagram this function could be implemented in software ..

Rgds,
IanP
 

I was burn the program into 89S52 IC.
But not working.

It is my progarm problem or my IC hardware setting problem?

-----------------------------------------------------------------------

ORG 00H
JMP START

ORG 100h

START:
SETB P2.0 ;Motion detector Input
SETB P2.1 ;Metal detector Input
CLR P1.0
CLR P1.1

Loop:
JNB P2.0, X
JNB P2.1, Z
SJMP Loop

; = = = = = = = = = = = = = =

X:
SETB P1.0
CLR P1.1
LCALL Delay ;Call Delay
SJMP START

Z:
SETB P1.1
CLR P1.0
LCALL Delay ;Call Delay
SJMP START

; = = = = = = = = = = = = = =

Delay:
MOV R2, #50 ;~1s
S1:
MOV R3, #200
S2:
MOV R4, #200
DJNZ R4, $
DJNZ R3, S2
DJNZ R2, S1

MOV R2, #50 ;~1s + 1s
S3:
MOV R3, #200
S4:
MOV R4, #200
DJNZ R4, $
DJNZ R3, S3
DJNZ R2, S4

MOV R2, #50 ;~1s + 1s +1s
S5:
MOV R3, #200
S6:
MOV R4, #200
DJNZ R4, $
DJNZ R3, S5
DJNZ R2, S6

RET

END
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top