#include
Sbit key1=P3^4;
Sbit p10=P1^0;
Void main()
{
While(1)
{
P10=1;
While(key1!=0);
P10=0;
}
}
My purpose is to use a keyboard to control the light emission of a diode. After the key on the keyboard is pressed, the diode emits light. When it is released, the diode goes out. If you use the while (key1! = 0); to make a judgment, the program works normally: the start diode goes out and the diode is lit when you press the corresponding button on the keyboard. However, if you use if (key1!=0); to make a judgment, the program will be abnormal: the diode will light when it starts, and there is no response if you press the key on the keyboard. May i know what is this all about? This was also the case when writing small programs. It was easy to make mistakes with the if statement, but it changed to normal after the while. Please help me explain this question~Thank you!
The usage of while and if is not understood upstairs.
While () to determine the expression in parentheses is 1, the program is constantly executing the while internal function, which is equivalent to stop in the while statement, do not go down. When it is 0, the internal function is jumped out and execution continues downward.
When if() is used to determine that the expression in the parentheses is 1, the execution of the internal function is executed once and the if statement is executed downward. When it is 0, it jumps directly to the internal function and continues to execute downwards.
Analyze this piece of program you write,
P10=1;
While(key1!=0);
P10=0;
Although the phenomenon has reached your expectations, it actually loops through 3 statements after you press the button. It does not stop after P10 = 0, so the LED is actually blinking rapidly instead of constantly. Because it's too fast, you can't see it. You can see this by adding a delay function after P10=0. Suggest changes.
P10=1;
While(key1!=0)
{
P10=0;
}
Or more simply,
P10=1;
While(key1!=0) // directly remove the semicolon
P10=0;
Watch Screen Protector features a stretchable and retractable TPU Screen Protector that resists air bubbles and fingerprints on your device's screen and provides maximum protection for your device from scratches. The Hydrogel Film repairs screen scratches on its own and is ideal for curved curved screens.
Full Coverage: The soft material matches the edges of the watch screen well. Full coverage provides better protection and looks very discreet.
Oleophobic and waterproof: The oleophobic waterproof transparent layer can prevent the residue of sweat and grease, resist fingerprints, and keep the phone screen as new as ever.
Sensitive touch: only 0.14mm thick ultra-thin protective layer will not interfere with touch screen commands, your touch screen can still operate 100% normally.
If you want to know more information about Smart Watch Screen Protector products, please click the product details to view the parameters, models, pictures, prices and other information of Watch Screen Protector products.
Whether you are a group or an individual, we will do our best to provide you with accurate and comprehensive information about Watch Hydrogel Screen Protectors!
Watch Screen Protector, Watch Hydrogel Screen Protector,Smart Watch Screen Protector,Watch Protective Film,Apple Watch Screen Protector,Watch Screen Protector Cover
Shenzhen Jianjiantong Technology Co., Ltd. , https://www.jjtphonesticker.com