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 / How to use IF statement with 8051?

How to use IF statement with 8051?

|

Microcontroller › 8051 › How to use IF statement with 8051?

  • This topic has 1 reply, 2 voices, and was last updated 10 years, 2 months ago by Prabakaran P M.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • August 25, 2015 at 1:36 pm #3929
    Embedded_pic
    Participant

    Hi,

    i'm trying to send command to two button S1 and S2,

    if i push S1 it will send signal to P1.0

    if i push S2 it will send signal to P1.1

    In my code, the first loop is executed but not the second.

    Thank you for your help.

     

    Here is the code:

    #include <reg51.h>
    sbit S1 = P2^0;
    sbit S2 = P2^1;

    sbit Led = P1^0;
    sbit Led2 = P1^1;

    void main()
    {
    S1 = 1;
    S2 = 1;

     while(1)  // For ever
     {
      if(S1 == 0) 
      {
        Led = 0;              
            while(S1 == 0);
      }
      Led = 1;
     }

     {
     if (S2 == 0)
     {
     Led2 = 0;
     while (S2 == 0);
     }
      Led2 = 1;
      }

     }

    August 26, 2015 at 5:22 am #13219
    Prabakaran P M
    Participant

    Here is the code:

    #include <reg51.h>
    sbit S1 = P2^0;
    sbit S2 = P2^1;

    sbit Led = P1^0;
    sbit Led2 = P1^1;

    void main()
    {
    S1 = 1;
    S2 = 1;

     while(1)  // For ever
     {
      if(S1 == 0) 
      {
        Led = 0;              
            while(S1 == 0);
      }
      Led = 1;
     }

     {  ////// remove this curly bracket
     if (S2 == 0)
     {
     Led2 = 0;
     while (S2 == 0);
     }
      Led2 = 1;
      }

     }

  • 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

  • Manually actuate fuel tank selector solenoid November 9, 2025
  • strange laptop problem November 9, 2025
  • JLCPBC are using a different shipping company = less $$$$$$$$ November 8, 2025
  • Help please! BLDC driver circuit using the IR2136s and the STP80NF06 MOSFETS November 8, 2025
  • need two ICs November 8, 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