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

📄 30dl.c

📁 一款30dl空调控制器程序,包括了室内室外控制.
💻 C
📖 第 1 页 / 共 4 页
字号:
/*
   2007.10.9


*/

#include <30dl.h>
#include <ystddef.h>
#include <io87.h>
#include <io87bit.h>
/*+++++++++++++++++++++++++++++++++++++++++++++++++*/
extern void main(),hdwinit();
extern void inttbt(),inttc3(),inttc4(),onlyreti(),onlyretn();
extern void remo_init(),r_shift();
extern void ad_sub(),ad_process();
extern void remo_decode();
extern void remo_decode_sub();
extern void output();
extern void mode_sub(),coolmode(),drymode(),heatmode(),is_mode_change();
extern void comp_dly_5s(),outfan_dly_15s(),ice_prv();
extern void heat_defrost_run(),heat_normal_run();
extern void comp_dly_5s_h(),press_protect();
extern void comptime();
extern void fancontrol();
extern void coolfan(),dryfan(),heatfan();
extern void setfanOFF(),setfanHi(),setfanMi(),setfanLo(),h_fan_normal();
extern void timer_sub();
extern void vancontrol(),stepdrive(),vane_monitor();
extern void comp_cumulate_sub();  /*count for defrost and vane dew*/
extern void abnormal_show(),sh_abnor_mid();
extern void emergency_timer(),read_key_emerg();
extern void sleepmode();
extern void fctest(),fc_test_output(),on_line_test();
extern void timer_cnt_sub();
extern void emergency_run();
extern void auto_start(),heat_stop();
extern unsigned char read_port_P1();
extern unsigned char read_port_P4();
/*+++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma section area _variable tiny 0x0060

unsigned char flag1,flag2,flag3,flag4,flag5,flag6,flag7;
unsigned char flag8,flag9,flag10,fan_st,timer_st;
unsigned char ram2;
unsigned char dig_tmp1,dig_tmp2,dig_tmp_mid,regA,regB;
unsigned char tempa,tempb,remo_step,t10ms_cnt,t60s_cnt,mode_change_cnt;
unsigned char run_time_cnt;
unsigned char remo_bit_cnt,remo_byte_cnt,shift_temp,remo_sum;
unsigned char remo_data[14],remo_data_receive[14];
unsigned char ram1;
unsigned char ad_room;
unsigned char ad_coil;
unsigned char roomtemp,settemp;
unsigned char adnum;
unsigned char ad_channel;
unsigned char mode,runmode,remo_fanspeed,vane_mode,oldrunmode;
unsigned char yufang_105m_time,fan_run_word;
unsigned char outfan_d5s,first_mode_change;
unsigned char defrost_step,c_cumulate_time;
unsigned char guoyali_time;
unsigned char comp_time_cnt,dtram,comprunT;
unsigned char fantime,first_remo;
unsigned char T_on_m,T_off_m,timer10min;
unsigned char motor_step,stop30s_cnt;
unsigned char v_object_cnt;
unsigned char ram3;
unsigned char v_swing_dly;
unsigned char v_swing_cnt;
unsigned char dew_prv_time;
unsigned char v_position_cnt,v_angle_cnt;
unsigned char mode_angle_mode,van_tmp;
unsigned char motor_cnt,delay_cnt;
unsigned char defrost_cnt,defrost_interval_t;
unsigned char err_cnt,ming_mie;
unsigned char emergency_test_time,emergency_key_cnt;
unsigned char key_cnt;
unsigned char sleeptime;
unsigned char sys_ram_P1;
unsigned char fc_pulse_cnt,fc_time,on_line_test_pass;
unsigned char shift_1,shift_2;
unsigned char ram4;
unsigned char tc1_watch,timer_cnt,no_short_time;
unsigned int buztime,adHLram,defrost_time,defrost_time_cnt;
unsigned int coil4c_time;
/*+++++++++++++++++++++++++++++++++++++++++++++++++*/
#pragma section code table near 0xe000

unsigned char ad_tab[]=
{
    12,12,13,13,13,14,14,14,15,15,  /*90d-99d*/
    15,16,16,16,17,17,17,18,18,18,  /*100d-109d*/
    19,19,19,20,20,20,21,21,22,22,  /*110d-119d*/
    22,23,23,23,24,24,24,25,25,25,  /*120d-129d*/
    26,26,26,27,27,28,28,28,29,29,  /*130d-139d*/
    29,30,30,30,31,31,32,32,32,33,  /*140d-149d*/
}; /* range 90-150*/

