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

📄 timer.c

📁 keil C51 LCD 驱动源码,其中还有I2C驱动,ADC驱动,键盘操作等,是一个完整的keil源代码,供大家参考
💻 C
字号:
/****************************************************************************
   +----------------------------------------------------------------------+
   | Copyright Trumpion Microelectronics Inc. 1999                        |
   | Trumpion Microelectronics Inc. reserves the right to change products |
   | or specifications without notice.                                    |
   +----------------------------------------------------------------------+
   Project    : LCD monitor
   Version    : 0.94
   File Name  : timer.c
   Functions  : V-sync,H-sync Freq and Polarity detect, 4ms timer, backlight
   Revision   :

   1999-05-18  OriginalTeam    First Created
   2000-06-30  Bill Tseng      Modified for Zurac-II
   2000-07-17  Glen Chang      Add HWMD module
****************************************************************************/

//=========================================================================
// include files                                                          =
//=========================================================================
#include  "lib\extent.h"
#include  "lib\wreg516.h"
#include  "lib\declare.h"

#include  "lib\global.h"
#include  "lib\initial.h"
#include  "lib\hwmd.h"


/************************************************************************
 * Function    : INT0ISR                                                *
 * Description : Interrupt 0 ISR                                        *
 *               This routine handle the interrupt from ZURAC2          *
/************************************************************************/
void  INT0ISR ( void ) interrupt 0 using 3
{   
#if     ZURAC_HWMD      
    EX0 = 0;                        // disable  INT0    interrupt
    FgHWMDInt = 1;
    if ( InputSource <= INPUT_DIGITAL )
    {
        if ( !FgFreeRun )
            PowerBacklight(0);      // back light off
        FgModeDetect = 0;
        MuteTimer = TIME_300MS;			//TIME_200MS;
    }
#endif  // ZURAC_HWMD 
}
 
/************************************************************************/
/* Function    : INT1ISR                                                */
/* Description : Interrupt 1 ISR                                        */
/*               This routine handle the VSYNC Input and get H polarity */
/************************************************************************/
void  INT1ISR ( void ) interrupt 2 using 3
{       
#if     ZURAC_HWMD
 #if     DIGITAL_DOS_MODE
    TR2 = 0;                    // stop   Counter2
    TR0 = 0;                    // stop   Timer0
    TH0 = 0;                    // clear  Timer0
    TL0 = 0;
    TH2 = 0xFF;                 // setup  Counter2 to filter 6 PH_SYNC
    TL2 = 0xFA;
    TR2 = 1;                    // start  Counter2
    ET2 = 1;                    // enable Counter2 interrupt 
    FgPHSFilterOn = 1;          // set software flag
 #endif
#else   // ZURAC_HWMD
    Word DATA  i1_1us;
            
    TR0 = 0;                          /* disable H-sync counter */
    HIBYTE_REF(HS1frCount) = TH0;     /* get     H-sync counter */
    LOBYTE_REF(HS1frCount) = TL0;     /* get     H-sync counter */
    TH0 = 0;                          /* reset   H-sync counter */
    TL0 = 0;                          /* reset   H-sync counter */
    TR0 = 1;                          /* enable  H-sync counter */

    i1_1us = VS1usCount;
    HIBYTE_REF(VS1usCount) = TH1;
    LOBYTE_REF(VS1usCount) = TL1;
    InVTime = ((Word)VS4msCount << 12) + VS1usCount - i1_1us;

    VS4msCount  = 0;                  /* reset 4ms counter */
    VPolTime    = TIME_8MS;
    VSyncOVTime = TIME_28MS;
    VSyncOn     = 1;
    VSyncReady  = 1;  
    VSyncStart  = 1;
#endif  // ZURAC_HWMD
}
/************************************************************************/
/* Function    : Timer1ISR                                              */
/* Description : 4 ms interrupt and V-polarity check                    */
/************************************************************************/
void  Timer1ISR ( void ) interrupt 3 using 3
{
    TL1 = CLOCK_4096us & 0xFF;
    TH1 = CLOCK_4096us >> 8;
    TF1 = 0;

#if     ZURAC_HWMD   
    if( MuteTimer != 0 )
    {
       if( --MuteTimer == 0 )
          FgModeDetect = 1;
    }
#else   // ZURAC_HWMD
    if( VPolTime != 0 )
    {
       if( --VPolTime == 0 )
          InVPol = ~VSYNC_PIN;
    }
    if( --VSyncOVTime == 0xFF )
    {
       InVTime     = 0;
       VSyncOn     = 0;
       VSyncReady  = 1;
       VSyncOVTime = TIME_28MS;
    }
    VS4msCount++;
#endif  // ZURAC_HWMD

    if( OSDOffTimer != 0 )    OSDOffTimer--;
    if( PromptTimer != 0 )    PromptTimer--;
    if( T8_192msTimer != 0 )  T8_192msTimer--;
    if( CountTimer != 0 )     CountTimer--;
    if( GeneralTimer != 0 )   GeneralTimer--;
}
/************************************************************************/
/* Function    : Timer0ISR                                              */
/* Description : Hsync counter for counting 256 Hsync's period of time  */
/************************************************************************/
void  Timer0ISR ( void ) interrupt 1 using 2
{
#if     ZURAC_HWMD
    TL0=0x00;           //TONNY Stop Timer0
    TH0=0x00;           //TONNY

#else   // ZURAC_HWMD
    /* should never happen if VGA connected */
    InVTime     = 0;
    VSyncOn     = 0;
    VSyncReady  = 1;
    VSyncOVTime = TIME_28MS;
#endif  // ZURAC_HWMD
}
/************************************************************************/
/* Function    : Timer2ISR                                              */
/* Description : 100 Hz software PWM output                             */
/************************************************************************/
void  Timer2ISR ( void ) interrupt 5 using 2
{
#if  ZURAC_HWMD
 #if  DIGITAL_DOS_MODE
    if ( FgPHSFilterOn )
    {
        TF2 = 0;                         // clear Counter2 interrupt status
        TH2 = 0xFF;                      // set   Counter2 to count 16 times
        TL2 = 0xF0;
        TR0 = 1;                         // start Timer0
        TR2 = 1;                         // start Counter2
        FgPHSFilterOn = 0;               // reset software flag
    }
    else
    {
        HIBYTE_REF(PHsync16) = TH0;      // get 16 PHsync time
        LOBYTE_REF(PHsync16) = TL0;
        TF2 = 0;                         // clear Counter2 interrupt status
        TR0 = 0;                         // stop  Timer0
        TR2 = 0;                         // stop  Counter2
    }
 #endif
#else
//  TF2 = 0;
#endif
}

void    RS232ISR()      interrupt 4 using 2
{
        if(RI)
        {
                RI=0;
                if(RxdBufIndex<ALIGNTOTAL)
                {
                        RxdBuf[RxdBufIndex]=SBUF;
                        RxdBufIndex++;
                }
        }
}

⌨️ 快捷键说明

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