EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Replies / Hi Osama,It is due to the

Hi Osama,It is due to the

|

Microcontroller › 8051 › Delay function in C › Hi Osama,It is due to the

May 16, 2014 at 4:36 am #11736
AJISH ALFRED
Participant

Hi Osama,

It is due to the compiler optimisation. It simply optimise out the loop, which is not executing any useful statements. One solution is to remove all the optimisation options, or reduce the level of optimisation to zero. Still not working, this is how people do it, declare the local variables as volatile.

 

void MSDelay(unsigned int itime)
{
volatile unsigned int i,j;
for (i=0;i<itime;i++)
      for (j=0;j<1275;j++);
}
 
Which compiler are you using. If you are using keil, this may also work.
 
void MSDelay(unsigned int itime)
{
xdata unsigned int i,j;
for (i=0;i<itime;i++)
     for (j=0;j<1275;j++);
}

 

RSS Recent Posts

  • excessive technology in multimeters March 9, 2026
  • energising a solenoid March 9, 2026
  • Pnp transistor query March 9, 2026
  • Project boxes March 8, 2026
  • MCS-51 Development Ecosystem March 8, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise