8051 creating delays question

Thread Starter

ra1ph

Joined Jan 5, 2010
31
Hi,
Could someone take a look at my answer and tell me if it is right?

The question is to modify the following piece of code so the the first delay takes 101us and the second takes 340us?

LJMP BEGIN
ORG 0200H
BEGIN:
SETB P1.6
MOV R0,#26H
LOOP1:
DJNZ R0,LOOP1
CLR P1.6
MOV R0,#26H
LOOP2:
DJNZ R0,LOOP2
JMP BEGIN
END

My answer is:
ORG 0200H
BEGIN:
SETB P1.6
MOV R0,#49
LOOP1:
DJNZ R0,LOOP1
NOP
CLR P1.6
MOV R0,#168
LOOP2:
DJNZ R0,LOOP2
JMP BEGIN
END

I have a simulator but I am unsure exactly where I should put the break-points and if this is meant to be a 50% duty cycle square wave which leads me on to the next question in this assignment.

Thanks
 

Zazoo

Joined Jul 27, 2011
114
If you are using the on-chip 12MHz oscillator, each machine-cycle requires 1μs (12 clock pulses per cycle)

For the first delay I get a machine cycle count of:
1+1+49*2+1 = 101
(for SETB, MOV, DJNZ loop, and NOP)

For the second delay I get a machine cycle count of:
1+1+168*2+2 = 340
(for CLR, MOV, DJNZ loop, and (S)JMP)

Looks good to me.

Duty cycle is actually about 23% for this square wave (101/(101+340)).
A 50% duty cycle would have equal on-off times.
 

Thread Starter

ra1ph

Joined Jan 5, 2010
31
Thanks for this.

I should have been more clearer regarding the 50% duty cycle square wave. It was in relation to the original question. Anyhow using your confirmation of my answer I was able to determine for sure that the delay times were 78us and 80us and is indeed not a square wave of 50% duty cycle.

Thanks Again
 
Top