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.

Assembly code for 1sec delay for 8051

Status
Not open for further replies.

rizwanspirit

Member level 4
Member level 4
Joined
Feb 22, 2008
Messages
74
Helped
4
Reputation
8
Reaction score
1
Trophy points
1,288
Activity points
1,791
I need assembly code for 1sec delay for 8051.i made this code in keil but this
is not executed.
And gives an error

error A21: EXPRESSION WITH FORWARD REFERENCE NOT PERMITTED

My program is

ORG O0H
MOV A,#55H
AGAIN1:
MOV P1,A
LCALL DELAY
CPL A
SJMP AGAIN1
ORG 30H
DELAY:
MOV R1,#250
AGAIN:
MOV R2,#250
HERE:
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
DJNZ R2,HERE
DJNZ R1,AGAIN
RET
END
 

8051 delay function

this is what I use to get perfect delay's.


runs in a dos window. just input the clock setting (i.e. 11.0592), then the time delay you want in microseconds.(in your case you want 1000000uS for 1 second)

I always check the delay routine in the 8051 simulator for accuracy.

Good Luck

Added after 2 minutes:

here's another one for windows.
 

    rizwanspirit

    Points: 2
    Helpful Answer Positive Rating
8051 delay .h

The problem is in the following line:
Code:
ORG O0H

You meant
Code:
ORG 00H

You mistyped capital "O" for zero.

JW
 

    rizwanspirit

    Points: 2
    Helpful Answer Positive Rating
8051 delay.h

any one please calculate that my program will give 1sec delay or not.
 

delay 1 second 8051

For those that might be willing to count your clock cycles (not me, sorry) one piece of information is mandatory, what is the crystal frequency!?

To get an exact 1 second delay that also works during interrupts, you need to use a hardware timer (T0 or T1), not a software timer. A software timer that can run for 1 second without being interrupted holds all execution on the device for that second, sounds not very real-time to me

Hope this helps to get your thoughts straightened out a bit.

Bob
 

8051 delay

I am assuming (guessing) that you are using an 11.0592 MHz clock since you did not mention anything about it.

Code:
;TIME DELAY CALCULATOR FOR 8051 - [url]WWW.USTR.NET[/url] 2001
; INPUT CLOCK VALUE IN MEGAHERTZ...: 11.0592
; WANTED TIME DELAY IN MICROSECONDS: 1000000
; CLOCK CYCLE TIME................ : 90 ns
; PROCESSOR CYCLE TIME (12)....... : 1085 ns
; TOTAL REQUIRED CYCLES........... : 921600
; TOTAL TIME (INCLUDING CALL)..... : 1000.00 mS
; USE THE FOLLOWING CODE:


Del_1_Sec:  MOV   R3,#8
      MOV   R2,#8
      MOV   R1,#236
Del_1_Sec0:
      DJNZ  R1,Del_1_Sec0
      DJNZ  R2,Del_1_Sec0
      DJNZ  R3,Del_1_Sec0
      RET
 

delay 8051

wek said:
The problem is in the following line:
Code:
ORG O0H

You meant
Code:
ORG 00H

You mistyped capital "O" for zero.

JW

great eye you have good. Good work WEK.

Rizwan. Please add 00 to TL0 and TH0 registers. If you use 11.0592MHz crystal then it takes 71.1msec to overflow. You run this for 14 times. You get 1 sec delay.
 

8051 delay

I use this in K*il
Use DelayMs(x); or DelayUs(x);

Delay.h (filename)

#define XTAL_FREQ 12
#define DelayUs(x) { unsigned char _dcnt; \
_dcnt = (x)*((XTAL_FREQ)/12); \
while(--_dcnt != 0) \
continue; }

extern void DelayMs(unsigned char);
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top