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 / Topics / Accessing timers on a microcontroller 8051

Accessing timers on a microcontroller 8051

|

Microcontroller › 8051 › Accessing timers on a microcontroller 8051

  • This topic has 1 reply, 2 voices, and was last updated 10 years, 5 months ago by Ashutosh Bhatt.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • November 9, 2015 at 8:28 am #4096
    Flavia
    Participant

    Could someone please help me out with this example. I dont understand why the they did not use (25μs × 1000). Why did they break it down to (25μs × 250 × 40) and later load (25μs × 250 × 36) on the microcontroller instead. Thank you.

    Example 14: Write an 8051 C program to toggle only pin P1.5 continuously every 250 ms.
    Use Timer 0, mode 2 (8-bit auto-reload) to create the delay.
    Solution:
    Solution: Assume XTAL=11.0592MHz
    For the delay of 250ms the count exceeds 256. hence, count for 25μs is calculated and
    count is 23
    Therefore for 250ms =>25μs × 250 × 40 = 250 ms
    Program
    #include <reg51.h>
    void T0M2Delay(void);
    sbit mybit=P1^5;
    void main(void){
    unsigned char x,y;
    while (1) {
    mybit=~mybit;
    for (x=0;x<250;x++)
    for (y=0;y<36;y++) //we put 36, not 40
    T0M2Delay();
    }
    }
    void T0M2Delay(void){
    TMOD=0x02;
    TH0=-23;
    TR0=1;
    while (TF0==0);
    TR0=0;
    TF0=0;
    }

    November 9, 2015 at 10:28 am #13468
    Ashutosh Bhatt
    Participant

    it is very hard to get exact required delay in embedded C programming

    u hv to do trial and error for getting closest value of required delay

    in loop inside loop it waste more cycles so we can not directly put 250*1000 = 250 ms

    also we can not put 250*25*40 = 250 ms. instead we have to put different count like 40,39,38,36 …. likewise and check when there is closest value of 250 ms

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • SDCC Array Access In Timer 0 Interrupt Handler April 14, 2026
  • Voltage comparator circuit verification April 13, 2026
  • EasyEda program has a major bug April 13, 2026
  • Chatter April 13, 2026
  • understanding transmission line properties from TDR plot April 13, 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