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 / why timer is required in this?

why timer is required in this?

|

Microcontroller › 8051 › why timer is required in this?

  • This topic has 2 replies, 3 voices, and was last updated 10 years, 5 months ago by Ashutosh Bhatt.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • December 20, 2014 at 4:58 am #3359
    ashish
    Participant

    Example-2: write a program to make 8 to 1 multiplexer with enable signal

    #include<reg51.h>

    sbit D0 = P0^0;                     // set P0.0-P0.7 (D0-D7) as input pins of mux
    sbit D1 = P0^1;
    sbit D2 = P0^2;
    sbit D3 = P0^3;
    sbit D4 = P0^4;
    sbit D5 = P0^5;
    sbit D6 = P0^6;
    sbit D7 = P0^7;
    sbit S0 = P1^0;                 // set P1.0-P1.2(S0-S2) as select pins of mux
    sbit S1 = P1^1;
    sbit S2 = P1^2;
    sbit EN = P1^7;                // set P1.7 as enable pin
    sbit pin = P3^5;               // set P3.5 as output 

    main()
    {
             P3=0x00;P0=0xFF;      // clear op and set all ips
            TMOD = 0x01;              // set timer 0 for 16 bit timer
     next:TL0 = 0xAF;                 // load count 
            TH0 = 0x3C; 
            while(EN==1){}           // wait till enable pin becomes 0
       if((S0==0)&&(S1==0)&&(S2==0)) pin = D0;                  // if select inputs are 000 op is first ip
       else if((S0==1)&&(S1==0)&&(S2==0)) pin = D1;           // if select inputs are 001 op is second ip
       else if((S0==0)&&(S1==1)&&(S2==0)) pin = D2;           // same as above
       else if((S0==1)&&(S1==1)&&(S2==0)) pin = D3;
       else if((S0==0)&&(S1==0)&&(S2==1)) pin = D4;
       else if((S0==1)&&(S1==0)&&(S2==1)) pin = D5;
       else if((S0==0)&&(S1==1)&&(S2==1)) pin = D6;
       else if((S0==1)&&(S1==1)&&(S2==1)) pin = D7;   
       else pin = 0;                                                                 // by default op is cleared
       TR0 = 1;                                                                      // start timer 0 
       while(TF0==0){}                                                          // wait until overflow means 50ms
       TR0 = 0;                                                                      // stop timer 
       goto next;                                                                    // go for next input 
    }  

    December 20, 2014 at 6:22 am #12433
    AJISH ALFRED
    Participant

    Hi,

    Here the timer is used to generate a precise 50 milli second delay before taking the next input.

    December 21, 2014 at 6:16 pm #12440
    Ashutosh Bhatt
    Participant

    you can remove this delay also. 

    the program will work

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

RSS Recent Posts

  • Siemens large industrial PLC parts June 15, 2025
  • Parts required for a personal project June 15, 2025
  • Cant log in to Easy PC forum June 15, 2025
  • Failure of polypropylene motor-run capacitors June 15, 2025
  • Wideband matching an electrically short bowtie antenna; 50 ohm, 434 MHz June 15, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 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