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

📄 powersupply.c

📁 NEC527多功能电表完整源代码,包括LCD驱动,显示,计量,存储,整个527驱动程序!
💻 C
📖 第 1 页 / 共 4 页
字号:
        if( AlarmCtlWord2 & ALARM_OF_SMALL_LOAD )
        {
            if( EvtTimerCounter[5]++ >= _SysPotInfo.timer_count[EVT_TC_SMALL_LOAD] )
            {
                EvtTimerCounter[5] = 0; 
                AlarmCtlWord2 &=~ ALARM_OF_SMALL_LOAD;
            }				
        }		
    }
    
    for( i[0] = 0; i[0] < 3; i[0]++ )
    {
        temp[0] =(uchar)( PS_LIA_PHA << i[0]);
        if( CurrentVI[3+i[0]] < 4 )
        {
            if( !(EvtLostiFlag & temp[0] ) )
            {
                EvtLostiFlag |= temp[0];
                EvtLostiTimerCount[i[0]] = 0;
            }

            if( EvtLostiTimerCount[i[0]]++ >= 5 )
            {
                EvtLostiTimerCount[i[0]] = 0;
                if( !( mrs & temp[0] ) )
                {
                    mrs |= temp[0];
                }
            }
        }
        else
        {
            if( EvtLostiFlag & temp[0] )
            {
                EvtLostiFlag &=~ temp[0];
                EvtLostiTimerCount[i[0]] = 0;
            }

            if( EvtLostiTimerCount[i[0]]++ >= 5 )
            {
                EvtLostiTimerCount[i[0]] = 0;
                if( mrs & temp[0] )
                {
                    mrs &=~ temp[0];
                }
            }
        }
    }        

    i_mrs = (unsigned short)( ( (unsigned long)CurrentVI[3]+(unsigned long)CurrentVI[4]+(unsigned long)CurrentVI[5] )/3 );
    v_temp = abs( CurrentVI[3]-(unsigned short)i_mrs );
    v_temp1 = abs( CurrentVI[4]-(unsigned short)i_mrs );
    v_temp2 = abs( CurrentVI[5]-(unsigned short)i_mrs );
    v_mrs = MaxValueOfNums( v_temp, v_temp1, v_temp2 );
    
    if( i_mrs != 0 ) 
    {
        pub_data.pub_data_buff2[0] = ( v_mrs*10000 )/i_mrs;
    }		
    else 
    {
        pub_data.pub_data_buff2[0] = 0;    
    }		
    
    if( !( AlarmCtlWord2 & ALARM_OF_SMALL_LOAD ) )
    {    	
        pub_data.pub_data_buff2[1] = 0;	
        FramRead( ADDR_OF_IMBA_UPVAL, (unsigned char *)&pub_data.pub_data_buff2[1], 3 );
        pub_data.pub_data_buff2[1] = Bcd2HexLong( pub_data.pub_data_buff2[1] );	
        if( pub_data.pub_data_buff2[0] > pub_data.pub_data_buff2[1] )
        {
            if( !( EvtTimerCounterflag & BIT1 ) )
            {
                EvtTimerCounterflag |= BIT1;
                EvtTimerCounter[1] = 0;            			
            }
		
            if( !( AlarmCtlWord2 & ALARM_OF_CURIMBA ) )
            {
                if( EvtTimerCounter[1]++ >= _SysPotInfo.timer_count[EVT_TC_CUR_IMBA] )
                {
                    EvtTimerCounter[1] = 0;
                    AlarmCtlWord2 |= ALARM_OF_CURIMBA;
                    SaveEvtStartInfo(4);
                }				
            }
        }
        else
        {
            if( EvtTimerCounterflag & BIT1 )
            {
                EvtTimerCounterflag &=~ BIT1;
                EvtTimerCounter[1] = 0;    			
            }
    
            if( AlarmCtlWord2 & ALARM_OF_CURIMBA )
            {
                if( EvtTimerCounter[1]++ >= _SysPotInfo.timer_count[EVT_TC_CUR_IMBA] )
                {
                    EvtTimerCounter[1] = 0; 
                    AlarmCtlWord2 &=~ ALARM_OF_CURIMBA;
                    SaveEvtStopInfo(4);
                }				
            }
        }
    }
    else
    {
        if( EvtTimerCounterflag & BIT1 )
        {
            EvtTimerCounterflag &=~ BIT1;
            EvtTimerCounter[1] = 0;
        }

        if( AlarmCtlWord2 & ALARM_OF_CURIMBA )
        {
            if( EvtTimerCounter[1]++ >= _SysPotInfo.timer_count[EVT_TC_CUR_IMBA] )
            {
                EvtTimerCounter[1] = 0;
                AlarmCtlWord2 &=~ ALARM_OF_CURIMBA;
                SaveEvtStopInfo(4);
            }				
        }    
    }
	
    for( i[0] = 0; i[0] < 3; i[0]++ )
    {
        flag = 0;    
        temp[0] = (uchar)(PS_LIA_PHA << i[0]);
        temp[1] =(uchar)(PS_LVA_PHA<< i[0]);
        if( i[0] == 0 )
        {
            if( ( CurrentVI[4] > _SysPotInfo.lvi_con[1]/10 ) ||
              ( CurrentVI[5] > _SysPotInfo.lvi_con[1]/10 ) )
            {
                flag = 1;
            }
        }
        else if( i[0] == 1 )
        {
            if( ( CurrentVI[3] > _SysPotInfo.lvi_con[1]/10 ) ||
              ( CurrentVI[5] > _SysPotInfo.lvi_con[1]/10 ) )
            {
                flag = 1;
            }
        }
        else
        {
            if( ( CurrentVI[3] > _SysPotInfo.lvi_con[1]/10 ) ||
              ( CurrentVI[4] > _SysPotInfo.lvi_con[1]/10 ) )
            {
                flag = 1;
            }
        }		
		
        if( ( pub_data.pub_data_buff2[0] > _SysPotInfo.lvi_con[2] ) && 
             ( CurrentVI[3+i[0]] < _SysPotInfo.lvi_con[0]/10 ) && ( flag != 0 ) )
        {
            if( !(EvtLowiFlag & temp[1] ) )
            {
                EvtLowiFlag |= temp[1];
                EvtLowiTimerCount[i[0]] = 0;
            }
            if( EvtLowiTimerCount[i[0]]++ > _SysPotInfo.timer_count[EVT_TC_LOWI] )
            {
                EvtLowiTimerCount[i[0]] = 0;
                if( !( lvisw & temp[0] ) )
                {
                    lvisw |= temp[0];
                }                
            }
        }
        else
        {
            if( EvtLowiFlag & temp[1] ) 
            {
                EvtLowiFlag &=~ temp[1];
                EvtLowiTimerCount[i[0]] = 0;
            }
			
            if( EvtLowiTimerCount[i[0]]++ > _SysPotInfo.timer_count[EVT_TC_LOWI] )
            {
                EvtLowiTimerCount[i[0]] = 0;				
                if( lvisw & temp[0] )
                {
                    lvisw &=~ ( temp[0] );
                }				
            }        
        }             
    }
    
    for( i[0] = 0; i[0] < 3; i[0]++ )
    {
        temp[0] = (unsigned char)(PS_OVI_PHA << i[0]);
        if( CurrentVI[3+i[0]] > _SysPotInfo.security_check_imax )
        {
            if( !( EvtOverIFlag & temp[0] ) )
            {
                EvtOverIFlag |= temp[0];
                EvtOveriTimerCount[i[0]] = 0;
            }

            if( EvtOveriTimerCount[i[0]]++ >= 5 )
            {
                EvtOveriTimerCount[i[0]] = 0;
                if( !(ovisw & temp[0] ) )
                {
                    ovisw |= temp[0];
                }                    
            }                
        }
        else
        {
            if( EvtOverIFlag & temp[0] )
            {
                EvtOverIFlag &=~ temp[0];
                EvtOveriTimerCount[i[0]] = 0;
            }

            if( EvtOveriTimerCount[i[0]]++ >= 5 )
            {
                EvtOveriTimerCount[i[0]] = 0;                
                if( ovisw & temp[0] )
                {
                    ovisw &=~ temp[0];
                }                    
            }
        }        
    }    
		
    if( pnsw & 0x70 )
    {
        LCDMEM[LCD_CN_INFO_ADDR_ALARM] |= LCD_CN_INFO_ALARM;
    }
    else
    {
        LCDMEM[LCD_CN_INFO_ADDR_ALARM] &=~ LCD_CN_INFO_ALARM;
    }

    if( MeterRunningState != mrs )
    {
        temp[0] = MeterRunningState & 0x07;
        temp[1] = mrs & 0x07;
        if( temp[0] != temp[1] )
        {        
            for( j = 0; j < 3; j++ )
            {
                if( temp[0] & ( BIT0 << j ) )
                {
                    if( !( temp[1] & ( BIT0 << j ) ) )
                    {
                        OnEvtOverLostStop( 1, j );
                    }
                }                    
                else
                {
                    if( temp[1] & ( BIT0 << j ) )
                    {
                        OnEvtOverLostStart( 1, j );
                    }
                }
            }
        }    
        
        MeterRunningState = mrs;
        FramWrite( ADDR_OF_METER_RUN_STATUS, (unsigned char *)&mrs, 1 );
    }
	
    pnsw = ( pnsw | ( mrs & 0x07 ) );
    PowerNetStateWord = pnsw;
    
    if( OverVIStateWord != ovisw )
    {        
        temp[0] = ( OverVIStateWord & 0x07 );
        temp[1] = ( ovisw & 0x07 );
        if( temp[0] != temp[1] )
        {
            for( j = 0; j < 3; j++ )
            {
                if( temp[0] & ( BIT0 << j ) )
                {
                    if( !( temp[1] & ( BIT0 << j ) ) )
                    {
                        OnEvtOverLostStop( 0, j );
                    }
                }
                else
                {
                    if( temp[1] & ( BIT0 << j ) )
                    {
                        OnEvtOverLostStart( 0, j );
                    }
                }
            }    
        }

        temp[0] = ( ( OverVIStateWord >> 4 ) & 0x07 );
        temp[1] = ( ( ovisw >> 4 ) & 0x07 );
        if( temp[0] != temp[1] )
        {
            for( j = 0; j < 3; j++ )
            {
                if( temp[0] & ( BIT0 << j ) )
                {
                    if( !( temp[1] & ( BIT0 << j ) ) )
                    {
                        OnEvtOverLostStop( 2, j );
                    }
                }
                else
                {
                    if( temp[1] & ( BIT0 << j ) )
                    {
                        OnEvtOverLostStart( 2, j );
                    }
                }
            }
        }
        
        OverVIStateWord = ovisw;
        FramWrite( ADDR_OF_OVISW, &ovisw, 1 );
    }
            
    if( LowVIStateWord != lvisw )
    {  
        GetLowViStatus( temp );     		
        i[0] = lvisw & 0x07;
        i[1] = ( lvisw >> 4 ) & 0x07;
        
        if( temp[1] != i[1] )
        {
            for( j = 0; j < 3; j++ )
            {
                if( temp[1] & ( BIT0 << j ) )
                {
                    if( !( i[1] & ( BIT0 << j ) ) )
                    {
                        OnLviStop( 1, j );
                    }
                }
                else
                {
                    if( i[1] & ( BIT0 << j ) ) 
                    {
                        OnLviStart( 1, j );
                    }
                }
            }
        }
        
        if( temp[0] != i[0] )
        {			
            for( mrs = 0; mrs < 3; mrs++ )
            {
                if( temp[0] & ( BIT0 << mrs ) )
                {
                    if( !( i[0] & ( BIT0 << mrs ) ) )
                    {
                       OnLviStop( 0, mrs ); 
                    }
                }
                else
                {
                    if( i[0] & ( BIT0 << mrs ) ) 
                    {    
                        OnLviStart( 0, mrs );
                    }
                }
            }
        }
        
        LowVIStateWord = lvisw;		
        FramWrite( ADDR_OF_LVISW, &lvisw, 1 );   
    }        
}

void GetFreq(void)
{
    unsigned long freq;
    unsigned short temp;
    
    if( !( PowerStateFlag & PS_BREAKPOWER_FLAG ) )
    {
        if( !( SystemIndication & EVT_INIT_ATT702X ) )
        {
            if( !(LowVIStateWord & PS_LVA_PHA ))
            {
                Att702xRead( ATT_ADDR_FREQ, (unsigned char *)&freq );
                {
                    freq &= 0xFFFFFF;
                    temp = (unsigned short)( (freq * 100)>>13 ); 
                    temp = Hex2BcdShort(temp);
                    CurrentFreq = temp;
                }
            }
            else
            {
                CurrentFreq = 0x5000;
            }
        }
    }
    else
    {
        CurrentFreq = 0;
    }
}

⌨️ 快捷键说明

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