如何实时检测FK信号,丢失后立即开始计时连续丢失3S,才认为真的是丢失
#include "SC92F725x_C.H"
#include "intrins.H"
#include "H/Function_Init.H"
sbit FMQ = P1^2;
sbit DJ1= P2^7;
sbit DJ2= P2^6;
sbit JDQ= P2^0;
sbit FK= P2^1;
bit bjbz;
typedef unsigned int u16;//对数据类型进行声明定义
typedef unsigned char u8;
u16 k;
u16 j;
bit t10msflag;
bit initalflag;
bit relayflag;
bit startflag;
bit overflag;
bit delayflag;
unsigned char tms;
unsigned char tms1;
unsigned char ts;
unsigned char t3s;
unsigned char t6s;
void Timer_Init(void);
void time10flag(void)
{
if(t10msflag)
{
t10msflag=0;
if(ts<19)
{
tms++;
if(tms>=100)
{
tms=0;
ts++;
}
}
else
{
PWMDTY4 = 0;
PWMDTY5 = 0;
FMQ=1;
JDQ=0;
}
if(!delayflag)
{
if(ts<3)
{
PWMDTY4 = 0; //PWM4低
PWMDTY5 = 0; //PWM5低
FMQ=0;
JDQ=0;
}
else if((ts>=3)&&(ts<6))
{
PWMDTY4 = 100; //PWM4的Duty =100
PWMDTY5 = 0;
FMQ=0;
JDQ=1;
}
else if((ts>=6)&&(ts<10))
{
PWMDTY4 = 50; //PWM4的Duty = 50/100 =1/2
PWMDTY5 = 0;
FMQ=0;
JDQ=1;
}
else if((ts>=10)&&(ts<13))
{
PWMDTY4 = 50; //PWM4的Duty = 50/100 =1/2
PWMDTY5 = 0;
FMQ=0;
JDQ=0;
}
else if(ts==13)
{
if(FK==1)
{
PWMDTY4 = 50; //PWM4的DutyPWM4的Duty = 50%
PWMDTY5 = 100;
FMQ=0;
JDQ=0;
}
else
{
ts=19;
delayflag=1;
}
}
else if((ts>13)&&(ts<16))
{
if(FK==1)
{
PWMDTY4 = 50; //PWM4的DutyPWM4的Duty = 50%
PWMDTY5 = 100;
FMQ=0;
JDQ=0;
ts=16;
tms=0;
}
else
{
//ts=19;
delayflag=1;
}
}
else if(ts>=16)
{
if(FK==1)
{
PWMDTY4 = 50; //PWM4的Duty = 50%
PWMDTY5 = 50;
FMQ=0;
JDQ=0;
ts=16;
tms=0;
}
else
{
delayflag=1;
}
}
}
}
}
void main(void)
{
IO_Init();
PWM_Init();
Timer_Init();
while(1)
{
time10flag();
}
}
|