现我假设K1,K2为两开关, dector 为脉冲检没开关。K1控制一个灯,K2控制一个灯。脉冲开关检测有脉冲时,无论K1,K2工作在什么状况,两灯关闭,另一灯亮
#include <reg52.h>
#define uchar unsigned char
void timer1_initial(void) ;
sbit d1=P1^0;
sbit d2=P1^1;
//sbit d3=P1^2;
sbit dector=P2^7;
sbit sw2=P3^2;
//sbit sw3=P3^3;
bit flag;
uchar key1,key2,a,b;
void main (void)
{
timer1_initial() ;
d1=0;
d2=0;
while(1)
{
while(( sw2==0)&&(flag==0))
{
d1=1;
d2=0;
}
while( sw2==1)
{
d1=0;
d2=0;
}
while((flag==1) &&(sw2==0))
{
d1=1;
d2=1;
}
}
}
void timer1_initial(void)
{
TMOD |=0X20;
TH1=0X38;
TL1=0X38;
TR1=1;
ET1=1;
EA=1;
}
void interrupt_serveice()interrupt 3
{
TH1=0X38;
TL1=0X38;
key1=key2;
key2=dector;
if((key1==1)&&(key2==0))
flag=1;
else
flag=0;
TF1=0;
}
在仿真进,脉冲控制时,那灯不停的闪
|