1.按下亮,松开不亮
#include "reg52.h"
sbit key1 = P2^1;
sbit ledone = P3^7;
void main()
{
//查询法检测是否被按下
while(1)
{
if(key1 == 0)
{ // 灯亮,给个低电平
ledone = 0;
break;
}else if(key1 ==1)
{
ledone = 1;
break;
}
}
}
1.按下亮,松开不亮
#include "reg52.h"
sbit key1 = P2^1;
sbit ledone = P3^7;
void main()
{
//查询法检测是否被按下
while(1)
{
if(key1 == 0)
{ // 灯亮,给个低电平
ledone = 0;
break;
}else if(key1 ==1)
{
ledone = 1;
break;
}
}
}