while(x)
当x = true 时,while执行循环,如while(1)为死循环;而while(!x)则是利用while(1)为死循环的特点,在单片机中用于判断键盘检测。
#include <reg52.h> #define uchar unsigned char; #define uint unsigned int; sbit s1 = P3^0; sbit rd = P3^7; void keyscan() { rd = 0 ; //rd赋值为0,相当于相关一列键盘接地 if(s1 == 0) { while(!s1); //键盘s1非零检测,s1=0时(if语句)进入,while(!s1)=while(!0)进入死循环,此时卡住为键盘光标状态,秒针暂停(TR=0),当s1为0变为1时,实际为键盘从被按下状态到弹起状态的变化,while(!s1)=while(!1)跳出了死循环。 TR = 0; //关定时器,暂停秒表 write_com(0x0f); //调用1602液晶的光标显示 ... ... } } void write_com(uchar com) { } void main() { }
联系客服