⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 m8.c

📁 采用ATMEGA8的芯片,功能为智能家居的门禁控制,单相交流电机的控制系统,性能稳定.
💻 C
📖 第 1 页 / 共 5 页
字号:
        //测试输出那个
        switch (out_task)
        {
            case (cst_out_open):
            {
                //开输出
                if (eep_out_j12==cst_out_j12_true)
                {
                    if ((eep_xc_close_sram+cst_run_min)<xc_currently)
                    {
                        subpr_out_open();
                    }
                }
                else
                {
                    if ((xc_currently+cst_run_min)<eep_xc_open_sram)
                    {
                        subpr_out_open();
                    }
                }
            }
            break;
        
            case (cst_out_close):
            {
                //关输出
                if (eep_out_j12==cst_out_j12_true)
                {
                    if ((xc_currently+cst_run_min)<eep_xc_open_sram)
                    {
                        subpr_out_close();
                    }
                }
                else
                {
                    if ((eep_xc_close_sram+cst_run_min)<xc_currently)
                    {
                        subpr_out_close();
                    }
                }
            }
            break;
        
            case (cst_out_ip1):
            {
                //运行至IP1
                if (eep_out_j12==cst_out_j12_true)
                {
                    if ((xc_currently+cst_run_min)<eep_xc_ip1_sram)
                    {
                        //当前行程小于IP位置,执行开(+)
                        subpr_out_close();
                    }
                    else if ((eep_xc_ip1_sram+cst_run_min)<xc_currently)
                    {
                        //当前行程大于IP位置,执行关
                        subpr_out_open();
                    }
                }
                else
                {
                    if ((xc_currently+cst_run_min)<eep_xc_ip1_sram)
                    {
                        //当前行程小于IP位置,执行开(+)
                        subpr_out_open();
                    }
                    else if ((eep_xc_ip1_sram+cst_run_min)<xc_currently)
                    {
                        //当前行程大于IP位置,执行关
                        subpr_out_close();
                    }
                }
                
            }
            break;
        
            case (cst_out_ip2):
            {
                //运行至IP2
                if (eep_out_j12==cst_out_j12_true)
                {
                    if ((xc_currently+cst_run_min)<eep_xc_ip2_sram)
                    {
                        //当前行程小于IP位置,执行开(+)
                        subpr_out_close();
                    }
                    else if ((eep_xc_ip2_sram+cst_run_min)<xc_currently)
                    {
                        //当前行程大于IP位置,执行关
                        subpr_out_open();
                    }
                }
                else
                {
                    if ((xc_currently+cst_run_min)<eep_xc_ip2_sram)
                    {
                        //当前行程小于IP位置,执行开(+)
                        subpr_out_open();
                    }
                    else if ((eep_xc_ip2_sram+cst_run_min)<xc_currently)
                    {
                        //当前行程大于IP位置,执行关
                        subpr_out_close();
                    }
                }
            }
            break;
        
            default:
            {
                //未知操作
                WDR();
            }
    
        }
        
        subpr_yms_com(2);
        clr_led_r;

    } 
    
}
 



//******************函数*******************
//清除行程
void subpr_clr_xc(void)
{
    //清除行程
    set_led_r;
    eep_xc_sum=cst_xc_sum;
    eep_xc_open=cst_xc_open;
    eep_xc_close=cst_xc_close;
    xc_currently=cst_xc_currently;
    eep_xc_ip1=cst_xc_open;
    eep_xc_ip2=cst_xc_close;
    subpr_yms_com(2);
    subpr_xc_copy();                    
    clr_led_r;
 
 }


//********************************************



/*

行程设置定位

*/
unsigned char subpr_xc_qs(void)
{
    //if (bit_xc_man==1)
    //{
        if (subpr_rif()==0)
        {
            if (subpr_eep_check()==cst_window_have)
            {
                if ((rif_val[3]==cst_rif_open)||(rif_val[3]==cst_rif_stop)||(rif_val[3]==cst_rif_close))
                {
                    subpr_rif_ok();
                }
                else if (rif_val[3]==cst_rif_learn)
                {
                     j1_close;
                     j2_close;
                     bit_xc_man=1;
                     return (rif_val[3]);
                }
            }
        }
    
        subpr_sbw_scan();
    
        if (sb_w_learn_ax)
        {
            subpr_yms_com(2);
            if (sb_w_learn_ax)
            {
                j1_close;
                j2_close;
                bit_xc_man=1;
                return (cst_rif_learn);
            }
        }
        else
        {
            return (0);
        }
    //}
    //else
    //{
    //    return (0);
    //}
}






