- This topic has 1 reply, 2 voices, and was last updated 9 years ago by .
Viewing 2 posts - 1 through 2 (of 2 total)
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.
|
Microcontroller › 8051 › How to use IF statement with 8051?
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;
}
}
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;
}
}