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

How to use IF statement with 8051?

|

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

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;
  }

 }

RSS Recent Posts

  • What diode should I use? March 7, 2026
  • LM016L + PCF8574 I2C Backpack Schematic with Backlight Control March 7, 2026
  • Expensive hobby March 7, 2026
  • USING EASYEDA BUT SOMETHING ISN'T RIGHT? March 7, 2026
  • What is this component and what is its function? March 6, 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