//******************函数*******************
//行程设置
void subpr_xc_config(void)
{
    //行程设置
    unsigned int sum_temp;
    
    bit_xc_man=0;
    
    if (j1_out_true||j2_out_true)
    {
        //关闭输出
        j1_close;
        j2_close;
        xc_work_old=cst_out_free;
        subpr_ys_com(2);
    }
    
    //运行至起点close
    subpr_clr_xc();
    subpr_yms_com(1);
 
    set_led_r;
    bit_xc_tsend=0;
    
    //if (bit_xc_man==0)
    //{
        subpr_out_close();
    //}
    
    //等待到起点
    while ((subpr_xc_qs()!=cst_rif_learn)&&((bit_xc_tsend==0) || (bit_xc_man==1)))
    {      
           WDR();
           set_led_r;
    }
    
    clr_led_r;
    subpr_ys_com(2);        //廷时2秒
    set_led_r;
    
    //运行至终点open
    subpr_clr_xc();
    subpr_yms_com(1);
    set_led_r;
    bit_xc_tsend=0;
    
    //if (bit_xc_man==0)
    //{
        subpr_out_open();       //运行至终点
   //}
    
    while ((subpr_xc_qs()!=cst_rif_learn)&&((bit_xc_tsend==0) || (bit_xc_man==1)))
    {      
           WDR();
           set_led_r;
    }
    
    //行程测试完成
    clr_led_r;
    subpr_ys_com(2);        //廷时2秒
    

    //记录行程
    if ((xc_currently<(cst_xc_currently-cst_xc_yx)||(xc_currently>(cst_xc_currently+cst_xc_yx)))||(bit_xc_man==1))
    {
        //if (eep_out_j12==cst_out_j12_true)
        if (cst_xc_currently>xc_currently)
        {
            //已换向
            if (bit_xc_man==0)
            {
                //自动测试
                eep_xc_sum=cst_xc_currently-xc_currently;
                sum_temp=cst_xc_currently-xc_currently;
                
                //按行程长短决定预留长度
                //1m=270di
                //1cm=2.7di
                //46.67r/s
                //2800r/m
                //1m->7di
                //open&&close
                
                eep_xc_open=cst_xc_currently-7;
                eep_xc_close=xc_currently+25;
                
                do
                {
                    WDR();
                    if (sum_temp>270)
                    {
                        sum_temp-=270;
                        eep_xc_open-=1;
                        eep_xc_close+=1;
                    }
                
                }
                while (sum_temp>270);
                
                /*    
                if (sum_temp<270)
                {
                    eep_xc_open=cst_xc_currently-7;
                    eep_xc_close=xc_currently+20;
                }
                else if ((540>sum_temp)&&(sum_temp>=270))
                {
                    eep_xc_open=cst_xc_currently-8;
                    eep_xc_close=xc_currently+25;
                }
                else if ((3000>sum_temp)&&(sum_temp>=540))
                {
                    eep_xc_open=cst_xc_currently-9;
                    eep_xc_close=xc_currently+30;
                }                                       
                else
                {
                    eep_xc_open=cst_xc_currently-10;
                    eep_xc_close=xc_currently+35;
                }
                */
              
            }
            else
            {
                //手动
                eep_xc_sum=cst_xc_currently-xc_currently;
                eep_xc_open=cst_xc_currently;
                eep_xc_close=xc_currently;
            }
        }
        else
        {
            //未换向
            if (bit_xc_man==0)
            {
                //自动测试
                eep_xc_sum=xc_currently-cst_xc_currently;
                sum_temp=xc_currently-cst_xc_currently;
                
                //按行程长短决定预留长度
                //open&&close
                eep_xc_open=xc_currently-20;
                eep_xc_close=cst_xc_currently+7;

                do
                {
                    WDR();
                    if (sum_temp>270)
                    {
                        sum_temp-=270;
                        eep_xc_open-=1;
                        eep_xc_close+=1;
                    }
                
                }
                while (sum_temp>270);
                
                /*
                if (sum_temp<700)
                {
                    eep_xc_open=xc_currently-20;
                    eep_xc_close=cst_xc_currently+7;
                }
                else if ((1500>sum_temp)&&(sum_temp>=700))
                {
                    eep_xc_open=xc_currently-25;
                    eep_xc_close=cst_xc_currently+8;
                }
                else if ((3000>sum_temp)&&(sum_temp>=1500))
                {
                    eep_xc_open=xc_currently-30;
                    eep_xc_close=cst_xc_currently+9;
                }                                       
                else
                {
                    eep_xc_open=xc_currently-35;
                    eep_xc_close=cst_xc_currently+10;
                }
                */
            }
            else
            {
                eep_xc_sum=xc_currently-cst_xc_currently;
                eep_xc_open=xc_currently;
                eep_xc_close=cst_xc_currently;
            }
        }
        
        eep_xc_ip1=eep_xc_open;
        eep_xc_ip2=eep_xc_close;
        subpr_xc_copy();

        
        //运行至起点
        //subpr_led_wink(10);
        subpr_out_close();
       
    }
    else
    {
        //行程太短,无效
        //清除行程
        set_led_r;
        subpr_clr_xc();
        subpr_yms_com(2);
        clr_led_r;

    }    

}




//******************函数*******************
//按键类型测试
void subpr_sbw_sort_test(void)
{
    //测试开关类型及按键按下时间
    if (bit_sbw_sort==cst_sbw_sb)
    {
        if (sbw_ax_timer1>=7)
        {
            //改写开关类型标志
            eep_sbw_sort=cst_sbw_k;
            bit_sbw_sort=cst_sbw_k;            
        }
    }
}





//******************函数*******************
//按键处理SBW_OPEN_AX
void subpr_sbw_open_ax(void)
{
    //测试外控开关类型
    if (bit_sbw_sort==cst_sbw_sb)
    {
        //清除开关按下定时器
        sbw_ax_timer1=0;
    }
    
    bit_sbw_open=cst_sbw_ax;         //置按下标志
    
    //调用输出
    subpr_out_control(cst_out_open);   
    
}




//******************函数*******************
//按键处理SBW_OPEN_FS
void subpr_sbw_open_fs(void)
{
    //关闭输出
    j1_close;
    j2_close;
    xc_work_old=cst_out_free;
}
 




//******************函数*******************
//按键处理SBW_CLOSE_AX
void subpr_sbw_close_ax(void)
{
    //测试外控开关类型
    if (bit_sbw_sort==cst_sbw_sb)
    {
        //清除开关按下定时器
        sbw_ax_timer1=0;
    }
    
    bit_sbw_close=cst_sbw_ax;         //置按下标志
    
    //调用输出
    subpr_out_control(cst_out_close);   

}





//******************函数*******************
//按键处理SBW_CLOSE_FS
void subpr_sbw_close_fs(void)
{
    //关闭输出
    j1_close;
    j2_close;
    xc_work_old=cst_out_free;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -