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
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
:|
;---------------------------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
;---------------------
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
Simply nice [poem], mate ..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
Set both pins in X and Z:macer_0001 said:Yes it works. Thank you. How can I modify the program to turn on the motors simultaneously?
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
...
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 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**
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
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?