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

📄 timer.c

📁 Bitek 公司 bit1611b模拟屏驱动芯片外接MCU驱动DEMO源码
💻 C
字号:
/* **********************************************************************

         Copyright (c) 2002-2006 Beyond Innovation Technology Co., Ltd

        All rights are reserved. Reproduction in whole or in parts is
    prohibited without the prior written consent of the copyright owner.
   ----------------------------------------------------------------------

    Module: TIMER.C

    Purpose: Implementation of TIMER module.

    Version: 0.01                                   11:33AM  2005/11/17

    Compiler: Keil 8051 C Compiler v8.01

    Reference:

   ----------------------------------------------------------------------
    Modification:

    R0.01 11:33AM  2005/11/17 Jeffrey Chang
    Reason:
        1. Original.
    Solution:

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

#define _TIMER_C_

/* ------------------------------------
    Header Files
   ------------------------------------ */
#include "common.h"
#include "led.h"
#include "key.h"
#include "mcu.h"
#include "menu.h"
#include "platform.h"
#include "timer.h"
#include "yuv.h"

#if (IR_CFG != IR_00_UNUSE)
    #include "ir.h"
#endif

/* ------------------------------------
    Macro Definitions
   ------------------------------------ */

/* ------------------------------------
    Type Definitions
   ------------------------------------ */


/* ------------------------------------
    Variables Definitions
   ------------------------------------ */


/* ------------------------------------
    Function Prototypes
   ------------------------------------ */


/* -------------------------------------------------------------------
    Name: TIMER_Init - To initialize TIMER module.
    Purpose:
    Passed: None.
    Returns: None.
    Notes:

    Reference: [3]87, [3]89
   ------------------------------------------------------------------- */
void TIMER_Init (void)
{
    IP  = 0x2A;


    // [3]64, 89
    TMOD            = TIMER_MODE;

    // Timer Mode 1 (16-bit)
    TIMER_COUNTER_H = (65536 - MACHINE_PER_TICK) / 256;
    TIMER_COUNTER_L = (65536 - MACHINE_PER_TICK) % 256;

    /* [3]89 Timer 0/1 start running */
    TIMER_RUN       = TRUE;

    /* [3]87 Enable Timer 0/1 overflow interrupt */
    TIMER_ENABLE    = TRUE;

    /* Initialize Variables */
    wTIMER_TickCnt  = 0;

    wTIMER_BurnInTick = 0;
} /* TIMER_Init */


/* -------------------------------------------------------------------
    Name: TIMER_ISR -
    Purpose: System Timer Interrupt Service Routine (ISR).
    Passed: None
    Returns: None.
    Notes:

    Reference: [2]19
   ------------------------------------------------------------------- */
void TIMER_ISR (void) interrupt TIMER_INT   using TIMER_USING
{
    // Timer Mode 1 (16-bit)
    TIMER_COUNTER_H = (65536 - MACHINE_PER_TICK) / 256;
    TIMER_COUNTER_L = (65536 - MACHINE_PER_TICK) % 256;

    wTIMER_TickCnt++;


    /* ....................................
       KEY module
       .................................... */
    /* To scan the keypad every 8 System Ticks since
       the debounce needs 48 ms at least                */
    // Period = 8 Ticks
    if ((wTIMER_TickCnt & 0x0007) == 0)
        KEY_Scan();

    #if (KEY_VR_AIN21)
    if (bKEY_VR_ADJUSTMENT)
        bKEY_VR_ADJUSTMENT--;
    #endif

    /* ....................................
       TIMER module
       .................................... */
    if (bTIMER_Tick)                 
        bTIMER_Tick--;

    if (wTIMER_Tick)
        wTIMER_Tick--;

    /* ....................................
       DISPATCH module
       .................................... */
    if (wTIMER_BurnInTick)
        wTIMER_BurnInTick--;

    /* ....................................
       MENU module
       .................................... */
    if (wMENU_Tick)
        wMENU_Tick--;


    /* ....................................
       LED module
       .................................... */
    if (fLED_RED_Blink)
    {
        // Period = 128 Ticks
        // 50% duty cycle
        if ((wTIMER_TickCnt & 0x007F) == 0x0000)
            LED_RED_OFF;

        if ((wTIMER_TickCnt & 0x007F) == 0x0040)
            LED_RED_ON;
    }


    if (fLED_GREEN_Blink)
    {
        // Period = 128 Ticks
        // 50% duty cycle
        if ((wTIMER_TickCnt & 0x007F) == 0x0010)
            LED_GREEN_OFF;

        if ((wTIMER_TickCnt & 0x007F) == 0x0050)
            LED_GREEN_ON;
    }

} /* TIMER_ISR */


/* -------------------------------------------------------------------
    Name: TIMER_DelayMS -
    Purpose: To wait a moment in milli-seconds.
    Passed:
        wMS = 1..65530                  @ System tick = 6ms

        Delay duration = 1 Tick         @ wMS = 1
                       = 6 ms           @ wMS = 1
        Delay duration = 10922 Ticks    @ wMS = 65530
                       = 65532 ms       @ wMS = 65530

    Returns: None.
    Notes:
    Reference: [2]19
   ------------------------------------------------------------------- */
void TIMER_DelayMS (UW16 wMS)
{
    TIMER_RUN   = FALSE;

    wTIMER_Tick = (wMS + MS_PER_TICK - 1) / MS_PER_TICK;

    TIMER_RUN   = TRUE;

    while (wTIMER_Tick)        
        ;                      
} /* TIMER_DelayMS */


/* -------------------------------------------------------------------
    Name:  -
    Purpose: .
    Passed: None.
    Returns: None.
    Notes:
   ------------------------------------------------------------------- */


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

    Description:


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

/* %% End Of File %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */

⌨️ 快捷键说明

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