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

📄 timer.c

📁 Realtek 公司的RTD2523A芯片原厂source code,没有被修改过的。
💻 C
字号:
#define __TIMER__

#include "Header\INCLUDE.H"


/////////////////////////////////////////////////////////////
// Interrupt Service Routine for Timer0 (Fired every 20ms) //
/////////////////////////////////////////////////////////////
void IntProc_Timer0(void) interrupt 1
{
#if (MCU_TYPE != MCU_STD8051)
    static unsigned char    ucTimerCounter  = 0;
#endif

#if (IRPOLLING)

    static unsigned char    ucIR_Seq    = 0xff;
    static unsigned char    ucTimerCnt  = 0x00;

    TL0         = TIME0_COUNTER_LBYTE;  // Reload Timer0 low-byte
    TH0         = TIME0_COUNTER_HBYTE;  // Reload Timer0 high-byte

    if (ucIR_State)
    {
        if (bIR_GPIO)
        {
            ucIR_Seq    = (ucIR_Seq << 1) | 0x01;

            if ((0xff == ucIR_Seq) && (ucIR_State & 0xfe))
            {
                ucIR_State  = 0;    // Command timeout; Back to idle state
                
                ((unsigned int *)ucIR_Cmd)[0]   = 0;
            }
        }
        else
        {
            if (1 < ucIR_State)
            {
                if (ucIR_Seq & 0x01)
                {
                    ((unsigned int *)ucIR_Cmd)[0]   = (((unsigned int *)ucIR_Cmd)[0] << 1) 
                                                    | (0x07 != (ucIR_Seq & 0x07) ? 1 : 0);

                    if (23 == ++ucIR_State && CUSTOM_CODE != ((unsigned int *)ucIR_Cmd)[0])
                    {
                        ucIR_State  = 0;    // Customer code error; Back to idle state

                        ((unsigned int *)ucIR_Cmd)[0]   = 0;
                    }
                    else if (39 == ucIR_State)
                    {
                        ucIR_State  = 0;    // Command complete; Back to idle state

                        ucIR_Cmd[1] = 8;    // Set command timer to 8 (7*20 = 140ms)
                    }
                }
                else if (0x00 == (ucIR_Seq & 0xfe))
                {
                    ucIR_State  = 0;    // Command crashed; Back to idle state
    
                    ((unsigned int *)ucIR_Cmd)[0]   = 0;
                }
            }
            else                        // ucIR_State is 1
            {
                if (0xff == ucIR_Seq)
                {
                    ucIR_State  = 0x07; // Start to decode new command and clear old command
    
                    ((unsigned int *)ucIR_Cmd)[0]   = 0;
                }
                else
                {
                    ucIR_State  = 0;    // Fire repeat command and reset to idle

                    ucIR_Cmd[1] = ucIR_Cmd[0] ? 8 : 0;
                }
            }
            
            ucIR_Seq    = ucIR_Seq << 1;
        }
    }
    else
    {
        ucIR_Seq    = (ucIR_Seq << 1) | bIR_GPIO;

        if (0x07 == ucIR_Seq)   ucIR_State  = 1;    // Leader code detected
    }

    if (54 <= ++ucTimerCnt)        // 0.375ms * 54 = 20.25ms passed
    {
        ucTimerCnt          = 0;

        bNotify_Timer0_Int  = 1;    // Post Timer0's timeout message

        if (usOSD_Timer)    usOSD_Timer -= 1;   // For OSD Timeout

        if (bAutoInProgress && !bPOWER_KEY)     bPowerDownWhenAuto = 1;

        // Clear command after 144ms if not repeat code
        if (0 == ucIR_State)
        {
            if (ucIR_Cmd[1] && 0 == --ucIR_Cmd[1])      ucIR_Cmd[0] = 0;
        }
    }

#if (MCU_TYPE != MCU_STD8051)

    if (3 <= ++ucTimerCounter)
    {
        ucTimerCounter      = 0;
        bNotify_Timer1_Int  = 1;    // Post Timer1's timeout message
    }

#endif

#else   // if not IRPOLLING

#if (MCU_TYPE == MCU_STD8051)

    TL0 = TIME0_COUNTER_LBYTE;  // Reload Timer0 low-byte
    TH0 = TIME0_COUNTER_HBYTE;  // Reload Timer0 high-byte

    bNotify_Timer0_Int  = 1;    // Post Timer0's timeout message

    if (usOSD_Timer)    usOSD_Timer -= 1;   // For OSD Timeout

    // For power-down during auto
    if (bAutoInProgress && !bPOWER_KEY)     bPowerDownWhenAuto = 1;

#else
    
    TL0 = TIME1_COUNTER_LBYTE;  // Reload Timer1 low-byte
    TH0 = TIME1_COUNTER_HBYTE;  // Reload Timer1 hifh-byte
    TR0 = 1;                    // Stop Timer1
    bNotify_Timer1_Int  = 1;    // Post Timer1's timeout message  

    if (20 <= ++ucTimerCounter)
    {
        ucTimerCounter      = 0;
        bNotify_Timer0_Int  = 1;                // Post Timer0's timeout message
        
        if (usOSD_Timer)    usOSD_Timer -= 1;   // For OSD Timeout

        // For power-down during auto
        if (bAutoInProgress && !bPOWER_KEY)     bPowerDownWhenAuto = 1;
    }

#endif

#endif
}

///////////////////////////////////////////////////////////////////////
// Interrupt Service Routine for Timer1 (Fired in 1ms after restart) //
///////////////////////////////////////////////////////////////////////
#if (MCU_TYPE == MCU_STD8051)   // Use the standard 8052 MCU

void IntProc_Timer1(void) interrupt 3
{   
    TR1 = 0;                    // Stop Timer1
    TL1 = TIME1_COUNTER_LBYTE;  // Reload Timer1 low-byte
    TH1 = TIME1_COUNTER_HBYTE;  // Reload Timer1 hifh-byte

    bNotify_Timer1_Int  = 1;    // Post Timer1's timeout message    
}

/////////////////////////////////////////////////////////////////////////////////
// Function Routines
/////////////////////////////////////////////////////////////////////////////////
void Delay_Xms(unsigned char x)     // For delay 0 ~ 255 ms
{
    if (x)
    {
        bNotify_Timer1_Int  = 0;    // Clear timer1's timeout message

        TR1 = 1;                    // Start timer1
        
        while (1)
        {
            if (bNotify_Timer1_Int)
            {
                bNotify_Timer1_Int  = 0;    // Clear timer1's timeout message

                if (--x)    TR1 = 1;        // Restart timer1 if not timeout
                else        return;         // Timeout for X ms.
            }
        }
    }
}

#else // Use just one timer

/////////////////////////////////////////////////////////////////////////////////
// Function Routines
/////////////////////////////////////////////////////////////////////////////////
void Delay_Xms(unsigned char x)     // For delay 0 ~ 255 ms
{
    if (x)
    {
        bNotify_Timer1_Int  = 0;    // Clear timer1's timeout message

        while (1)
        {
            if (bNotify_Timer1_Int)
            {
                bNotify_Timer1_Int  = 0;    // Clear timer1's timeout message
                
                if (0 == --x)   return;     // Timeout for X ms.
            }
        }
    }
}

#endif

⌨️ 快捷键说明

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