#include "reg51.h" // 试试
sbit k1 = P1^0;//按键1 开关
sbit p6 = P1^6; //输出1 灯
bit t1, t2;
void main(void)
{
while(1)
{
if(k1==0 && t1==0) {t1=1; p6=~p6;}
if(k1==1 ) {t1=0;}
}}
// 下面是四个开关,两个灯 的实例
http://zhidao.baidu.com/question/532520062.html
#include
sbit KEY=P1^2;
sbit LED=P1^0;
void main(void)
{
while(1)
{LED=!KEY;
}
}
#include
#define uchar unsigned char
sbit k1=P1^0;
sbit led1=P1^1;
void delay(uchar del)
{
uchar i,j;
for(i=0;i<200;i++)
for(j=0;j}
void main()
{
led1=1;
k1=1;
while(1)
{
if(k1==0)
{
delay(10);
if(k1==0)
{
delay(10);
while(k1);
delay(10);
led1=~led1;
delay(50);
}
}
}
}