打印

如何在程序里加入实时检测

[复制链接]
830|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
javachen|  楼主 | 2021-3-20 11:20 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
如何实时检测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();
          

   }  
}
       

使用特权

评论回复

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

19

帖子

0

粉丝