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.

why the value 1275 is used in this function?

Status
Not open for further replies.

regin

Junior Member level 1
Joined
Oct 11, 2011
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,430
hi,

i am a beginner in microcontroller and embbeded c.

///// please help me/////

why 1275 value selected in this fuction?

void delay(unsigned int msec)
{
int i,j;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}

what is the logic behind this?

i am using AT89s52 .... frequency set to 11.0592 mhz.
 

Hello!

Probably because the guy who wrote the function tried a few values and ended up with
1275 as the closest number of loops to make 1 millisecond.
It sounds like an odd value, anyway. 11.0592 MHZ divided by 1275 makes 8674.
With a value very close to 9000 for instance, I would guess that 1 loop takes 9 clocks.
By the way, I suppose you took the code as is from another implementation that was
working with another crystal, right?

Dora.
 
  • Like
Reactions: regin

    regin

    Points: 2
    Helpful Answer Positive Rating
Hello!

Just a remark about your code above.

Writing a raw value (like this 1275) is just a sign of a poorly written code.
What you should do is:

#define LOOPS_PER_MS 1275 // Number of loops per millisecond

and later for(j = 0 ; j < LOOPS_PER_MS ; ++j)

Doing this, you will have no trouble to understand what you wrote even
a few months later, and on top of that other people will also understand
what you wrote.

Dora.
 
  • Like
Reactions: regin

    regin

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top