unsigned char tab_step[]=
{
    0y10010001,
    0y10000011,
    0y11000010,
    0y01000110,
    0y01100100,
    0y00101100,
    0y00111000,
    0y00011001
};
/*-------------------------------------*/
void main()
{
    RBS = 0;
    
    EIR = 0;       

    SP = STACK_BOTTOM;                      /* Stack pointer set    */
    WDTCR1 = 0y00001111;
    WDTCR2 = 0x4e;

    hdwinit();

    if (ram1!=0xaa || ram2!=0xaa || ram3!=0xaa || ram4!=0xaa)
    {
        WA = SIZE;
        HL = RAM_TOP;
        do {
            *HL++ = 0;
        } while(--WA);

        ram1=0xaa;
        ram2=0xaa;
        ram3=0xaa;
        ram4=0xaa;

        sys_ram_P1 = read_port_P1() ^ 0y00001111;

        autostart = JPA;
    }

    shift_1 = 0y00001000;
    shift_2 = 0y00000100;
    TBTCR = 0y00001110;     /* 0.256ms every interrupt */
    EIR = 0y0000010101000001;

    remo_step=0;
    TC3CR = 0y01000101;
    NOP();
    NOP();
    TC3CR = 0y00010101;
    ADCCR = 0y01000000;

    if (!read_port_P4().2 && JPT)
    {
        fctest();
    }

    IOP5.1 = 1;

    for (;;)
    {
/*
        if ((fc_time < 20) && on_line_1s)
        {
            on_line_1s=0;
            fc_time+=1;
            if ((on_line_test_pass==0) && line_testing)
            {
                line_testing=0;
                on_line_test();
                on_line_test_pass=0x0f;
            }
        }
*/
        if (tc1_watch!=100)
        {
            tc1_watch=100;
            WDTCR2 = 0x4e;
        }

        if (TREG3A >=250 || TREG3B >= 250 )
        {
            TC3CR = 0y00000101;
            TC3CR = 0y00010101;
            remo_step = 0;
            EIRH.0 = 1;       
        }

        timer_cnt_sub();
        if (van_ctrl_flg)
        {
            van_ctrl_flg = OFF;
            vancontrol();      
        }

        if (autostart1s)
        {
            autostart = 1;
            autostart1s = 0;
            auto_start();
        }

        ad_sub();
        remo_decode();
        output();
        mode_sub();
        comptime();
        timer_sub();
        vane_monitor();
        emergency_timer();   
        sleepmode();
        read_key_emerg();
        emergency_run();   
    }
}
/*-------------------------------------*/
void hdwinit()
{
    SYSCR1 = 0x00;
    SYSCR2 = 0x80;

    TREG4 = 0x08;      /* 4096Hz */
    IL = 0;            /* Clear interrupt latch    */

    P1CR = 0y11111000;    
    P5CR = 0y00000010;
    P6CR = 0y11111100;

    TBTCR = 0y00000110;     /* 0.256ms every interrupt */
    TC3CR = 0y00000101;
    EINTCR.3 = 1;           /* INT3ES = 1 */
    TC3CR = 0y00010101;

    CLZCR = 0x07;

    SELREF = 0x00;

    return;
}
/*-------------------------------------*/
void auto_start()
{
    power=1;
    mode=cool;
    settemp=24;
    remo_fanspeed=3;
    vane_mode=angle_1;
    TC4CR = 0y00010110;
    return;
}
/*-------------------------------------*/
void emergency_run()
{
    if (emergency_test)
    {
        if ((!abnormal) && power && (!defrost))
        {
            setfanHi();
        }
        else
        {
            setfanOFF();
        }
    }
    else
    {
        fancontrol();    
    }
    return;
}
/*-------------------------------------*/
void timer_cnt_sub()
{
    if (bit_1s)
    {
        bit_1s = 0;
        tc1_watch-=1;

        run_time_cnt = 2;

        if (read_port_P4().3)
        {
            run_time_cnt = 100;
        }

        van_ctrl_flg = ON;

        if (++err_cnt >= 25)
        {
            err_cnt = 0;
            sh_error_1s = 1;
        }

        if (++no_short_time>=100)
        {
            no_short_time = 0;
            on_line_1s = 1;
            port1s=1;

            if (!autostart)
            {
                autostart1s = 1;
            }
        }

        if (++t10ms_cnt>=run_time_cnt)
        {
            t10ms_cnt = 0;
            outfan1s = 1;
            delay1s = 1;
            t60s_cnt+=1;
            defrost_1s = 1;
            fantime1s = 1;
            coil4c_1m = ON;
            guoyali_1s = 1;
            remo_mornitor = 1;
            stop1s = 1;
        }

        if (t60s_cnt>=60)
        {
            t60s_cnt = 0;
            yufang_c_1m = ON;
            timer1m = ON;
            c_c_t_1m = ON;
            dew_prv_1m = ON;
            emergency_1m = ON;
            sleep_1m = ON;
        }

        if (++mode_change_cnt>=run_time_cnt+10)
        {
            mode_change_cnt = 0;
            mode_bak = 0;
        }
    }
    return;
}
/*-------------------------------------*/
void remo_init()
{
    remo_step = 0;

    for (tempa=0;tempa<14;tempa+=1)
    {
        remo_data_receive[tempa]=0;
    }

    EIRH.0 = 1;           /* Enable INT3,TC1      */
    return;
}
/*-------------------------------------*/
void r_shift()
{
    remo_data_receive[remo_byte_cnt]=remo_data_receive[remo_byte_cnt]>>1;
    remo_data_receive[remo_byte_cnt]=shift_temp | remo_data_receive[remo_byte_cnt];
    return;
}
/*-------------------------------------*/
void ad_sub()
{
    if (ADCCR.7==1)
    {
        if (++adnum==0)
        {
            regA = 0;
            if ((adHLram & 0x00ff) >= 0x80)
            {
                regA = 1;
            }
            regB = adHLram >> 8;
            adHLram = 0;

            if (ad_channel==0)
            {
                ad_room = regA + regB;
                ad_channel=0x01;
                ADCCR = 0y01000001;
            }
            else
            {
                ad_coil = regA + regB;
                ad_channel=0x00;
                ADCCR = 0y01000000;
                ad_process();
            }
        }
        else
        {
            adHLram+=ADCDRL;
        }
    }
    ADCCR.6=1;

    return;
}
/*-------------------------------------*/
void ad_process()
{
    if (power)
    {
        if ((ad_room<0x05) || (ad_room>0xfb))
        {
            abnormal=1;
            roomtemp_err=1;
        }
        else    
        {
            roomtemp_err=0;
            if (!coil_err)
            {
                abnormal=0;
            }
        }
        if ((ad_coil<0x05) || (ad_coil>0xfb))
        {
            abnormal=1;
            coil_err=1;
        }
        else
        {
            coil_err=0;
            if (!roomtemp_err)
            {
                abnormal=0;
            }
        }

        if (!abnormal && !defrost)
        {
            if (ad_coil>picoil34)
            {
                defrost_time_cnt=60;
            }
            else
            {
                defrost_time_cnt=480;
            }
        }

        if (!abnormal)
        {
            if (ad_room<=90)
            {
                roomtemp=12;
            }
            else
            {       
                if (ad_room>=149)
                {
                    roomtemp=33;
                }
                else
                {
                    roomtemp=ad_tab[ad_room-90];
                }
            }

            if (emergency_test)
            {
                TCB = 1;
            }
            else
            {
                if (runmode==heat)
                {
                    roomtemp -= 2;
                    if (settemp > roomtemp)
                    {
                        TCB=1;
                    }       
                    else
                    {
                        if (settemp < roomtemp)
                        {
                            TCB=0;
                        }
                    }       
                }
                else
                {       
                    if (settemp > roomtemp)
                    {
                        TCB=0;
                    }
                    else
                    {
                        if (settemp < roomtemp)
                        {
                            TCB=1;
                        }
                    }
                }     
            }
        }
        else
        {
            TCB = 0;
        }
    }
    else
    {
        TCB = 0;
    }

    if (mode==dry || mode==fan)
    {
        TCB=0;
    }
    return;
}
/*-------------------------------------*/
void remo_decode()
{
    if (flg_remo_ok == ON)
    {
        remo_test = 1;
        flg_remo_ok = OFF;
        tempa = remo_data[6] & 0y00001111;/*run mode*/

        if (tempa != auto)/*自动运行不用解码*/
        {
            if (cool_only)/*是否单冷机*/
            {
                if (tempa != heat)
                {
                    remo_decode_sub();
                }
            }
            else
            {
                remo_decode_sub();
            }
        }
    }
    return;
}
/*-------------------------------------*/
void remo_decode_sub()
{
/*
    if ((on_line_test_pass==0) && (fc_time < 20) && ((remo_data[5]&0x03)==3))
    {
        line_testing=1;
        TC4CR = 0y00010110;
    }
    else
    {       
        on_line_test_pass=0x0f;
*/
        tempa = remo_data[5];
        power = tempa.2;
        TC4CR = 0y00010110;

        tempa = tempa & 0y00011000;

        if (tempa == 0x08)
        {
            timer_st = TIME_ON_OFF;
        }       
        else
        {
            if (tempa == 0x10)
            {
                timer_st = TIME_ON_ON;
                power = OFF;
            }
            else
            {
                if (tempa == 0x00)
                {
                    timer_st = TIME_OFF;
                }
                else
                {
                    timer = time_on = time_off = ON;
                    if (remo_data[9] > remo_data[10])
                    {
                        power = OFF;
                    }
                    else
                    {
                        power = ON;
                    }
                }
            }
        }
    
        T_off_m = remo_data[9];
        T_on_m = remo_data[10];

        mode = remo_data[6] & 0y00001111;     /* run mode */

        if ((mode == cool) || (mode == heat))
        {
            settemp = remo_data[7] ^ 0y11111111;
            settemp = settemp & 0y00001111;
            settemp = settemp + 16;
        }

        remo_fanspeed = remo_data[8] & 0y00000111 ; /* d2d1d0 fan speed */

        tempa = remo_data[8] & 0y00111000;
        tempa = tempa >> 3;

        if (vane_mode == angle_swing)/*当摇摆功能被取消时重新定位*/
        {
            if (tempa != angle_swing)
            {
                position_ok = OFF;
            }
        }    
        vane_mode = tempa;
        dew_prv = 0;   

        tempa = remo_data[11];

⌨️ 快捷键说明

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