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.

Sub routine in Assembly language which gives 2s delay in 8051

Status
Not open for further replies.

vikky

Full Member level 3
Full Member level 3
Joined
Oct 18, 2007
Messages
150
Helped
4
Reputation
8
Reaction score
3
Trophy points
1,298
Activity points
2,664
can anyone give me a sub routine which gives 2s delay in 8051 in assembly language
 

Re: Delay time for 8051

ha ha, you need all readymade. But please specify the xtal freq.
 

    vikky

    Points: 2
    Helpful Answer Positive Rating
Delay time for 8051

You can use timer in 8051.
Or use loop, sure you know period time of instruction.
 

Re: Delay time for 8051

i am also trying but not getting the exact delay.thats why i asked you.the crystal is 11.0592.

Added after 1 minutes:

thanks lequangtrung.
 

Re: Delay time for 8051

Accurate time delays can be easily achieved using timers' interrupts ..

Here are examples:


Regards,
IanP
 

Re: Delay time for 8051

hi...i used two loops and 2 counters but not getting the desired delay.can anyone help me out with a delay routine.
 

Delay time for 8051

If you mean 11.5092 MHZ.
And if you consider the size of Variable of one byte


11509200000/ (256*256*256)=686

686=49*14

So use 5 Bytes to be initialised in the loop as follow:
B1=FF (hex)
B2=FF
B3=FF
B4=31
B5=0E

You can improve this solution to reduce the resulting error.

Hope it help.
Master_Picengineer.
 

    vikky

    Points: 2
    Helpful Answer Positive Rating
Re: Delay time for 8051

Hi
Here is what you need my friend ... it is a very helpfull program please don't forget to hit a helped me button



Regards

MedTronic
 

    vikky

    Points: 2
    Helpful Answer Positive Rating
Re: Delay time for 8051

Use Timer 0 as a 16 bit auto reload timer with a time interval of let's say 10msec

One tick is 12 / fosc = 12 / 11.0592 e6 = 1.0851 µsec
You need 9216 ticks to make a 10 msec delay (10000 / 1.0426) = 9216

With the code below you need 1 byte to store the 10msec pulse count.
The main code isn't halted during the 2 sec delay.

Code in your main program
Code:
Time_0	equ 65535 - 9216     ;Delay for 10msec

       mov   My2SecDelay,#0     ;Initialize the 2 sec counter

       mov  TH0,#High Time_0     ;Load timer value
       mov  TL0,#Low  Time_0
       mov  TMOD,#01H              ;timer 0 mode 1
       setb  ET0                          ;enable interrupt timer 0
       setb EA           
       setb TR0                           ;start timer 0

EndlessLoop:
                           ;do all your endless coding here

       jmp   EndlessLoop


Code in ISR of timer 0
Code:
T0_ISR: mov    th0,#High Time_0   ;Reload timer
             mov    tl0,#Low  Time_0
             push   acc                        ;Save registers used in ISR

             inc     My2SecDelay          ;increment delay counter
             mov   a,My2SecDelay
             xrl     a,#200
             jnz     No2Sec
             mov   My2SecDalay,#0    ;Reset 10msec counter

               ;do your 2 sec stuff here

No2Sec:     
               ; do other timed stuff here


T0_ISR_End:	
              pop  acc                      ;Restore registers
              reti                             ;End ISR
 

    vikky

    Points: 2
    Helpful Answer Positive Rating
Re: Delay time for 8051

Thanks for ur pgm.my pgm is working fine.Thank u to both master_picengineer and mcs51mc.
 

Re: Delay time for 8051

can i get in c program can any body help me
 

Re: Delay time for 8051

try this:
void delay(unsigned int del)
{
unsigned int i,j;
for(i=0;i<=1000;i++);
for(j=0;j<=del;j++);
}
 

Re: Delay time for 8051

you can make a very acurrate delay in 8051 using its timer and its very easy.


Attached Complet C code contains delay function "accurate 50 ms delay" you can call it four times to have 2 second delay

if you need more help in 8051/52 i can send you a very useful book
 

Re: Delay time for 8051

aomran said:
you can make a very acurrate delay in 8051 using its timer and its very easy.


Attached Complet C code contains delay function "accurate 50 ms delay" you can call it four times to have 2 second delay

if you need more help in 8051/52 i can send you a very useful book


Note:- don't try to make delays using for loops or any loops tips, because it will not be accurate ever.
 

Re: Delay time for 8051

aomran said:
Note:- don't try to make delays using for loops or any loops tips, because it will not be accurate ever.

then how to make delay loops.??? :?:

i think if we are calculating properly the instructions values then ther will not be any mistake.
 

Delay time for 8051

make delays using timers, not loops,...
 

Re: Delay time for 8051

aomran said:
make delays using timers, not loops,...

that is also good option....

but this is not the answer of the question...
according to me to caculate delay is complicated by instructions but there will not occur any mistake from MCU.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top