欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
下面單片機程序中while((s5==0)&&(count<500000)) 怎么理解
[打印本頁]
作者:
陌路狂花
時間:
2018-3-12 19:42
標題:
下面單片機程序中while((s5==0)&&(count<500000)) 怎么理解
#include "button.h"
#include "reg51.h"
sbit s4=P3^3;
sbit s5=P3^2;
sbit s6=P3^1;
sbit s7=P3^0;
void delay_button(unsigned char m)
{
unsigned char n;
for(m;m>0;m--)
{
for(n=250;n>0;n--)
{}
}
}
unsigned char keyboard()
{
unsigned char button_flag=0;
int count=0;
if(s4==0)
{
delay_button(10);
if(s4==0)
{
while((s4==0)&&(count<500000))
{
button_flag=4;
count++;
}
}
}
if(s5==0)
{
delay_button(10);
if(s5==0)
{
while((s5==0)&&(count<500000))
{
button_flag=5;
count++;
}
}
}
if(s6==0)
{
delay_button(10);
if(s6==0)
{
while((s6==0)&&(count<500000))
{
button_flag=6;
count++;
}
}
}
if(s7==0)
{
delay_button(10);
if(s7==0)
{
while((s7==0)&&(count<500000))
{
button_flag=7;
count++;
}
}
}
if(count>500000)
count=0;
return button_flag;
}
作者:
huangkeke
時間:
2018-3-12 20:16
當s5的值為0并且count的值小于500000這兩個條件都為真,進入while()循環;否則不進入while()循環。
作者:
huangkeke
時間:
2018-3-12 20:18
s5的值為0并且count<500000兩個條件都為真的時候進入While()循環
作者:
藍廊坊市
時間:
2018-3-12 21:24
&&是按位與 (s5==0)&&(count<500000)同時為真時執行
作者:
陌路狂花
時間:
2018-3-13 08:13
為什么count<500000,而不是其他
作者:
HC6800-ES-V2.0
時間:
2018-3-13 10:26
這條語句就是松鍵消抖的功能。
鍵被按下就等于零(S1==0),后面就是控制按鍵的時間的(count<50000)。
這兩個條件同時滿足,說明鍵是按著的,而且時間不是很長。
如果松開鍵,或者按鍵時間太長,都會跳出循環,避免程序死在這里。
個人認為,這樣的程序不好。
對于像你的程序,這樣的簡單按鍵功能,還可以使用,看不問題,但如果按鍵功能復雜一點,那么,就會在按下鍵不松的一段時間內,程序會讓那個功能重復很多次(事實上,你的程序已經重復了很多次,最大可以重復49999次,只是功能簡單,眼睛看不出來而已)。
作者:
shuisheng
時間:
2019-1-30 21:16
while((s5==0)&&(count<500000))
分解來分析:(s5==0)&&(count<500000)
有三個結果1.(1&&1)// (s5==0是真)&&(count<500000也是真)
2.(0&&1)// (s5==0是假)&&(count<500000是真)
3.(1&&0)// (s5==0是真)&&(count<500000是假)
最終while(中只有1或者0), 當while(1時)執行button_flag=5;count++; 否則就跳
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1