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.

Delay in 8051 embedded c

Status
Not open for further replies.

vinothksr08

Member level 3
Joined
Jun 18, 2013
Messages
66
Helped
7
Reputation
14
Reaction score
7
Trophy points
8
Location
Tamilnadu, India
Activity points
367
dear friends,

i have doubt in delay... i have to give the 1 ms delay without using timer.. how can i???

And also to know what is delay time of this for loop??
am using 8051 with 12MHz crystal frequency...

for(i=0;i<1275;i++);
 

This will give the approximate delay of (1÷12M)×(prescale value)×(no.of cycles)×(your "for" loop length) ...check wether you have assigned prescale value or not .. and what is the no. of cycles ? But again you won't get exact delay without timers.
USE TIMERS because Embedded have to be exact,ALWAYS !! :smile:
 

i have doubt in delay... i have to give the 1 ms delay without using timer.. how can i???

You will need to use the polling method for this, i.e. looping for some time.
like the same "for" loop example you gave.

for(i=0;i<1275;i++);

According to some examples in the book on 8051 by Mazidi, it will give a delay of 1ms. But you can check the exact delay of this loop by using breakpoints in Keil cross compiler. The delay may vary from compiler to compiler because of the way how the C code is converted into Assembly instructions. It will not take more time in verifying in Keil or any such compiler.
 

You will need to use the polling method for this, i.e. looping for some time.
like the same "for" loop example you gave.



According to some examples in the book on 8051 by Mazidi, it will give a delay of 1ms. But you can check the exact delay of this loop by using breakpoints in Keil cross compiler. The delay may vary from compiler to compiler because of the way how the C code is converted into Assembly instructions. It will not take more time in verifying in Keil or any such compiler.


how to use the polling method can u explain???

thank you
 

how to use the polling method can u explain???

thank you

Debug that code using keil debugger . That is a easy way to find the time for execute the loop.

delay.JPG
 

The looping method can be used to simply make CPU do some dummy steps, so that it will provide a necessary delay.

Suppose if we use for(i=0;i<1275;i++);
This will make the CPU to just increment the value of ' i ' and check if it is less than 1275. This checking will make the CPU revolve there itself to produce some finite delay.

Which compiler are you using..?
 

hai

s, i can understand that but i would like to know the time of that delay.. am using keil c compiler
 

If you want to know the delay of this loop just use "Debug" mode in Keil.

> Set a Break point at the loop.
> Start the execution in debug mode.
> In debug mode, on the left-hand you will find a window showing the register contents. There will be a field showing the time also. Note the time from there.
> Now put a break point on the next statement after the loop, and start execution.
> It will stop at that break point. Here too note the time.
> The difference between those two noted time is the delay that the loop will give.
 

there is accurate and easier method by using assembly and this simple program. Use this method and make mix between c and assembly
 

Attachments

  • delay.rar
    33.3 KB · Views: 49

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top